Uplink decoders are used to decode or "translate" a device-specific payload into a human-readable JSON object (e.g. HEX -> JSON object).
Script Structure
An uplink decoder script has to implement the function consume(object) which takes an event object as argument. An error will be returned if the script doesn't implement a consume(event) function.
The consume(event) function is the entry point for the script and will be invoked upon execution. Each execution loads the script again, resetting any variable values which were set in previous runs.
Uplink Event Object
The uplink event object differs slightly based on connectivity but share the same base structure. Every event contains the following structure:
{"data": {// the data sent in the uplink request },"device": {// device properties },"uplinkMetrics": {// info about the uplink },"topic": "default"//topic sent along with the event or "default" if not specified}
Example HTTP or MQTT event
The data object contains everything which was sent in the request body of the uplink request.
{"data": {"temperature":12.4,"humidty":85,... },"device": {"id":"string",// the akenza id"deviceId":"string",// the device id"name":"string","description":"string" },"uplinkMetrics": { // meta information about the uplink forwarded by the carrier"deviceId":"string",// the device id"uplinkSize":223,// recieved uplink size in bytes"timestamp":"iso-8601-date-string"// time when the uplink was received at akenza },"topic": "events"}
Example LoRaWAN event
The contents of the uplinkMetrics object differs depending on the network provider.
{"data": {"port":2,// the port specified in the LoRaWAN uplink"payloadHex":"aabbcc112233"// the hex string sent by the device },"device": {"id":"string",// the akenza id"deviceId":"string",// the device id"name":"string","description":"string" },"uplinkMetrics": { // meta information about the uplink forwarded by the network provider"deviceId":"string",// the device id"uplinkSize":223,// recieved uplink size in bytes"timestamp":"iso-8601-date-string",// time when the uplink was sent by the device"latitude":46.928403,"longitude":7.628662,"port":2,"frameCountUp":14,"frameCountDown":1,"rssi":-88.0,"snr":7.75,"sf":7,"txPower":8.0,"numberOfGateways":2,"esp":-88.67,"sqi":3 }}
Example Array Uplink event
When processing an array uplink, the structure is slighly different to other events. The data object contains a single property values which contains the original array sent in the uplink.
{"data": {"values": [ {"temperature":12.4,"humidty":85,... },... ] },"device": {... },"uplinkMetrics": { // meta information about the uplink forwarded by the carrier... }}
Event examples
LoRaWAN Device uplink event
A raw LoRaWAN uplink that invokes an uplink decoder script (Custom Device Type), looks as follows: