Hello Every one,
I don’t know why I want to decode “bytes”, but the function Decode(fPort,bytes) decode “data”.
Hi
The Bytes is in an array, bytes[0] etc…
with a temp sensor for dragino
the decoding looks like this
function Decoder(fPort, bytest) {
// Decode an uplink message from a buffer
// (array) of bytes to an object of fields.
var value=(bytes[0]<<8 | bytes[1]) & 0x3FFF;
var batV=value/1000;//Battery,units:V
value=bytes[2]<<8 | bytes[3];
if(bytes[2] & 0x80)
{value |= 0xFFFF0000;}
var temp_SHT=(value/100).toFixed(2); //SHT20,temperature,units:℃
value=bytes[4]<<8 | bytes[5];
var hum_SHT=(value/10).toFixed(1); //SHT20,Humidity,units:%
value=bytes[7]<<8 | bytes[8];
if(bytes[7] & 0x80)
{value |= 0xFFFF0000;}
var temp_ds=(value/100).toFixed(2); //DS18B20,temperature,units:℃
return {
BatV:batV,
TempC_DS:temp_ds,
TempC_SHT:temp_SHT,
Hum_SHT:hum_SHT
};
}
That changes the “Data” key in the mqtt to more readable.
example.
data:"zDAM7gE2AX//f/8="
to
data:"zDAM7gE2AX//f/8=",object:{ BatV:3.12, Hum_SHT:"31.0", TempC_DS:"327.67", TempC_SHT:"33.10"}
1 Like