|
| 1 | + |
| 2 | +# LoRaWAN Data Encoding |
| 3 | + |
| 4 | +To achieve incredible low-power and long-range performance, a LoRaWAN end node minimizes the size of data packets sent across the LoRa network. While the size of a data packet is adjustable based on specific performance needs and network deployment topology, for maximum flexibility, the SparkFun IoT Node - LoRaWAN firmware uses a packet payload size of 11 bytes. This relativity small payload length is a challenge for a general data-logging application and requires that the firmware develop a unique data packing methodology to meet the general data logging goals of the implementation. |
| 5 | + |
| 6 | +## Value Packing Structure |
| 7 | + |
| 8 | +The IoT Node - LoRaWAN firmware employs a simple tagged format to pack and send sensor data across the LoRaWAN network. The key element to this methodology is the ***tag***, which is defined a "Value Type" for the implementation used for sending data. The Value Type tag is followed by the data value, which is formatted for network transport. |
| 9 | + |
| 10 | +The general structure of a packed value is: |
| 11 | + |
| 12 | + \[ **Value Type** *{1 byte}* ][**Data Value** *{n bytes - network byte order }*] |
| 13 | + |
| 14 | + |
| 15 | +### Value Type |
| 16 | + |
| 17 | +Key attributes of a "Value Type" tag/code: |
| 18 | + |
| 19 | +* There is a common set of "Value Type" code IDs - each code identifies a value, which is defined as a specific measured value/phenomenology and its associated units. |
| 20 | +* The "Value Type" codes are known by both sender and receiver of a data value |
| 21 | +* The length of a data value is defined by it's Value Type. |
| 22 | + * Data types supported: *unit8, uint16, unit32, int8, int16, int32, float and double* |
| 23 | + |
| 24 | +### Data Formatting |
| 25 | + |
| 26 | +When a data value is "packed", for multi-byte values, the data is encoded for network endianness (big-endian format). |
| 27 | + |
| 28 | +The following table outlines how a data value is packed, based on it's data type size: |
| 29 | + |
| 30 | +| Data Type | Length (bytes) | Format Used | |
| 31 | +|--|--|--| |
| 32 | +| int8 | 1 | No format applied | |
| 33 | +| int16 | 2 | Network Byte Order (2 bytes) | |
| 34 | +| int32 | 4 | Network Byte Order (4 bytes) | |
| 35 | +| uint8 | 1 | No format applied | |
| 36 | +| uint16 | 2 | Network Byte Order (2 bytes) | |
| 37 | +| uint32 | 4 | Network Byte Order (4 bytes) | |
| 38 | +| float | 4 | Network Byte Order (4 bytes) | |
| 39 | +| double | 8 | \[ Network Byte Order (4 bytes) ][ Network Byte Order (4 bytes) ] | |
| 40 | + |
0 commit comments