Payload Conversion

Device Profile Codec

Device profiles can use payload codecs.

This encoding/decoding is taken care of by the LoRa Server Stack and not by the device driver. This is off-the-shelf functionality. It needs to be configured as part of the device profiles; using the API.

Cayenne LPP

When selecting the Cayenne LPP codec, ChirpStack Application Server will decode and encode following the Cayenne Low Power Payload specification.

Custom JavaScript codec Functions

When selecting the Custom JavaScript codec Functions option, you can write your own (JavaScript) functions to decode an array of bytes to a JavaScript object and encode a JavaScript object to an array of bytes.

Conversion Templates

In addition to this, the ECP LoRaWAN device driver has "conversion templates" to be able to add extra conversion from the LoRa payload to Web-of-Things formatting, when required.

The API for it has the following endpoints:
POST /drivers/lorawan/conversion-templates
GET /drivers/lorawan/conversion-templates
GET /drivers/lorawan/conversion-templates/{conversion_template_id}
PUT /drivers/lorawan/conversion-templates/{conversion_template_id}
DELETE /drivers/lorawan/conversion-templates/{conversion_template_id}
The request body for creating one looks like:
{
    "id": "",
    "name": "MyConversionTemplate",
    "type": "OBJECT",
    "conversion": "{\"temp\":\"temperature\",\"humi\":\"humidity\"}"
}

The "type" can be one of two options: ARRAY / OBJECT.

For "type" ARRAY the "conversion" needs to be a JSON array where each indexed element has a string value of the WoT property key. For example, an array with two numeric elements in the LoRA payload, coming in as [22,88], denoting temperature and humidity can be converted with '["temperature","humidity"]' as the "conversion" template.

For "type" OBJECT the "conversion" needs to be a JSON object where each element key corresponds to the LoRA payload key and the element value corresponds to the WoT property key. For example, an object with two properties in the LoRA payload, coming in as {"temp":22,"humi":88}, denoting temperature and humidity can be converted with '{"temp":"temperature","humi":"humidity"}' as the "conversion" template.

There are two ways a conversion template can be specified for a Thing:
  1. Use conversionTemplateId={conversion_template_id} in the "@type" of the thing description
  2. Use a writable property called "conversionTemplateId" in the Thing description and set the property value to the desired template, when required.