Decent Lab Flood Sensor Payload Decoder

There is no good information about how to decode the payload of this sensor.

I found this in a forgotten folder hide in the hell at the office.

Decoding payload of Maxbotix LoRaWAN devices v2
———————————————–

Date: 2017-01-18

Frame format version 2
———————-

frame header:
uint8_t frame_format_id; // == 2 for version 2
uint16_t node_id;
uint16_t valid_data_flags;

sensor 0 data:
uint16_t distance; // [mm]
uint16_t trials; // # measurement trials

sensor 1 data:
uint16_t battery_voltage; // VBAT = battery_voltage / 1000 [V]

Notes
—–

– 16 bit unsigned integers (uint16_t) are big endian: MSB first, LSB
second byte.
– valid_data_flags: 16 flags; bit 0 (LSB): sensor 0 data flag; bit 1:
sensor 1 data flag, etc.
– flag x == 1: sensor x data included
– flag x == 0: sensor x data not included

Example 1
———
02 012f 0003 04d2 0001 0bb1

frame_format_id: 2
node_id: 303
valid_data_flags: 0000 0000 0000 0011

distance: 1234 mm
trials: 1
battery_voltage: 2.993 V

Example 2
———
02 012f 0002 0bb1

frame_format_id: 2
node_id: 303
valid_data_flags: 0000 0000 0000 0010

distance: (no data)
trials: (no data)
battery_voltage: 2.993 V

Base on that I was able to understand the payload sections getting this:

​02
012f
0003
04d2
0001
0bb1
format version node ID flag distance trials voltage
2 303 3 1234 1 2993

And now it is possible to create a decoder payload for TTN:

function Decoder(bytes) {
var data = {};
var flag = (bytes[3] << 8) + bytes[4];
data.version = bytes[0];
data.nodeid = (bytes[1] << 8) + bytes[2];

if (flag == 3){
data.distance = ((bytes[5] << 8) + bytes[6]); //milimeters
data.trials = (bytes[7] << 8) + bytes[8];
data.voltage = ((bytes[9] << 8) + bytes[10]); // V / 1000
return data;
}else{
data.voltage = ((bytes[5] << 8) + bytes[6]); // V / 1000
return data;
}
}

This is the data decoded based on the same payload example:

02 01 2F 00 03 04 D2 00 01 0B B1

{
“distance”: 1234,
“nodeid”: 303,
“trials”: 1,
“version”: 2,
“voltage”: 2993
}

or 02 01 2F 00 02 0B B1

{
“nodeid”: 303,
“version”: 2,
“voltage”: 2993
}

Leave a Reply

Your email address will not be published. Required fields are marked *

*