Page 1 of 1
How to decode Data store in the Options field in DB
Posted: Sunday 07 October 2018 15:51
by pipiche
In order to do some debuging, I need to find out a way to decode the Options column in the domoticz Database.
Here is what I got from the following command
Code: Select all
[code]Select DeviceID, Name, Options from DeviceStatus ;
Code: Select all
d3a9|Cube|LevelActions:fHx8fHx8fHx8;LevelNames:T2ZmfFNoYWtlfFdha2V1cHxEcm9wfDkwwrB8MTgwwrB8UHVzaHxUYXB8Um90YXRpb24=;LevelOffHidden:dHJ1ZQ==;SelectorStyle:MA==;TypeName:QXFhcmE=;Zigate:eydSU1NJJzogMjQzLCAnWkRldmljZUlEJzoge30sICdUeXBlJzogJ0FxYXJhJywgJ1N0YXR1cyc6ICdpbkRCJywgJ1JJQSc6ICczJywgJ01hY0NhcGEnOiAnODAnLCAnQmF0dGVyeSc6IHt9LCAnSGVhcnRiZWF0JzogJzAnLCAnTW9kZWwnOiAnbHVtaS5zZW5zb3JfY3ViZS5hcWdsMDEnLCAnSUVFRSc6ICcwMDE1OGQwMDAyNzk4NGFlJywgJ1Byb2ZpbGVJRCc6IHt9LCAnRXAnOiB7JzAxJzogeycwMDAwJzoge30sICcwMDBjJzoge30sICcwMDEyJzoge319fX0=
Now my question is can from a python script or some other script I can decode the Options['Zigate'] and Options['TypeName'] fields ?
Re: How to decode Data store in the Options field in DB
Posted: Sunday 07 October 2018 18:28
by SweetPants
These are Base64 encoded strings, using Base64 decoder you get your strings back (I hope)
T2ZmfFNoYWtlfFdha2V1cHxEcm9wfDkwwrB8MTgwwrB8UHVzaHxUYXB8Um90YXRpb24 = Off|Shake|Wakeup|Drop|90°|180°|Push|Tap|Rotation
Re: How to decode Data store in the Options field in DB
Posted: Sunday 07 October 2018 20:09
by waaren
pipiche wrote: ↑Sunday 07 October 2018 15:51
In order to do some debuging, I need to find out a way to decode the Options column in the domoticz Database.
T2ZmfFNoYWtlfFdha2V1....
Now my question is can from a python script or some other script I can decode the Options['Zigate'] and Options['TypeName'] fields ?
In Lua (and dzVents) you can do this by using:
Code snippet
Code: Select all
-- Base string
local b='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
-- decode function
function dec(data)
data = string.gsub(data, '[^'..b..'=]', '')
return (data:gsub('.', function(x)
if (x == '=') then return '' end
local r,f='',(b:find(x)-1)
for i=6,1,-1 do r=r..(f%2^i-f%2^(i-1)>0 and '1' or '0') end
return r;
end):gsub('%d%d%d?%d?%d?%d?%d?%d?', function(x)
if (#x ~= 8) then return '' end
local c=0
for i=1,8 do c=c+(x:sub(i,i)=='1' and 2^(8-i) or 0) end
return string.char(c)
end))
end
local codedString = "T2ZmfFNoYWtlfFdha2V1cHxEcm9wfDkwwrB8MTgwwrB8UHVzaHxUYXB8Um90YXRpb24"
local codedString2= "eydSU1NJJzogMjQzLCAnWkRldmljZUlEJzoge30sICdUeXBlJzogJ0FxYXJhJywgJ1N0YXR1cyc6ICdpbkRCJywgJ1JJQSc6ICczJywgJ01hY0NhcGEnOiAnODAnLCAnQmF0dGVyeSc6IHt9LCAnSGVhcnRiZWF0JzogJzAnLCAnTW9kZWwnOiAnbHVtaS5zZW5zb3JfY3ViZS5hcWdsMDEnLCAnSUVFRSc6ICcwMDE1OGQwMDAyNzk4NGFlJywgJ1Byb2ZpbGVJRCc6IHt9LCAnRXAnOiB7JzAxJzogeycwMDAwJzoge30sICcwMDBjJzoge30sICcwMDEyJzoge319fX0"
dz.log(dec(codedString),dz.LOG_FORCE)
dz.log(dec(codeString2),dz.LOG_FORCE)
Result:
Code: Select all
2018-10-07 19:53:00.727 Status: dzVents: !Info: Off|Shake|Wakeup|Drop|90°|180°|Push|Tap|Rotation
2018-10-07 19:53:00.734 Status: dzVents: !Info: {'RSSI': 243, 'ZDeviceID': {}, 'Type': 'Aqara', 'Status': 'inDB', 'RIA': '3', 'MacCapa': '80', 'Battery': {}, 'Heartbeat': '0', 'Model': 'lumi.sensor_cube.aqgl01', 'IEEE': '00158d00027984ae', 'ProfileID': {}, 'Ep': {'01': {'0000': {}, '000c': {}, '0012': {}}}}
Just be clear.. Not invented by me
