Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Dragino devices decoder support, fix battery decode on LDS01 and LSE01 #11

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions transform_binary_payload/src-payload-decoders/node/dragino_laq4.js
Original file line number Diff line number Diff line change
@@ -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"]
}
}
}
Original file line number Diff line number Diff line change
@@ -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"]
}
}
}
Original file line number Diff line number Diff line change
@@ -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"]
}
}
}
Original file line number Diff line number Diff line change
@@ -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"]
}
}
}
Original file line number Diff line number Diff line change
@@ -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"]
}
}
}
100 changes: 100 additions & 0 deletions transform_binary_payload/src-payload-decoders/node/dragino_lsn50v2.js
Original file line number Diff line number Diff line change
@@ -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"]
}
}
}
Loading