From f6310a3ce0f67a5daecd996d830e80d73d0f5685 Mon Sep 17 00:00:00 2001 From: mikayong Date: Wed, 31 Mar 2021 09:18:39 +0800 Subject: [PATCH] Add Dragino devices decoder support --- .../src-payload-decoders/node/dragino_laq4.js | 43 ++++ .../node/dragino_ldds20.js | 28 +++ .../node/dragino_ldds75.js | 28 +++ .../node/dragino_lds01.js | 57 +++++ .../node/dragino_lse01.js | 35 +++ .../node/dragino_lsn50v2.js | 100 +++++++++ .../node/dragino_lt22222-l.js | 112 ++++++++++ .../node/dragino_lt33222-l.js | 112 ++++++++++ .../node/dragino_lwl01.js | 57 +++++ .../python/dragino_laq4.py | 64 ++++++ .../python/dragino_ldds20.py | 39 ++++ .../python/dragino_ldds75.py | 39 ++++ .../python/dragino_lds01.py | 141 ++++++------ .../python/dragino_lse01.py | 120 +++++----- .../python/dragino_lsn50v2.py | 183 ++++++++++++++++ .../python/dragino_lt22222-l.py | 207 ++++++++++++++++++ .../python/dragino_lt33222-l.py | 207 ++++++++++++++++++ .../python/dragino_lwl01.py | 61 ++++++ 18 files changed, 1483 insertions(+), 150 deletions(-) create mode 100644 transform_binary_payload/src-payload-decoders/node/dragino_laq4.js create mode 100644 transform_binary_payload/src-payload-decoders/node/dragino_ldds20.js create mode 100644 transform_binary_payload/src-payload-decoders/node/dragino_ldds75.js create mode 100644 transform_binary_payload/src-payload-decoders/node/dragino_lds01.js create mode 100644 transform_binary_payload/src-payload-decoders/node/dragino_lse01.js create mode 100644 transform_binary_payload/src-payload-decoders/node/dragino_lsn50v2.js create mode 100644 transform_binary_payload/src-payload-decoders/node/dragino_lt22222-l.js create mode 100644 transform_binary_payload/src-payload-decoders/node/dragino_lt33222-l.js create mode 100644 transform_binary_payload/src-payload-decoders/node/dragino_lwl01.js create mode 100644 transform_binary_payload/src-payload-decoders/python/dragino_laq4.py create mode 100644 transform_binary_payload/src-payload-decoders/python/dragino_ldds20.py create mode 100644 transform_binary_payload/src-payload-decoders/python/dragino_ldds75.py create mode 100644 transform_binary_payload/src-payload-decoders/python/dragino_lsn50v2.py create mode 100644 transform_binary_payload/src-payload-decoders/python/dragino_lt22222-l.py create mode 100644 transform_binary_payload/src-payload-decoders/python/dragino_lt33222-l.py create mode 100644 transform_binary_payload/src-payload-decoders/python/dragino_lwl01.py diff --git a/transform_binary_payload/src-payload-decoders/node/dragino_laq4.js b/transform_binary_payload/src-payload-decoders/node/dragino_laq4.js new file mode 100644 index 0000000..550e991 --- /dev/null +++ b/transform_binary_payload/src-payload-decoders/node/dragino_laq4.js @@ -0,0 +1,43 @@ +function decodeUplink(input) { + var port = input.fPort; + var bytes = input.bytes; + var mode=(bytes[2] & 0x7C)>>2; + var bat=(bytes[0]<<8 | bytes[1])/1000; + var data = {}; + switch (input.fPort) { + case 2: + if(mode==1) + { + data.Bat_V=bat; + data.Work_mode="CO2"; + data.Alarm_status=(bytes[2] & 0x01)? "TRUE":"FALSE"; + data.TVOC_ppb= bytes[3]<<8 | bytes[4]; + data.CO2_ppm= bytes[5]<<8 | bytes[6]; + data.TempC_SHT=parseFloat(((bytes[7]<<24>>16 | bytes[8])/10).toFixed(2)); + data.Hum_SHT=parseFloat(((bytes[9]<<8 | bytes[10])/10).toFixed(1)); + } + else if(mode==31) + { + data.Bat_V=bat; + data.Work_mode="ALARM"; + data.SHTEMPMIN= bytes[3]<<24>>24; + data.SHTEMPMAX= bytes[4]<<24>>24; + data.SHTHUMMIN= bytes[5]; + data.SHTHUMMAX= bytes[6]; + data.CO2MIN= bytes[7]<<8 | bytes[8]; + data.CO2MAX= bytes[9]<<8 | bytes[10]; + } + + if(bytes.length==11) + { + return { + data: data, + } + } + break; + default: + return { + errors: ["unknown FPort"] + } + } +} \ No newline at end of file diff --git a/transform_binary_payload/src-payload-decoders/node/dragino_ldds20.js b/transform_binary_payload/src-payload-decoders/node/dragino_ldds20.js new file mode 100644 index 0000000..e3ef28d --- /dev/null +++ b/transform_binary_payload/src-payload-decoders/node/dragino_ldds20.js @@ -0,0 +1,28 @@ +function decodeUplink(input) { + var data = {}; + var len=input.bytes.length; + var value=(input.bytes[0]<<8 | input.bytes[1]) & 0x3FFF; + var batV=value/1000;//Battery,units:V + var distance = 0; + var interrupt = input.bytes[len-1]; + switch (input.fPort) { + case 2: + if(len==5) + { + data.value=input.bytes[2]<<8 | input.bytes[3]; + data.distance=(value);//distance,units:mm + if(value<20) + data.distance = "Invalid Reading"; + } + else + data.distance = "No Sensor"; + return { + data:data, + }; + +default: + return { + errors: ["unknown FPort"] + } +} +} \ No newline at end of file diff --git a/transform_binary_payload/src-payload-decoders/node/dragino_ldds75.js b/transform_binary_payload/src-payload-decoders/node/dragino_ldds75.js new file mode 100644 index 0000000..e3ef28d --- /dev/null +++ b/transform_binary_payload/src-payload-decoders/node/dragino_ldds75.js @@ -0,0 +1,28 @@ +function decodeUplink(input) { + var data = {}; + var len=input.bytes.length; + var value=(input.bytes[0]<<8 | input.bytes[1]) & 0x3FFF; + var batV=value/1000;//Battery,units:V + var distance = 0; + var interrupt = input.bytes[len-1]; + switch (input.fPort) { + case 2: + if(len==5) + { + data.value=input.bytes[2]<<8 | input.bytes[3]; + data.distance=(value);//distance,units:mm + if(value<20) + data.distance = "Invalid Reading"; + } + else + data.distance = "No Sensor"; + return { + data:data, + }; + +default: + return { + errors: ["unknown FPort"] + } +} +} \ No newline at end of file diff --git a/transform_binary_payload/src-payload-decoders/node/dragino_lds01.js b/transform_binary_payload/src-payload-decoders/node/dragino_lds01.js new file mode 100644 index 0000000..4bdb0d5 --- /dev/null +++ b/transform_binary_payload/src-payload-decoders/node/dragino_lds01.js @@ -0,0 +1,57 @@ +function decodeUplink(input) { + var port = input.fPort; + var bytes = input.bytes; + var value=(bytes[0]<<8 | bytes[1])&0x3FFF; + var bat=value/1000;//Battery,units:V + + var door_open_status=bytes[0]&0x80?1:0;//1:open,0:close + var water_leak_status=bytes[0]&0x40?1:0; + + var mod=bytes[2]; + var alarm=bytes[9]&0x01; + var data = {}; + switch (input.fPort) { + case 10: + if(mod==1){ + var open_times=bytes[3]<<16 | bytes[4]<<8 | bytes[5]; + var open_duration=bytes[6]<<16 | bytes[7]<<8 | bytes[8];//units:min + data.BAT_V=bat, + data.MOD=mod, + data.DOOR_OPEN_STATUS=door_open_status, + data.DOOR_OPEN_TIMES=open_times, + data.LAST_DOOR_OPEN_DURATION=open_duration, + data.ALARM=alarm + + } + else if(mod==2) + { + var leak_times=bytes[3]<<16 | bytes[4]<<8 | bytes[5]; + var leak_duration=bytes[6]<<16 | bytes[7]<<8 | bytes[8];//units:min + data.BAT_V=bat, + data.MOD=mod, + data.WATER_LEAK_STATUS=water_leak_status, + data.WATER_LEAK_TIMES=leak_times, + data.LAST_WATER_LEAK_DURATION=leak_duration + } + else if(mod==3) + { + data.BAT_V=bat, + data.MOD=mod, + data.DOOR_OPEN_STATUS=door_open_status, + data.WATER_LEAK_STATUS=water_leak_status, + data.ALARM=alarm + + } + else{ + data.BAT_V=bat, + data.MOD=mod + } + return { + data: data, + } + default: + return { + errors: ["unknown FPort"] + } +} +} diff --git a/transform_binary_payload/src-payload-decoders/node/dragino_lse01.js b/transform_binary_payload/src-payload-decoders/node/dragino_lse01.js new file mode 100644 index 0000000..74f5d41 --- /dev/null +++ b/transform_binary_payload/src-payload-decoders/node/dragino_lse01.js @@ -0,0 +1,35 @@ +function decodeUplink(input) { + var port = input.fPort; +var bytes = input.bytes; + var value=(bytes[0]<<8 | bytes[1]) & 0x3FFF; + var batV=value/1000;//Battery,units:V + value=bytes[2]<<8 | bytes[3]; + var data = {}; +switch (input.fPort) { + case 2: + if(bytes[2] & 0x80) + {value |= 0xFFFF0000;} + data.Bat=batV; + data.TempC_DS18B20=(value/10).toFixed(1);//DS18B20,temperature,units:℃ + + value=bytes[4]<<8 | bytes[5]; + data.water_SOIL=(value/100).toFixed(2);//water_SOIL,Humidity,units:% + + value=bytes[6]<<8 | bytes[7]; + if((value & 0x8000)>>15 === 0) + data.temp_SOIL=(value/100).toFixed(2);//temp_SOIL,temperature,units:°C + else if((value & 0x8000)>>15 === 1) + data.temp_SOIL=((value-0xFFFF)/100).toFixed(2);//temp_SOIL,temperature,units:°C + + value=bytes[8]<<8 | bytes[9]; + data.conduct_SOIL=(value);//conduct_SOIL,conductivity,units:uS/cm + + return { + data:data, + }; + default: + return { + errors: ["unknown FPort"] + } +} +} \ No newline at end of file diff --git a/transform_binary_payload/src-payload-decoders/node/dragino_lsn50v2.js b/transform_binary_payload/src-payload-decoders/node/dragino_lsn50v2.js new file mode 100644 index 0000000..924ef93 --- /dev/null +++ b/transform_binary_payload/src-payload-decoders/node/dragino_lsn50v2.js @@ -0,0 +1,100 @@ +function decodeUplink(input) { + var mode=(input.bytes[6] & 0x7C)>>2; + var data = {}; + switch (input.fPort) { + case 2: + if((mode!=2)&&(mode!=31)) +{ + data.BatV=(input.bytes[0]<<8 | input.bytes[1])/1000; + data.TempC1= parseFloat(((input.bytes[2]<<24>>16 | input.bytes[3])/10).toFixed(2)); + data.ADC_CH0V=(input.bytes[4]<<8 | input.bytes[5])/1000; + data.Digital_IStatus=(input.bytes[6] & 0x02)? "H":"L"; + if(mode!=6) + { + data.EXTI_Trigger=(input.bytes[6] & 0x01)? "TRUE":"FALSE"; + data.Door_status=(input.bytes[6] & 0x80)? "CLOSE":"OPEN"; + } +} + if(mode=='0') +{ + data.Work_mode="IIC"; + if((input.bytes[9]<<8 | input.bytes[10])===0) + { + data.Illum=(input.bytes[7]<<24>>16 |input.bytes[8]); + } + else + { + data.TempC_SHT=parseFloat(((input.bytes[7]<<24>>16 | input.bytes[8])/10).toFixed(2)); + data.Hum_SHT=parseFloat(((input.bytes[9]<<8 | input.bytes[10])/10).toFixed(1)); + } +} +else if(mode=='1') +{ + data.Work_mode=" Distance"; + data.Distance_cm=parseFloat(((input.bytes[7]<<8 | input.bytes[8])/10) .toFixed(1)); + if((input.bytes[9]<<8 | input.bytes[10])!=65535) + { + data.Distance_signal_strength=parseFloat((input.bytes[9]<<8 | input.bytes[10]) .toFixed(0)); + } +} +else if(mode=='2') +{ + data.Work_mode=" 3ADC"; + data.BatV=input.bytes[11]/10; + data.ADC_CH0V=(input.bytes[0]<<8 | input.bytes[1])/1000; + data.ADC_CH1V=(input.bytes[2]<<8 | input.bytes[3])/1000; + data.ADC_CH4V=(input.bytes[4]<<8 | input.bytes[5])/1000; + data.Digital_IStatus=(input.bytes[6] & 0x02)? "H":"L"; + data.EXTI_Trigger=(input.bytes[6] & 0x01)? "TRUE":"FALSE"; + data.Door_status=(input.bytes[6] & 0x80)? "CLOSE":"OPEN"; + if((input.bytes[9]<<8 | input.bytes[10])===0) + { + data.Illum=(input.bytes[7]<<24>>16 | input.bytes[8]); + } + else + { + data.TempC_SHT=parseFloat(((input.bytes[7]<<24>>16 |input.bytes[8])/10).toFixed(2)); + data.Hum_SHT=parseFloat(((input.bytes[9]<<8 | input.bytes[10])/10) .toFixed(1)); + } +} +else if(mode=='3') +{ + data.Work_mode="3DS18B20"; + data.TempC2=parseFloat(((input.bytes[7]<<24>>16 | input.bytes[8])/10).toFixed(2)); + data.TempC3=parseFloat(((input.bytes[9]<<8 | input.bytes[10])/10) .toFixed(1)); + +} +else if(mode=='4') +{ + data.Work_mode="Weight"; + data.Weight=(input.bytes[7]<<24>>16 | input.bytes[8]); +} +else if(mode=='5') +{ + data.Work_mode="Count"; + data.Count=(input.bytes[7]<<24 | input.bytes[8]<<16 | input.bytes[9]<<8 | input.bytes[10]); +} +else if(mode=='31') +{ + data.Work_mode="ALARM"; + data.BatV=(input.bytes[0]<<8 | input.bytes[1])/1000; + data.TempC1= parseFloat(((input.bytes[2]<<24>>16 | input.bytes[3])/10).toFixed(2)); + data.TempC1MIN= input.bytes[4]<<24>>24; + data.TempC1MAX= input.bytes[5]<<24>>24; + data.SHTEMPMIN= input.bytes[7]<<24>>24; + data.SHTEMPMAX= input.bytes[8]<<24>>24; + data.SHTHUMMIN= input.bytes[9]; + data.SHTHUMMAX= input.bytes[10]; +} + + if((input.bytes.length==11)||(input.bytes.length==12)) + return { + data: data, + } + break; +default: + return { + errors: ["unknown FPort"] + } + } +} \ No newline at end of file diff --git a/transform_binary_payload/src-payload-decoders/node/dragino_lt22222-l.js b/transform_binary_payload/src-payload-decoders/node/dragino_lt22222-l.js new file mode 100644 index 0000000..8e724a8 --- /dev/null +++ b/transform_binary_payload/src-payload-decoders/node/dragino_lt22222-l.js @@ -0,0 +1,112 @@ +function decodeUplink(input) { + var port = input.fPort; +var bytes = input.bytes; + var hardware= (bytes[10] & 0xC0)>>6; + var mode0= bytes[10] & 0xff; + var mode= bytes[10] & 0x3f; + var data = {}; +switch (input.fPort) { + case 2: + + if(hardware=='0') + { + data.Hardware_mode="LT33222"; + data.DO3_status=(bytes[8] &0x04)? "L":"H"; + if(mode0=='1') + { + data.DI3_status= (bytes[8] &0x20)?"H":"L"; + } + } + else if(hardware=='1') + { + data.Hardware_mode= "LT22222"; + } + + if(mode!=6) + { + data.DO1_status= (bytes[8] &0x01)? "L":"H"; + data.DO2_status= (bytes[8] &0x02)? "L":"H"; + data.RO1_status= (bytes[8] &0x80)? "ON":"OFF"; + data.RO2_status= (bytes[8] &0x40)? "ON":"OFF"; + if(mode!=1) + { + if(mode!=5) + { + data.Count1_times= (bytes[0]<<24 | bytes[1]<<16 | bytes[2]<<8 | bytes[3]); + } + data.First_status= (bytes[8] &0x20)? "Yes":"No"; + } + } + + if(mode=='1') + { + data.Work_mode= "2ACI+2AVI"; + data.AVI1_V= parseFloat(((bytes[0]<<24>>16 | bytes[1])/1000).toFixed(3)); + data.AVI2_V= parseFloat(((bytes[2]<<24>>16 | bytes[3])/1000).toFixed(3)); + data.ACI1_mA= parseFloat(((bytes[4]<<24>>16 | bytes[5])/1000).toFixed(3)); + data.ACI2_mA= parseFloat(((bytes[6]<<24>>16 | bytes[7])/1000).toFixed(3)); + data.DI1_status= (bytes[8] &0x08)? "H":"L"; + data.DI2_status= (bytes[8] &0x10)? "H":"L" + } + else if(mode=='2') + { + data.Work_mode= "Count mode 1"; + data.Count2_times= (bytes[4]<<24 | bytes[5]<<16 | bytes[6]<<8 | bytes[7]); + } + else if(mode=='3') + { + data.Work_mode= "2ACI+1Count"; + data.ACI1_mA= parseFloat(((bytes[4]<<24>>16 | bytes[5])/1000).toFixed(3)); + data.ACI2_mA= parseFloat(((bytes[6]<<24>>16 | bytes[7])/1000).toFixed(3)); + } + else if(mode=='4') + { + data.Work_mode= "Count mode 2"; + data.Acount_times= (bytes[4]<<24 | bytes[5]<<16 | bytes[6]<<8 | bytes[7]); + } + else if(mode=='5') + { + data.Work_mode= " 1ACI+2AVI+1Count"; + data.AVI1_V= parseFloat(((bytes[0]<<24>>16 | bytes[1])/1000).toFixed(3)); + data.AVI2_V= parseFloat(((bytes[2]<<24>>16 | bytes[3])/1000).toFixed(3)); + data.ACI1_mA= parseFloat(((bytes[4]<<24>>16 | bytes[5])/1000).toFixed(3)); + data.Count1_times= bytes[6]<<8 | bytes[7]; + } + else if(mode=='6') + { + data.Work_mode= "Exit mode"; + data.Mode_status= bytes[9] ? "True":"False"; + data.AV1L_flag= (bytes[0] &0x80)? "True":"False"; + data.AV1H_flag= (bytes[0] &0x40)? "True":"False"; + data.AV2L_flag= (bytes[0] &0x20)? "True":"False"; + data.AV2H_flag= (bytes[0] &0x10)? "True":"False"; + data.AC1L_flag= (bytes[0] &0x08)? "True":"False"; + data.AC1H_flag= (bytes[0] &0x04)? "True":"False"; + data.AC2L_flag= (bytes[0] &0x02)? "True":"False"; + data.AC2H_flag= (bytes[0] &0x01)? "True":"False"; + data.AV1L_status= (bytes[1] &0x80)? "True":"False"; + data.AV1H_status= (bytes[1] &0x40)? "True":"False"; + data.AV2L_status= (bytes[1] &0x20)? "True":"False"; + data.AV2H_status= (bytes[1] &0x10)? "True":"False"; + data.AC1L_status= (bytes[1] &0x08)? "True":"False"; + data.AC1H_status= (bytes[1] &0x04)? "True":"False"; + data.AC2L_status= (bytes[1] &0x02)? "True":"False"; + data.AC2H_status= (bytes[1] &0x01)? "True":"False"; + data.DI2_status= (bytes[2] &0x08)? "True":"False"; + data.DI2_flag= (bytes[2] &0x04)? "True":"False"; + data.DI1_status= (bytes[2] &0x02)? "True":"False"; + data.DI1_flag= (bytes[2] &0x01)? "True":"False"; + } + + if(bytes.length==11) + { + return { + data:data, + }; + } + default: + return { + errors: ["unknown FPort"] + } +} +} \ No newline at end of file diff --git a/transform_binary_payload/src-payload-decoders/node/dragino_lt33222-l.js b/transform_binary_payload/src-payload-decoders/node/dragino_lt33222-l.js new file mode 100644 index 0000000..8e724a8 --- /dev/null +++ b/transform_binary_payload/src-payload-decoders/node/dragino_lt33222-l.js @@ -0,0 +1,112 @@ +function decodeUplink(input) { + var port = input.fPort; +var bytes = input.bytes; + var hardware= (bytes[10] & 0xC0)>>6; + var mode0= bytes[10] & 0xff; + var mode= bytes[10] & 0x3f; + var data = {}; +switch (input.fPort) { + case 2: + + if(hardware=='0') + { + data.Hardware_mode="LT33222"; + data.DO3_status=(bytes[8] &0x04)? "L":"H"; + if(mode0=='1') + { + data.DI3_status= (bytes[8] &0x20)?"H":"L"; + } + } + else if(hardware=='1') + { + data.Hardware_mode= "LT22222"; + } + + if(mode!=6) + { + data.DO1_status= (bytes[8] &0x01)? "L":"H"; + data.DO2_status= (bytes[8] &0x02)? "L":"H"; + data.RO1_status= (bytes[8] &0x80)? "ON":"OFF"; + data.RO2_status= (bytes[8] &0x40)? "ON":"OFF"; + if(mode!=1) + { + if(mode!=5) + { + data.Count1_times= (bytes[0]<<24 | bytes[1]<<16 | bytes[2]<<8 | bytes[3]); + } + data.First_status= (bytes[8] &0x20)? "Yes":"No"; + } + } + + if(mode=='1') + { + data.Work_mode= "2ACI+2AVI"; + data.AVI1_V= parseFloat(((bytes[0]<<24>>16 | bytes[1])/1000).toFixed(3)); + data.AVI2_V= parseFloat(((bytes[2]<<24>>16 | bytes[3])/1000).toFixed(3)); + data.ACI1_mA= parseFloat(((bytes[4]<<24>>16 | bytes[5])/1000).toFixed(3)); + data.ACI2_mA= parseFloat(((bytes[6]<<24>>16 | bytes[7])/1000).toFixed(3)); + data.DI1_status= (bytes[8] &0x08)? "H":"L"; + data.DI2_status= (bytes[8] &0x10)? "H":"L" + } + else if(mode=='2') + { + data.Work_mode= "Count mode 1"; + data.Count2_times= (bytes[4]<<24 | bytes[5]<<16 | bytes[6]<<8 | bytes[7]); + } + else if(mode=='3') + { + data.Work_mode= "2ACI+1Count"; + data.ACI1_mA= parseFloat(((bytes[4]<<24>>16 | bytes[5])/1000).toFixed(3)); + data.ACI2_mA= parseFloat(((bytes[6]<<24>>16 | bytes[7])/1000).toFixed(3)); + } + else if(mode=='4') + { + data.Work_mode= "Count mode 2"; + data.Acount_times= (bytes[4]<<24 | bytes[5]<<16 | bytes[6]<<8 | bytes[7]); + } + else if(mode=='5') + { + data.Work_mode= " 1ACI+2AVI+1Count"; + data.AVI1_V= parseFloat(((bytes[0]<<24>>16 | bytes[1])/1000).toFixed(3)); + data.AVI2_V= parseFloat(((bytes[2]<<24>>16 | bytes[3])/1000).toFixed(3)); + data.ACI1_mA= parseFloat(((bytes[4]<<24>>16 | bytes[5])/1000).toFixed(3)); + data.Count1_times= bytes[6]<<8 | bytes[7]; + } + else if(mode=='6') + { + data.Work_mode= "Exit mode"; + data.Mode_status= bytes[9] ? "True":"False"; + data.AV1L_flag= (bytes[0] &0x80)? "True":"False"; + data.AV1H_flag= (bytes[0] &0x40)? "True":"False"; + data.AV2L_flag= (bytes[0] &0x20)? "True":"False"; + data.AV2H_flag= (bytes[0] &0x10)? "True":"False"; + data.AC1L_flag= (bytes[0] &0x08)? "True":"False"; + data.AC1H_flag= (bytes[0] &0x04)? "True":"False"; + data.AC2L_flag= (bytes[0] &0x02)? "True":"False"; + data.AC2H_flag= (bytes[0] &0x01)? "True":"False"; + data.AV1L_status= (bytes[1] &0x80)? "True":"False"; + data.AV1H_status= (bytes[1] &0x40)? "True":"False"; + data.AV2L_status= (bytes[1] &0x20)? "True":"False"; + data.AV2H_status= (bytes[1] &0x10)? "True":"False"; + data.AC1L_status= (bytes[1] &0x08)? "True":"False"; + data.AC1H_status= (bytes[1] &0x04)? "True":"False"; + data.AC2L_status= (bytes[1] &0x02)? "True":"False"; + data.AC2H_status= (bytes[1] &0x01)? "True":"False"; + data.DI2_status= (bytes[2] &0x08)? "True":"False"; + data.DI2_flag= (bytes[2] &0x04)? "True":"False"; + data.DI1_status= (bytes[2] &0x02)? "True":"False"; + data.DI1_flag= (bytes[2] &0x01)? "True":"False"; + } + + if(bytes.length==11) + { + return { + data:data, + }; + } + default: + return { + errors: ["unknown FPort"] + } +} +} \ No newline at end of file diff --git a/transform_binary_payload/src-payload-decoders/node/dragino_lwl01.js b/transform_binary_payload/src-payload-decoders/node/dragino_lwl01.js new file mode 100644 index 0000000..4bdb0d5 --- /dev/null +++ b/transform_binary_payload/src-payload-decoders/node/dragino_lwl01.js @@ -0,0 +1,57 @@ +function decodeUplink(input) { + var port = input.fPort; + var bytes = input.bytes; + var value=(bytes[0]<<8 | bytes[1])&0x3FFF; + var bat=value/1000;//Battery,units:V + + var door_open_status=bytes[0]&0x80?1:0;//1:open,0:close + var water_leak_status=bytes[0]&0x40?1:0; + + var mod=bytes[2]; + var alarm=bytes[9]&0x01; + var data = {}; + switch (input.fPort) { + case 10: + if(mod==1){ + var open_times=bytes[3]<<16 | bytes[4]<<8 | bytes[5]; + var open_duration=bytes[6]<<16 | bytes[7]<<8 | bytes[8];//units:min + data.BAT_V=bat, + data.MOD=mod, + data.DOOR_OPEN_STATUS=door_open_status, + data.DOOR_OPEN_TIMES=open_times, + data.LAST_DOOR_OPEN_DURATION=open_duration, + data.ALARM=alarm + + } + else if(mod==2) + { + var leak_times=bytes[3]<<16 | bytes[4]<<8 | bytes[5]; + var leak_duration=bytes[6]<<16 | bytes[7]<<8 | bytes[8];//units:min + data.BAT_V=bat, + data.MOD=mod, + data.WATER_LEAK_STATUS=water_leak_status, + data.WATER_LEAK_TIMES=leak_times, + data.LAST_WATER_LEAK_DURATION=leak_duration + } + else if(mod==3) + { + data.BAT_V=bat, + data.MOD=mod, + data.DOOR_OPEN_STATUS=door_open_status, + data.WATER_LEAK_STATUS=water_leak_status, + data.ALARM=alarm + + } + else{ + data.BAT_V=bat, + data.MOD=mod + } + return { + data: data, + } + default: + return { + errors: ["unknown FPort"] + } +} +} diff --git a/transform_binary_payload/src-payload-decoders/python/dragino_laq4.py b/transform_binary_payload/src-payload-decoders/python/dragino_laq4.py new file mode 100644 index 0000000..5fc92cb --- /dev/null +++ b/transform_binary_payload/src-payload-decoders/python/dragino_laq4.py @@ -0,0 +1,64 @@ +import base64 + + +def dict_from_payload(base64_input: str, fport: int = None): + """ Decodes a base64-encoded binary payload into JSON. + Parameters + ---------- + base64_input : str + Base64-encoded binary payload + fport: int + FPort as provided in the metadata. Please note the fport is optional and can have value "None", if not provided by the LNS or invoking function. + If fport is None and binary decoder can not proceed because of that, it should should raise an exception. + Returns + ------- + JSON object with key/value pairs of decoded attributes + """ +bytes = base64.b64decode(base64_input) + mode=(bytes[2] & 0x7C)>>2 + Bat_V=(bytes[0]<<8 | bytes[1])/1000; + if(mode==1): + { + Work_mode="CO2"; + Alarm_status=(bytes[2] & 0x01) and "TRUE" or "FALSE" + TVOC_ppb= bytes[3]<<8 | bytes[4]; + CO2_ppm= bytes[5]<<8 | bytes[6]; + TempC_SHT=parseFloat(((bytes[7]<<24>>16 | bytes[8])/10).toFixed(2)); + Hum_SHT=parseFloat(((bytes[9]<<8 | bytes[10])/10).toFixed(1)); + } + result = { + "Mode": mode, + "battery": BatV, + "Work_mode": Work_mode, + "Alarm_status": Alarm_status, + "TVOC_ppb": TVOC_ppb, + "CO2_ppm": CO2_ppm, + "TempC_SHT": TempC_SHT, + "Hum_SHT": Hum_SHT, + } + return result + + elif(mode==31): + { + Work_mode="ALARM"; + SHTEMPMIN= bytes[3]<<24>>24; + SHTEMPMAX= bytes[4]<<24>>24; + SHTHUMMIN= bytes[5]; + SHTHUMMAX= bytes[6]; + CO2MIN= bytes[7]<<8 | bytes[8]; + CO2MAX= bytes[9]<<8 | bytes[10]; + } + result = { + "Mode": mode, + "battery": BatV, + "Work_mode": Work_mode, + "CO2MIN": CO2MIN, + "CO2MAX": CO2MAX, + "SHTEMPMIN": SHTEMPMIN, + "SHTEMPMAX": SHTEMPMAX, + "SHTHUMMIN": SHTHUMMIN, + "SHTHUMMAX": SHTHUMMAX, + } + return result + + \ No newline at end of file diff --git a/transform_binary_payload/src-payload-decoders/python/dragino_ldds20.py b/transform_binary_payload/src-payload-decoders/python/dragino_ldds20.py new file mode 100644 index 0000000..57488ce --- /dev/null +++ b/transform_binary_payload/src-payload-decoders/python/dragino_ldds20.py @@ -0,0 +1,39 @@ +import base64 + + +def dict_from_payload(base64_input: str, fport: int = None): + """ Decodes a base64-encoded binary payload into JSON. + Parameters + ---------- + base64_input : str + Base64-encoded binary payload + fport: int + FPort as provided in the metadata. Please note the fport is optional and can have value "None", if not provided by the LNS or invoking function. + If fport is None and binary decoder can not proceed because of that, it should should raise an exception. + Returns + ------- + JSON object with key/value pairs of decoded attributes + """ + decoded = base64.b64decode(base64_input) + + len=decoded.length + value=(decoded[0]<<8 | decoded[1]) & 0x3FFF + batV=value/1000 + distance = 0 + if(len==5): + { + value=decoded[2]<<8 | decoded[3] + distance=(value) + if(value<20): + distance = "Invalid Reading" + } + else: + distance = "No Sensor" + interrupt = decoded[len-1] + result ={ + "Bat":batV , + "Distance":distance, + "Interrupt_status":interrupt + } + +return result diff --git a/transform_binary_payload/src-payload-decoders/python/dragino_ldds75.py b/transform_binary_payload/src-payload-decoders/python/dragino_ldds75.py new file mode 100644 index 0000000..57488ce --- /dev/null +++ b/transform_binary_payload/src-payload-decoders/python/dragino_ldds75.py @@ -0,0 +1,39 @@ +import base64 + + +def dict_from_payload(base64_input: str, fport: int = None): + """ Decodes a base64-encoded binary payload into JSON. + Parameters + ---------- + base64_input : str + Base64-encoded binary payload + fport: int + FPort as provided in the metadata. Please note the fport is optional and can have value "None", if not provided by the LNS or invoking function. + If fport is None and binary decoder can not proceed because of that, it should should raise an exception. + Returns + ------- + JSON object with key/value pairs of decoded attributes + """ + decoded = base64.b64decode(base64_input) + + len=decoded.length + value=(decoded[0]<<8 | decoded[1]) & 0x3FFF + batV=value/1000 + distance = 0 + if(len==5): + { + value=decoded[2]<<8 | decoded[3] + distance=(value) + if(value<20): + distance = "Invalid Reading" + } + else: + distance = "No Sensor" + interrupt = decoded[len-1] + result ={ + "Bat":batV , + "Distance":distance, + "Interrupt_status":interrupt + } + +return result diff --git a/transform_binary_payload/src-payload-decoders/python/dragino_lds01.py b/transform_binary_payload/src-payload-decoders/python/dragino_lds01.py index ffb8287..67e61d3 100644 --- a/transform_binary_payload/src-payload-decoders/python/dragino_lds01.py +++ b/transform_binary_payload/src-payload-decoders/python/dragino_lds01.py @@ -1,80 +1,61 @@ -# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. -# SPDX-License-Identifier: MIT-0 -# -# Permission is hereby granted, free of charge, to any person obtaining a copy of this -# software and associated documentation files (the "Software"), to deal in the Software -# without restriction, including without limitation the rights to use, copy, modify, -# merge, publish, distribute, sublicense, and/or sell copies of the Software, and to -# permit persons to whom the Software is furnished to do so. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, -# INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A -# PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT -# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - - -import base64 - - -def dict_from_payload(base64_input: str, fport: int = None): - """ Decodes a base64-encoded binary payload into JSON. - Parameters - ---------- - base64_input : str - Base64-encoded binary payload - fport: int - FPort as provided in the metadata. Please note the fport is optional and can have value "None", if not provided by the LNS or invoking function. - - If fport is None and binary decoder can not proceed because of that, it should should raise an exception. - - Returns - ------- - JSON object with key/value pairs of decoded attributes - - """ - - bytes = base64.b64decode(base64_input) - battery = (bytes[0] << 8 | bytes[1]) & 0x3FFF - door_open_status = 0 - - if bytes[0] & 0x40: - water_leak_status = 1 - - water_leak_status = 0 - if bytes[0] & 0x80: - door_open_status = 1 - - mod = bytes[2] - - if mod == 1: - open_times = bytes[3] << 16 | bytes[4] << 8 | bytes[5] - open_duration = bytes[6] << 16 | bytes[7] << 8 | bytes[8] - result = { - "mod": mod, - "battery": battery, - "door_open_status": door_open_status, - "open_times": open_times, - "open_duration": open_duration - } - - return result - - if mod == 2: - leak_times = bytes[3] << 16 | bytes[4] << 8 | bytes[5] - leak_duration = bytes[6] << 16 | bytes[7] << 8 | bytes[8] - - result = { - "mod": mod, - "battery": battery, - "leak_times": leak_times, - "leak_duration": leak_duration - } - - return result - - result = { - "battery": battery, - "mod": mod - } +import base64 + + +def dict_from_payload(base64_input: str, fport: int = None): + """ Decodes a base64-encoded binary payload into JSON. + Parameters + ---------- + base64_input : str + Base64-encoded binary payload + fport: int + FPort as provided in the metadata. Please note the fport is optional and can have value "None", if not provided by the LNS or invoking function. + If fport is None and binary decoder can not proceed because of that, it should should raise an exception. + Returns + ------- + JSON object with key/value pairs of decoded attributes + """ + + bytes = base64.b64decode(base64_input) + value= (bytes[0] << 8 | bytes[1]) & 0x3FFF + battery = value/1000 + door_open_status = 0 + + if bytes[0] & 0x40: + water_leak_status = 1 + + water_leak_status = 0 + if bytes[0] & 0x80: + door_open_status = 1 + + mod = bytes[2] + + if mod == 1: + open_times = bytes[3] << 16 | bytes[4] << 8 | bytes[5] + open_duration = bytes[6] << 16 | bytes[7] << 8 | bytes[8] + result = { + "mod": mod, + "battery": battery, + "door_open_status": door_open_status, + "open_times": open_times, + "open_duration": open_duration + } + + return result + + if mod == 2: + leak_times = bytes[3] << 16 | bytes[4] << 8 | bytes[5] + leak_duration = bytes[6] << 16 | bytes[7] << 8 | bytes[8] + + result = { + "mod": mod, + "battery": battery, + "leak_times": leak_times, + "leak_duration": leak_duration + } + + return result + + result = { + "battery": battery, + "mod": mod + } \ No newline at end of file diff --git a/transform_binary_payload/src-payload-decoders/python/dragino_lse01.py b/transform_binary_payload/src-payload-decoders/python/dragino_lse01.py index 6f0be83..b19bb12 100644 --- a/transform_binary_payload/src-payload-decoders/python/dragino_lse01.py +++ b/transform_binary_payload/src-payload-decoders/python/dragino_lse01.py @@ -1,70 +1,50 @@ -# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. -# SPDX-License-Identifier: MIT-0 -# -# Permission is hereby granted, free of charge, to any person obtaining a copy of this -# software and associated documentation files (the "Software"), to deal in the Software -# without restriction, including without limitation the rights to use, copy, modify, -# merge, publish, distribute, sublicense, and/or sell copies of the Software, and to -# permit persons to whom the Software is furnished to do so. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, -# INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A -# PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT -# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - - -import base64 - - -def dict_from_payload(base64_input: str, fport: int = None): - """ Decodes a base64-encoded binary payload into JSON. - Parameters - ---------- - base64_input : str - Base64-encoded binary payload - fport: int - FPort as provided in the metadata. Please note the fport is optional and can have value "None", if not provided by the LNS or invoking function. - - If fport is None and binary decoder can not proceed because of that, it should should raise an exception. - - Returns - ------- - JSON object with key/value pairs of decoded attributes - - """ - - decoded = base64.b64decode(base64_input) - - value = (decoded[0] << 8 | decoded[1]) & 0x3FFF - battery_value = value # /Battery,units:V - - value = decoded[2] << 8 | decoded[3] - if decoded[2] & 0x80: - value |= 0xFFFF0000 - - temp_DS18B20 = (value/10) # /DS18B20,temperature,units:℃ - - value = decoded[4] << 8 | decoded[5] - water_SOIL = (value/100) # /water_SOIL,Humidity,units:% - - value = decoded[6] << 8 | decoded[7] - - if ((value & 0x8000) >> 15) == 0: - temp_SOIL = (value/100) # /temp_SOIL,temperature,units:°C - elif ((value & 0x8000) >> 15) == 1: - temp_SOIL = ((value-0xFFFF)/100) - - value = decoded[8] << 8 | decoded[9] - conduct_SOIL = (value/100) # /conduct_SOIL,conductivity,units:uS/cm - - result = { - "battery_value": battery_value, - "temperature_internal": temp_DS18B20, - "water_soil": water_SOIL, - "temperature_soil": temp_SOIL, - "conduct_soil": conduct_SOIL - - } - return result +import base64 + + +def dict_from_payload(base64_input: str, fport: int = None): + """ Decodes a base64-encoded binary payload into JSON. + Parameters + ---------- + base64_input : str + Base64-encoded binary payload + fport: int + FPort as provided in the metadata. Please note the fport is optional and can have value "None", if not provided by the LNS or invoking function. + If fport is None and binary decoder can not proceed because of that, it should should raise an exception. + Returns + ------- + JSON object with key/value pairs of decoded attributes + """ + + decoded = base64.b64decode(base64_input) + + value = (decoded[0] << 8 | decoded[1]) & 0x3FFF + battery_value = value/1000 # /Battery,units:V + + value = decoded[2] << 8 | decoded[3] + if decoded[2] & 0x80: + value |= 0xFFFF0000 + + temp_DS18B20 = (value/10) # /DS18B20,temperature,units:℃ + + value = decoded[4] << 8 | decoded[5] + water_SOIL = (value/100) # /water_SOIL,Humidity,units:% + + value = decoded[6] << 8 | decoded[7] + + if ((value & 0x8000) >> 15) == 0: + temp_SOIL = (value/100) # /temp_SOIL,temperature,units:°C + elif ((value & 0x8000) >> 15) == 1: + temp_SOIL = ((value-0xFFFF)/100) + + value = decoded[8] << 8 | decoded[9] + conduct_SOIL = (value/100) # /conduct_SOIL,conductivity,units:uS/cm + + result = { + "battery_value": battery_value, + "temperature_internal": temp_DS18B20, + "water_soil": water_SOIL, + "temperature_soil": temp_SOIL, + "conduct_soil": conduct_SOIL + + } + return result \ No newline at end of file diff --git a/transform_binary_payload/src-payload-decoders/python/dragino_lsn50v2.py b/transform_binary_payload/src-payload-decoders/python/dragino_lsn50v2.py new file mode 100644 index 0000000..9c52efe --- /dev/null +++ b/transform_binary_payload/src-payload-decoders/python/dragino_lsn50v2.py @@ -0,0 +1,183 @@ +import base64 + + +def dict_from_payload(base64_input: str, fport: int = None): + """ Decodes a base64-encoded binary payload into JSON. + Parameters + ---------- + base64_input : str + Base64-encoded binary payload + fport: int + FPort as provided in the metadata. Please note the fport is optional and can have value "None", if not provided by the LNS or invoking function. + If fport is None and binary decoder can not proceed because of that, it should should raise an exception. + Returns + ------- + JSON object with key/value pairs of decoded attributes + """ + +bytes = base64.b64decode(base64_input) +mode=(bytes[6] & 0x7C)>>2 +if(mode!=2)and(mode!=31): +{ + BatV=(bytes[0]<<8 | bytes[1])/1000 + TempC1= parseFloat(((bytes[2]<<24>>16 | bytes[3])/10).toFixed(2)) + ADC_CH0V=(bytes[4]<<8 | bytes[5])/1000 + Digital_IStatus=((bytes[6] & 0x02)==2) and "H" or "L" + if(mode!=6): + { + EXTI_Trigger=((bytes[6] & 0x01)==1) and "TRUE" or "FALSE" + Door_status=((bytes[6] & 0x80)==128) and "CLOSE" or "OPEN" + } +} + result = { + "Mode": mode, + "TempC1": TempC1, + "battery": BatV, + "ADC_CH0V": ADC_CH0V, + "Digital_IStatus": Digital_IStatus + "EXTI_Trigger": EXTI_Trigger + "Door_status": Door_status + } + + return result + + +if(mode=='0'): +{ + Work_mode="IIC"; + if((bytes[9]<<8 | bytes[10])===0): + { + Illum=(bytes[7]<<24>>16 | bytes[8]); + } + else: + { + TempC_SHT=parseFloat(((bytes[7]<<24>>16 | bytes[8])/10).toFixed(2)); + Hum_SHT=parseFloat(((bytes[9]<<8 | bytes[10])/10).toFixed(1)); + } + result = { + + "Work_mode": Work_mode, + "Illum": Illum, + "TempC_SHT": TempC_SHT + "Hum_SHT": Hum_SHT + } + + return result +} +elif(mode=='1'): +{ + Work_mode=" Distance"; + Distance_cm=parseFloat(((bytes[7]<<8 | bytes[8])/10) .toFixed(1)); + if((bytes[9]<<8 | bytes[10])!=65535): + { + Distance_signal_strength=parseFloat((bytes[9]<<8 | bytes[10]) .toFixed(0)); + } +} + result = { + "Work_mode": Work_mode, + "Distance_cm": Distance_cm, + "Distance_signal_strength": Distance_signal_strength + } + + return result + +elif(mode=='2'): +{ + Work_mode=" 3ADC"; + BatV=bytes[11]/10; + ADC_CH0V=(bytes[0]<<8 | bytes[1])/1000; + ADC_CH1V=(bytes[2]<<8 | bytes[3])/1000; + ADC_CH4V=(bytes[4]<<8 | bytes[5])/1000; + Digital_IStatus=((bytes[6] & 0x02)==2) and "H" or "L" + EXTI_Trigger=((bytes[6] & 0x01)==1) and "TRUE" or "FALSE" + Door_status=((bytes[6] & 0x80)==128) and "CLOSE" or "OPEN" + if((bytes[9]<<8 | bytes[10])===0): + { + Illum=(bytes[7]<<24>>16 | bytes[8]); + } + else: + { + TempC_SHT=parseFloat(((bytes[7]<<24>>16 | bytes[8])/10).toFixed(2)); + Hum_SHT=parseFloat(((bytes[9]<<8 | bytes[10])/10) .toFixed(1)); + } +} + result = { + "Mode": mode, + "Work_mode": Work_mode, + "battery": BatV, + "ADC_CH0V": ADC_CH0V, + "ADC_CH1V": ADC_CH1V, + "ADC_CH4V": ADC_CH4V, + "Digital_IStatus": Digital_IStatus + "EXTI_Trigger": EXTI_Trigger + "Door_status": Door_status + "Illum": Illum, + "TempC_SHT": TempC_SHT + "Hum_SHT": Hum_SHT + } + + return result + +elif(mode=='3'): +{ + Work_mode="3DS18B20"; + TempC2=parseFloat(((bytes[7]<<24>>16 | bytes[8])/10).toFixed(2)); + TempC3=parseFloat(((bytes[9]<<8 | bytes[10])/10) .toFixed(1)); +} + result = { + "Work_mode": Work_mode, + "TempC2": TempC1, + "TempC3": TempC1, + } + return result + +elif(mode=='4'): +{ + Work_mode="Weight"; + Weight=(bytes[7]<<24>>16 | bytes[8]); +} + result = { + "Work_mode": Work_mode, + "Weight": Weight, + } + return result + +elif(mode=='5'): +{ + Work_mode="Count"; + Count=(bytes[7]<<24 | bytes[8]<<16 | bytes[9]<<8 | bytes[10]); +} + result = { + "Work_mode": Work_mode, + "Count": Count, + } + return result + +elif(mode=='31'): +{ + Work_mode="ALARM"; + BatV=(bytes[0]<<8 | bytes[1])/1000; + TempC1= parseFloat(((bytes[2]<<24>>16 | bytes[3])/10).toFixed(2)); + TempC1MIN= bytes[4]<<24>>24; + TempC1MAX= bytes[5]<<24>>24; + SHTEMPMIN= bytes[7]<<24>>24; + SHTEMPMAX= bytes[8]<<24>>24; + SHTHUMMIN= bytes[9]; + SHTHUMMAX= bytes[10]; +} + result = { + "Mode": mode, + "Work_mode": Work_mode, + "TempC1": TempC1, + "battery": BatV, + "TempC1MIN": TempC1MIN, + "TempC1MAX": TempC1MAX, + "SHTEMPMIN": SHTEMPMIN, + "SHTEMPMAX": SHTEMPMAX, + "SHTHUMMIN": SHTHUMMIN, + "SHTHUMMAX": SHTHUMMAX, + } + return result + + + diff --git a/transform_binary_payload/src-payload-decoders/python/dragino_lt22222-l.py b/transform_binary_payload/src-payload-decoders/python/dragino_lt22222-l.py new file mode 100644 index 0000000..27504a0 --- /dev/null +++ b/transform_binary_payload/src-payload-decoders/python/dragino_lt22222-l.py @@ -0,0 +1,207 @@ +import base64 + + +def dict_from_payload(base64_input: str, fport: int = None): + """ Decodes a base64-encoded binary payload into JSON. + Parameters + ---------- + base64_input : str + Base64-encoded binary payload + fport: int + FPort as provided in the metadata. Please note the fport is optional and can have value "None", if not provided by the LNS or invoking function. + If fport is None and binary decoder can not proceed because of that, it should should raise an exception. + Returns + ------- + JSON object with key/value pairs of decoded attributes + """ +bytes = base64.b64decode(base64_input) + hardware= (bytes[10] & 0xC0)>>6 + mode0= bytes[10] & 0xff + mode= bytes[10] & 0x3f + + if(hardware=='0'): + { + Hardware_mode="LT33222"; + DO3_status=((bytes[8] &0x04)==4) and "L" or "H" + if(mode0=='1'): + { + DI3_status=((bytes[8] &0x20)==32) and "H" or "L" + } + result = { + "Mode": mode, + "Hardware_mode": Hardware_mode, + "DO3_status": DO3_status, + "DI3_status": DI3_status, + } + + return result + } + elif(hardware=='1'): + { + Hardware_mode= "LT22222"; + } + + result = { + "Mode": mode, + "Hardware_mode": Hardware_mode, + } + + return result + + if(mode!=6): + { + DO1_status=((bytes[8] &0x01)==1) and "L" or "H" + DO2_status=((bytes[8] &0x02)==2) and "L" or "H" + RO1_status=((bytes[8] &0x80)==128) and "ON" or "OFF" + RO2_status=((bytes[8] &0x40)==64) and "ON" or "OFF" + if(mode!=1): + { + if(mode!=5): + { + Count1_times= (bytes[0]<<24 | bytes[1]<<16 | bytes[2]<<8 | bytes[3]); + } + First_status=((bytes[8] &0x20)==32) and "Yes" or "No" + } + } + result = { + "DO1_status": DO1_status, + "DO2_status": DO2_status, + "RO1_status": RO1_status, + "RO2_status": RO2_status, + "Count1_times": Count1_times, + "First_status": First_status, + } + + return result + + if(mode=='1'): + { + Work_mode= "2ACI+2AVI"; + AVI1_V= parseFloat(((bytes[0]<<24>>16 | bytes[1])/1000).toFixed(3)); + AVI2_V= parseFloat(((bytes[2]<<24>>16 | bytes[3])/1000).toFixed(3)); + ACI1_mA= parseFloat(((bytes[4]<<24>>16 | bytes[5])/1000).toFixed(3)); + ACI2_mA= parseFloat(((bytes[6]<<24>>16 | bytes[7])/1000).toFixed(3)); + DI1_status=((bytes[8] &0x08)==8) and "H" or "L" + DI2_status=((bytes[8] &0x10)==16) and "H" or "L" + } + result = { + "Work_mode": Work_mode, + "AVI1_V": AVI1_V, + "AVI2_V": AVI2_V, + "ACI1_mA": ACI1_mA, + "ACI2_mA": ACI2_mA, + "DI1_status": DI1_status, + "DI2_status": DI2_status, + } + + return result + + elif(mode=='2'): + { + Work_mode= "Count mode 1"; + Count2_times= (bytes[4]<<24 | bytes[5]<<16 | bytes[6]<<8 | bytes[7]); + } + result = { + "Work_mode": Work_mode, + "Count2_times": Count2_times, + } + + return result + + elif(mode=='3'): + { + Work_mode= "2ACI+1Count"; + ACI1_mA= parseFloat(((bytes[4]<<24>>16 | bytes[5])/1000).toFixed(3)); + ACI2_mA= parseFloat(((bytes[6]<<24>>16 | bytes[7])/1000).toFixed(3)); + } + result = { + "Work_mode": Work_mode, + "ACI1_mA": ACI1_mA, + "ACI2_mA": ACI2_mA, + } + + return result + + elif(mode=='4'): + { + Work_mode= "Count mode 2"; + Acount_times= (bytes[4]<<24 | bytes[5]<<16 | bytes[6]<<8 | bytes[7]); + } + result = { + "Work_mode": Work_mode, + "Acount_times": Acount_times, + } + + return result + + elif(mode=='5'): + { + Work_mode= " 1ACI+2AVI+1Count"; + AVI1_V= parseFloat(((bytes[0]<<24>>16 | bytes[1])/1000).toFixed(3)); + AVI2_V= parseFloat(((bytes[2]<<24>>16 | bytes[3])/1000).toFixed(3)); + ACI1_mA= parseFloat(((bytes[4]<<24>>16 | bytes[5])/1000).toFixed(3)); + Count1_times= bytes[6]<<8 | bytes[7]; + } + result = { + "Work_mode": Work_mode, + "AVI1_V": AVI1_V, + "AVI2_V": AVI2_V, + "ACI1_mA": ACI1_mA, + "Count1_times": Count1_times, + } + + return result + + elif(mode=='6'): + { + Work_mode= "Exit mode"; + Mode_status=(bytes[9]==0) and "False" or "True" + AV1L_flag=((bytes[0] &0x80)==128) and "True" or "False" + AV1H_flag=((bytes[0] &0x40)==64) and "True" or "False" + AV2L_flag=((bytes[0] &0x20)==32) and "True" or "False" + AV2H_flag=((bytes[0] &0x10)==16) and "True" or "False" + AC1L_flag=((bytes[0] &0x08)==8) and "True" or "False" + AC1H_flag=((bytes[0] &0x04)==4) and "True" or "False" + AC2L_flag=((bytes[0] &0x02)==2) and "True" or "False" + AC2H_flag=((bytes[0] &0x01)==1) and "True" or "False" + AV1L_status=((bytes[1] &0x80)==128) and "True" or "False" + AV1H_status=((bytes[1] &0x40)==64) and "True" or "False" + AV2L_status=((bytes[1] &0x20)==32) and "True" or "False" + AV2H_status=((bytes[1] &0x10)==16) and "True" or "False" + AC1L_status=((bytes[1] &0x08)==8) and "True" or "False" + AC1H_status=((bytes[1] &0x04)==4) and "True" or "False" + AC2L_status=((bytes[1] &0x02)==2) and "True" or "False" + AC2H_status=((bytes[1] &0x01)==1) and "True" or "False" + DI2_status=((bytes[2] &0x08)==8) and "True" or "False" + DI2_flag=((bytes[2] &0x04)==4) and "True" or "False" + DI1_status=((bytes[2] &0x02)==2) and "True" or "False" + DI1_flag=((bytes[2] &0x01)==1) and "True" or "False" + } + result = { + "Work_mode": Work_mode, + "Mode_status": Mode_status, + "AV1L_flag": AV1L_flag, + "AV1H_flag": AV1H_flag, + "AV2L_flag": AV2L_flag, + "AV2H_flag": AV2H_flag, + "AC1L_flag": AC1L_flag, + "AC1H_flag": AC1H_flag, + "AC2L_flag": AC2L_flag, + "AC2H_flag": AC2H_flag, + "AV1L_status": AV1L_status, + "AV1H_status": AV1H_status, + "AV2L_status": AV2L_status, + "AV2H_status": AV2H_status, + "AC1L_status": AC1L_status, + "AC1H_status": AC1H_status, + "AC2L_status": AC2L_status, + "AC2H_status": AC2H_status, + "DI2_status": DI2_status, + "DI2_flag": DI2_flag, + "DI1_status": DI1_status, + "DI1_flag": DI1_flag, + } + + return result + + diff --git a/transform_binary_payload/src-payload-decoders/python/dragino_lt33222-l.py b/transform_binary_payload/src-payload-decoders/python/dragino_lt33222-l.py new file mode 100644 index 0000000..27504a0 --- /dev/null +++ b/transform_binary_payload/src-payload-decoders/python/dragino_lt33222-l.py @@ -0,0 +1,207 @@ +import base64 + + +def dict_from_payload(base64_input: str, fport: int = None): + """ Decodes a base64-encoded binary payload into JSON. + Parameters + ---------- + base64_input : str + Base64-encoded binary payload + fport: int + FPort as provided in the metadata. Please note the fport is optional and can have value "None", if not provided by the LNS or invoking function. + If fport is None and binary decoder can not proceed because of that, it should should raise an exception. + Returns + ------- + JSON object with key/value pairs of decoded attributes + """ +bytes = base64.b64decode(base64_input) + hardware= (bytes[10] & 0xC0)>>6 + mode0= bytes[10] & 0xff + mode= bytes[10] & 0x3f + + if(hardware=='0'): + { + Hardware_mode="LT33222"; + DO3_status=((bytes[8] &0x04)==4) and "L" or "H" + if(mode0=='1'): + { + DI3_status=((bytes[8] &0x20)==32) and "H" or "L" + } + result = { + "Mode": mode, + "Hardware_mode": Hardware_mode, + "DO3_status": DO3_status, + "DI3_status": DI3_status, + } + + return result + } + elif(hardware=='1'): + { + Hardware_mode= "LT22222"; + } + + result = { + "Mode": mode, + "Hardware_mode": Hardware_mode, + } + + return result + + if(mode!=6): + { + DO1_status=((bytes[8] &0x01)==1) and "L" or "H" + DO2_status=((bytes[8] &0x02)==2) and "L" or "H" + RO1_status=((bytes[8] &0x80)==128) and "ON" or "OFF" + RO2_status=((bytes[8] &0x40)==64) and "ON" or "OFF" + if(mode!=1): + { + if(mode!=5): + { + Count1_times= (bytes[0]<<24 | bytes[1]<<16 | bytes[2]<<8 | bytes[3]); + } + First_status=((bytes[8] &0x20)==32) and "Yes" or "No" + } + } + result = { + "DO1_status": DO1_status, + "DO2_status": DO2_status, + "RO1_status": RO1_status, + "RO2_status": RO2_status, + "Count1_times": Count1_times, + "First_status": First_status, + } + + return result + + if(mode=='1'): + { + Work_mode= "2ACI+2AVI"; + AVI1_V= parseFloat(((bytes[0]<<24>>16 | bytes[1])/1000).toFixed(3)); + AVI2_V= parseFloat(((bytes[2]<<24>>16 | bytes[3])/1000).toFixed(3)); + ACI1_mA= parseFloat(((bytes[4]<<24>>16 | bytes[5])/1000).toFixed(3)); + ACI2_mA= parseFloat(((bytes[6]<<24>>16 | bytes[7])/1000).toFixed(3)); + DI1_status=((bytes[8] &0x08)==8) and "H" or "L" + DI2_status=((bytes[8] &0x10)==16) and "H" or "L" + } + result = { + "Work_mode": Work_mode, + "AVI1_V": AVI1_V, + "AVI2_V": AVI2_V, + "ACI1_mA": ACI1_mA, + "ACI2_mA": ACI2_mA, + "DI1_status": DI1_status, + "DI2_status": DI2_status, + } + + return result + + elif(mode=='2'): + { + Work_mode= "Count mode 1"; + Count2_times= (bytes[4]<<24 | bytes[5]<<16 | bytes[6]<<8 | bytes[7]); + } + result = { + "Work_mode": Work_mode, + "Count2_times": Count2_times, + } + + return result + + elif(mode=='3'): + { + Work_mode= "2ACI+1Count"; + ACI1_mA= parseFloat(((bytes[4]<<24>>16 | bytes[5])/1000).toFixed(3)); + ACI2_mA= parseFloat(((bytes[6]<<24>>16 | bytes[7])/1000).toFixed(3)); + } + result = { + "Work_mode": Work_mode, + "ACI1_mA": ACI1_mA, + "ACI2_mA": ACI2_mA, + } + + return result + + elif(mode=='4'): + { + Work_mode= "Count mode 2"; + Acount_times= (bytes[4]<<24 | bytes[5]<<16 | bytes[6]<<8 | bytes[7]); + } + result = { + "Work_mode": Work_mode, + "Acount_times": Acount_times, + } + + return result + + elif(mode=='5'): + { + Work_mode= " 1ACI+2AVI+1Count"; + AVI1_V= parseFloat(((bytes[0]<<24>>16 | bytes[1])/1000).toFixed(3)); + AVI2_V= parseFloat(((bytes[2]<<24>>16 | bytes[3])/1000).toFixed(3)); + ACI1_mA= parseFloat(((bytes[4]<<24>>16 | bytes[5])/1000).toFixed(3)); + Count1_times= bytes[6]<<8 | bytes[7]; + } + result = { + "Work_mode": Work_mode, + "AVI1_V": AVI1_V, + "AVI2_V": AVI2_V, + "ACI1_mA": ACI1_mA, + "Count1_times": Count1_times, + } + + return result + + elif(mode=='6'): + { + Work_mode= "Exit mode"; + Mode_status=(bytes[9]==0) and "False" or "True" + AV1L_flag=((bytes[0] &0x80)==128) and "True" or "False" + AV1H_flag=((bytes[0] &0x40)==64) and "True" or "False" + AV2L_flag=((bytes[0] &0x20)==32) and "True" or "False" + AV2H_flag=((bytes[0] &0x10)==16) and "True" or "False" + AC1L_flag=((bytes[0] &0x08)==8) and "True" or "False" + AC1H_flag=((bytes[0] &0x04)==4) and "True" or "False" + AC2L_flag=((bytes[0] &0x02)==2) and "True" or "False" + AC2H_flag=((bytes[0] &0x01)==1) and "True" or "False" + AV1L_status=((bytes[1] &0x80)==128) and "True" or "False" + AV1H_status=((bytes[1] &0x40)==64) and "True" or "False" + AV2L_status=((bytes[1] &0x20)==32) and "True" or "False" + AV2H_status=((bytes[1] &0x10)==16) and "True" or "False" + AC1L_status=((bytes[1] &0x08)==8) and "True" or "False" + AC1H_status=((bytes[1] &0x04)==4) and "True" or "False" + AC2L_status=((bytes[1] &0x02)==2) and "True" or "False" + AC2H_status=((bytes[1] &0x01)==1) and "True" or "False" + DI2_status=((bytes[2] &0x08)==8) and "True" or "False" + DI2_flag=((bytes[2] &0x04)==4) and "True" or "False" + DI1_status=((bytes[2] &0x02)==2) and "True" or "False" + DI1_flag=((bytes[2] &0x01)==1) and "True" or "False" + } + result = { + "Work_mode": Work_mode, + "Mode_status": Mode_status, + "AV1L_flag": AV1L_flag, + "AV1H_flag": AV1H_flag, + "AV2L_flag": AV2L_flag, + "AV2H_flag": AV2H_flag, + "AC1L_flag": AC1L_flag, + "AC1H_flag": AC1H_flag, + "AC2L_flag": AC2L_flag, + "AC2H_flag": AC2H_flag, + "AV1L_status": AV1L_status, + "AV1H_status": AV1H_status, + "AV2L_status": AV2L_status, + "AV2H_status": AV2H_status, + "AC1L_status": AC1L_status, + "AC1H_status": AC1H_status, + "AC2L_status": AC2L_status, + "AC2H_status": AC2H_status, + "DI2_status": DI2_status, + "DI2_flag": DI2_flag, + "DI1_status": DI1_status, + "DI1_flag": DI1_flag, + } + + return result + + diff --git a/transform_binary_payload/src-payload-decoders/python/dragino_lwl01.py b/transform_binary_payload/src-payload-decoders/python/dragino_lwl01.py new file mode 100644 index 0000000..67e61d3 --- /dev/null +++ b/transform_binary_payload/src-payload-decoders/python/dragino_lwl01.py @@ -0,0 +1,61 @@ +import base64 + + +def dict_from_payload(base64_input: str, fport: int = None): + """ Decodes a base64-encoded binary payload into JSON. + Parameters + ---------- + base64_input : str + Base64-encoded binary payload + fport: int + FPort as provided in the metadata. Please note the fport is optional and can have value "None", if not provided by the LNS or invoking function. + If fport is None and binary decoder can not proceed because of that, it should should raise an exception. + Returns + ------- + JSON object with key/value pairs of decoded attributes + """ + + bytes = base64.b64decode(base64_input) + value= (bytes[0] << 8 | bytes[1]) & 0x3FFF + battery = value/1000 + door_open_status = 0 + + if bytes[0] & 0x40: + water_leak_status = 1 + + water_leak_status = 0 + if bytes[0] & 0x80: + door_open_status = 1 + + mod = bytes[2] + + if mod == 1: + open_times = bytes[3] << 16 | bytes[4] << 8 | bytes[5] + open_duration = bytes[6] << 16 | bytes[7] << 8 | bytes[8] + result = { + "mod": mod, + "battery": battery, + "door_open_status": door_open_status, + "open_times": open_times, + "open_duration": open_duration + } + + return result + + if mod == 2: + leak_times = bytes[3] << 16 | bytes[4] << 8 | bytes[5] + leak_duration = bytes[6] << 16 | bytes[7] << 8 | bytes[8] + + result = { + "mod": mod, + "battery": battery, + "leak_times": leak_times, + "leak_duration": leak_duration + } + + return result + + result = { + "battery": battery, + "mod": mod + } \ No newline at end of file