Key concepts

Introduction to binary decoding and binary encoding
To optimize energy consumption, LoRaWAN devices perform binary encoding of the data before sending. Many cloud-hosted applications are designed to process structured data (e.g. in JSON). If we want to process telemetry from the LoRaWAN devices in the cloud-hosted applications, a transformation from binary to e.g. JSON is necessary. This transformation process is called “binary decoding”.

Similarly, if the cloud-hosted application needs to send command to the LoRaWAN device, a transformation from a structured format (e.g. JSON) into binary format is necessary. This process is called “binary encoding”.

Example for binary decoding
For example, consider this sample payload as sent by a LoRaWAN device with a temperature sensor:

Bytes     : 1  2  3  4  5  6  
Hex value : cb c0 09 c3 10 71  

By analying individual bytes according to the device manual we are able to decode the above binary message into it’s individual valuees:

Bytes Description Hex value Decoding instructions from device’s user manual Decoded decimal value
1-2 Battery level CB C0 treat as unsigned integer 3088
2-3 Temperature 09 C3 treat as unsigned integer and divide by 1000 24.99
3-4 Humidity 10 71 treat as unsigned integer and divide by 1000 42.09

In the next step, we can use the decoded decimal values to create a JSON document:

  "battery_value": 3008, 
  "temperature": 24.99,
  "humidity": 42.09 

As we can see, with 81 bytes the JSON document is more then 1300% bigger then the binary message. However, it can be easier processed by cloud-hosted applications.