Examples of decoding and downloads to be used with our smoke and heat detectors with LoRa.
To be able to decode payload in a Linux console from the detectors, the definition file below is needed.
Example from Linux environment:
Install protobuf-compiler:
apt install protobuf-compiler
To manually decode a payload, run this in the folder where you have the proto file:
echo -n “payload hex string” | xxd -r -p | protoc –decode Uplink uplink.proto
To be able to use python to decoded the payload from the detectors, a compiled version of the definition file below is needed.
Example from Linux environment:
Install protobuf-compiler:
apt install protobuf-compiler
Compile definition file:
protoc -I=$src_dir –python_out=$dst_dir $src_dir/uplink.proto
(Example: protoc -I=. –python_out=. uplink.proto )
A file named uplink_pb2.py will be created.
Python code example:
from uplink_pb2 import Uplink
#Example of payload to decode
payload = “0a0b08f91c1010187120e1a201120b086110a0dba80418012015220808a0dba80410944e2a1a0a18d001d001d101d001ce01ce01d101d001cf01cf01cf01d001”
#print(“payload: “, payload)
#Decode the payload with protobuf
data = bytes.fromhex(payload)
uplink_data = Uplink()
uplink_data.ParseFromString(data)
print(“data: “, uplink_data)
# Split decoded payload into segments
if uplink_data.HasField(“heartbeat”):
print (“batt: “, uplink_data.heartbeat.battery_voltage)
print (“tx: “, uplink_data.heartbeat.tx_power)
print (“rssi: “, uplink_data.heartbeat.downlink_rssi)
print (“temp: “, uplink_data.heartbeat.temperature)
if uplink_data.HasField(“end_of_alarm”):
print (“eof_alarm_count: “, uplink_data.end_of_alarm.counter)
print (“eof_timestamp: “, uplink_data.end_of_alarm.timestamp)
if uplink_data.HasField(“announcement”):
print (“hw: “, uplink_data.announcement.hardware_version)
print (“sw: “, uplink_data.announcement.software_version)
if uplink_data.HasField(“software_assertion”):
print (“assertion_file: “, uplink_data.software_assertion.file)
print (“assertion_line: “, uplink_data.software_assertion.line)
if uplink_data.HasField(“metadata”):
print (“meta_uptime: “, uplink_data.metadata.uptime)
print (“meta_no: “, uplink_data.metadata.magic_no)
if uplink_data.HasField(“temperature_history”):
print(uplink_data.temperature_history)
#print(“Smoke sensor events:”, len(uplink_data.smoke_sensor_event))
for event in uplink_data.smoke_sensor_event:
print(“frame_id”, event.frame_id)
print(“timestamp”, event.timestamp)
print(“counter”, event.counter)
To be able to decode payload in a Linux console from the detectors, the definition file below is needed.
Example from Linux environment:
First install Node, nodejs and npm.
To decode protobuf:
npm install protobufjs
npm install protobufjs-cli
Create a js-file of below definition file (uplink.proto)
“./node-modules/.bin/pbjs -t static-module -w commonjs -o uplink.js uplink.proto”
To run a testfile:
node parser.js
Definition file for Google Protocol Buffers
Test file for Javascript
Node-RED flow