Uplink

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.

function consume(event) {
    emit('sample', { data: {}, topic: 'default' });
}

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.

Decoding the Payload

Here you can see a example to decode the payload from hex to a unsigned integer in this case a counter variable. This variable is added to the data payload and emitted to the default topic.

function consume(event) {
    let payload = event.data.payloadHex;
    let bits = Bits.hexToBits(payload);
    data.counter = Bits.bitsToUnsigned(bits.substr(6, 10)) / 4;
    // emit
    emit('sample', { data: {}, topic: 'default' });
}

The uplink event object differs slightly based on connectivity but share the same base structure. Every event contains the following structure:

Example HTTP or MQTT event

The data object contains everything which was sent in the request body of the uplink request.

Example LoRaWAN event

The contents of the uplinkMetrics object differs depending on the network provider.

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.

Event examples

A raw LoRaWAN uplink that invokes an uplink decoder script (Custom Device Type), looks as follows:

A raw MQTT uplink that invokes an uplink decoder script (Custom Device Type), looks as follows:

Last updated

Was this helpful?