> Français
> English
> Deutsch

LoRaWAN payload encoding

Proposal of April 30th, 2016. Thierry Schneider, Tetraedre Sarl

 

The maximum size of the LoRaWAN payload is 64 bytes. This limited size is the main reason to develop a flexible and compact data encoding. 

Tetraedre is active in the Internet Of Things technology since many years and has developped efficient and versatile data encoding.

The goal is not to be the most size efficient but to find a good trade-off between size, versatility and portability.

 

Header_main

The first byte of the payload is named header_main. This is the only fixed part of the payload. The description of this parameter is given below. The rest of the payload is a concatenation of data chunks. Chunks are either of type A, type B or type C. There might be any mix of chunks, in any order.

LoRaWAN Payload
First byte rest of payload
header_main serie of chunks

The two must significant bits of header_main are reserved and must be set to 0. Allowed values for header_main are thus 0 to 63. 

 

 

Chunk type distinction

Each chunk start with a header byte. This byte is used for data identification but also to know the size of the chunk.

Header value Type / Description
0x00 Reserved value. Means end of stream
0x01 - 0x5F Type A Chunk. Fixed size. 3 bytes
0x60 - 0x7F Type D Chunk. Fixed size. 2 bytes
0x80 - 0xBF Type B Chunk. Fixed size. 5 bytes
0xC0 - 0xFE Type C Chunk. Variable size
0xFF reserved value. Means end of stream

 

Type A Chunk

The type A chunk is 3 bytes long. The first byte is the chunk header. The header is followed by 2 bytes

header data
byte8
data
byte0

 byte8 is MSB

Type B Chunk

The type B chunk is 5 bytes long. The first byte is the chunk header. The header is followed by 4 bytes

header data
byte24
data
byte16
data
byte8
data
byte0

byte24 is MSB

When data are transmitted in floating point the IEEE754 format must be used

 

Type C Chunk

The type C chunk is a variable size block. The first byte is the chunk header. The header is followed the size parameter which indicates the size of the data field

header size data field
length is "size" bytes

 

Type D Chunk

The type D chunk is 2 bytes long. The first byte is the chunk header. The header is followed by 1 byte

header data

 

 

Content definition

 The content is defined with a combination of header_main and of header. The following table is a proposal of standard values.

header_main header Chunk description
0 1 0x01 A Temperature. signed integer 16bits. 1 LSB = 0.01°C.   0: 0°C; 1: +0.01°C; 0xFFFF : -0.01°C
0 2 0x02 A Relative Humidity. unsigned integer 16bits. 1 LSB = 0.01°RH
0 3 0x03 A Oxygen concentration. 1 LSB = 0.001%
0 4 0x04 A CO2 concentration. 1 LSB = 0.001%
0 5 0x05 A Second temperature. signed integer 16bits. 1 LSB = 0.01°C.   0: 0°C; 1: +0.01°C; 0xFFFF : -0.01°C
0 6 0x06 A Pressure. unsigned integer 16bits. 1 LSB = 0.5mbar
0 7 0x07 A analog channel #0. 1 LSB = 1 uA
0 8 0x08 A analog channel #1. 1 LSB = 1 uA
0 9 0x09 A analog channel #2. 1 LSB = 1 uA
0 10 0x0A A analog channel #3. 1 LSB = 1 uA
0 11 0x0B A digital inputs state
0 12 0x0C A relative pulse counter 0
0 13 0x0D A relative pulse counter 1
0 14 0x0E A relative pulse counter 2
       
0 or 1 96
0x60
D Battery voltage
if (value>=81)
    Volt = 4.2 + (value-80) * 0.1
else
    Volt = 1.8 + value * 0.03
       
0 or 1 128  0x80 B timestamp of the measurement. unsigned integer 32 bits. UNIX timestamp 
1 129 0x81 B Main energy index. IEEE754 floating point. Unit : kWh for electricty meters (register 1.8.0), m3 for water meter, m3 for uncorrected gaz meters
1 130 0x82 B Serial number. unsigned integer 32bits. Serial number of the meter 
1 131 0x83 B First tariff energy index. IEEE754 floating point. Unit : kWh for electricty meters (register 1.8.1)
1 132 0x84 B Second tariff energy index. IEEE754 floating point. Unit : kWh for electricty meters (register 1.8.2)
1 133 0x85 B Main energy index. IEEE754 floating point. Unit : m3 for water meter
1 134 0x86 B Main energy index. IEEE754 floating point. Unit : m3 for uncorrected gaz meters
1 135 0x87 B Flow temperature. IEEE754 floating point. Unit : °C
1 136
0x88
B absolute pulse counter 0. unsigned integer 32bits
1 137
0x89
B absolute pulse counter 1. unsigned integer 32bits
       
1 192 0xC0 C ZMD410 profil. First is timestamp (32bits unix) followed by either 1, 2 or 3 float16 values. The values definition and number are dependant of the ZMD410 configuration. Their encoding is float16 (see below). The first value represents to the first field of the profil, the second value (if any) represents the second field,...
1 200 0xC8 C M-BUS data chunk.
1 224 0xE0 C Index of the FastForward EnergyCam module.
1 229 0xE5 C  SNR of the FastForward EnergyCam module.

 

 

 

 

If you intend to use this specification or if you have comments, please inform me.

 

 

 

 

Type definition

float16 type

The goal of the float16 type is to encode small and large values using only 16-bit. Of course this is not as efficient as IEEE754 but it already gives interesting possibilites. Only positive values are accepted. Values in range 0 to 181930 are converted

The two most significant bits define a decimal range (0.01, 0.1, 1, 10) (exponent), while the 14 lest significant bits defines the value (mantisse). Use the following code to decode the values

    left = (value >> 14) & 0x03;

    value0 = value & 0x3FFF;
    result = (float32) value0;
    switch(left)
    {
        case 0:
           result = result / 100.0;
        break;
        case 1:
            result = result / 10.0;
            result = result + 163.0;
            break;
        case 3:
            result = result * 10.0;
            result = result + 18100;
            break;
        case 2:
        default:
            result = result + 1793;
            break;
    }

 

VBAT type

The goal of the VBAT type is to encode the battery voltage with a single byte and sufficient accuracy.

The decoding is very simple: V is the byte value.

if (v<128)
Voltage = 1 + ((v & 0x7F) * 0.025)
else
 Voltage = 4.175 + ((v & 0x7F) * 0.15)

if (v==0)
Voltage = 0; // undefined

 

 

 

 

 

 

 

 




Tetraedre Sarl Company, Copyright ©1999-2015