Payload Format
Codec
A complete LoRaWAN payload codec with examples can be found in the downloads section. See also Decoder example for reference.
Overview
The payload of up and downlink messages consists of an arbitrary number of data structs (DS) of different types and lengths.
DS 1 | DS 2 | ... | DS n |
---|---|---|---|
Each data struct is a combination of a header and the actual data payload:
L | T | payload |
---|---|---|
The header consists of two fields:
Field | Description |
---|---|
L | Length of data struct, 1 byte, not including the length byte itself |
T | Data struct type, 1 byte |
Data Encoding
Signed integers use two’s complement for encoding.
Important
Unless otherwise noted, payloads will use little endian data encoding.
Uplinks
The following uplink payload types are defined:
- Battery (*)
- Current scene
- Battery voltage (*)
(*) This devices doesn't have batteries. The battery message returns the estimated used uWh. The battery voltage message returns the measured voltage from the microcontroller.
Important
All uplinks are sent on LoRaWAN port 15.
Regular Status Message
The device sends a regular status messages at a configurable interval. The content of the status message consists of three messages:
- Battery Message
- Current scene Message
- Battery voltage Message
An additional purpose of the status message is to allow reception of downlink messages if the network server does not support class C.
Battery
This devices doesn't have batteries. The battery message returns the estimated used uWh.
Message type T = 0x02 and length L = 0x04.
Byte | Size | Description | Format |
---|---|---|---|
0 | 1 | Message length (0x04) | Byte |
1 | 1 | Message type (0x02) | Byte |
2 | 4 | Accu uAh | Word 32 bit |
Example
Payload 05:02:00:00:00:55 is reporing accumulated energy consumption to be 85 uAh
CurrentScene
The CurrentScene message type is used to get information about the current scene.
Message type T = 0x04 and length L = 0x02.
Byte | Size | Description | Format |
---|---|---|---|
0 | 1 | Message length (0x02) | Byte |
1 | 1 | Message type (0x04) | Byte |
2 | 1 | Current Scene | Byte |
Example
Payload 02:04:07 is reporting current scene to be set to 7
BatteryVoltage
This devices doesn't have batteries. The battery voltage message returns the measured voltage from the microcontroller.
Message type T = 0x03 and length L = 0x03.
Byte | Size | Description | Format |
---|---|---|---|
0 | 1 | Message length (0x03) | Byte |
1 | 1 | Message type (0x03) | Byte |
2 | 2 | Battery Voltage in mV | Word 16bit |
Example
Payload 03:03:0C:E4 reports battery voltage to be 3300 mV
Downlinks
Downlink messages are used to change the configuration of the device. They use the same general payload format as uplinks.
Important
All down-links must be sent on the LoRaWAN port 3
Device Configuration
The device configuration message type is used to set general device configuration.
Message type T = 0x80 and length L = 0x06.
Byte | Size | Description | Format | Value Range |
---|---|---|---|---|
0 | 1 | Message length (0x06) | 0x06 | |
1 | 1 | Message type (0x80) | 0x80 | |
2 | 1 | Flags, bitwise or combination: Bit 7 = Confirmed uplinks (0 = off, 1 = on) Bit 6 = Duty Cycle (0 = off, 1 = on) Bit 5 = LoRaWAN Class (0 = A, 1 = C) Bit 4 = Buzzer (0 = off, 1 = on) Bits 0-3: RFU |
Bitfield |
3-4 |
3 | 2 | Keep Alive interval in minutes | uint16 | |
5 | 1 | Number of LEDs in ring (max 48) | uint8 | 0..48 |
6 | 1 | Automatic reset time (0 = disabled) | uint8, hours | 0..0xFF |
Example
payload 06:80:60:00:0A:10:0A will result in following configuration options
Config option | Value |
---|---|
Flags | Class C |
Status interval | 10 minutes |
Number of LEDs | 16 |
Reset time | 10 |
Set Scene
This downlink command is used to set the scene. A scene is a preprogrammed LED color. The same color is set on all LEDs. Optionally, a scene also includes a buzzer melody to be played, either once or on repeat until the scene ends. Only a select few melodies are available. A scene is valid until the next scene will be set with another downlink command or until its preconfigured timeout is reached.
Message type T = 0x81 and length L = 0x02:
Byte | Size | Description | Format | Value Range |
---|---|---|---|---|
0 | 1 | Message length (0x02) | uint8 | 0x02 |
1 | 1 | Message type (0x81) | uint8 | 0x81 |
2 | 1 | Scene (0=Oxff) | uint8 | 0..21, 0xFF |
Example
payload 02:81:01 will set scene 1 on the device
Set Brightness
Set LED brightness.
Message type T = 0x82 and length L = 0x02.
Byte | Size | Description | Format | Value Range |
---|---|---|---|---|
0 | 1 | Message length (0x02) | uint8 | 0x02 |
1 | 1 | Message type (0x82) | uint8 | 0x82 |
2 | 1 | Brightness [0=darkest,255=brightest | uint8 | 0..21, 0xFF |
Example
payload 02:82:80 will set brightness to 128 which is equalt to 50% of maximum brightness
Set Volume
Set buzzer volume.
Message type T = 0x85 and length L = 0x02.
Byte | Size | Description | Format | Value Range |
---|---|---|---|---|
0 | 1 | Message length (0x02) | uint8 | 0x02 |
1 | 1 | Message type (0x85) | uint8 | 0x82 |
2 | 1 | Volume [0=off,1=low,2=medium,3=high] | enum | 0..21, 0xFF |
Note
It is recommended to use the buzzer flag instead of setting the volume to 0.
Example
payload 02:85:03 will set buzzer volume to high (maximum)
Configure Scene (only LED)
Configure an LED scene by changing its color and timeout time.
Message type T = 0x83 and length L = 0x07.
Byte | Size | Description | Format | Value Range |
---|---|---|---|---|
0 | 1 | Message length (0x07) | 0x07 | |
1 | 1 | Message type (0x83) | 0x83 | |
2 | 1 | Scene to configure | 1-4 | 0..21, 0xFF |
3 | 1 | Red value | uint8 | 0..0xFF |
4 | 1 | Green value | uint8 | 0..0xFF |
5 | 1 | Blue value | uint8 | 0..0xFF |
6-7 | 2 | Timeout time of scene (0=no timeout) | uint16, minutes | 0..0xFFFF |
Example
payload 07:83:02:FF:9A:00:00:0A will configure scene 2 with following values
Parameter | Value |
---|---|
Red value | 0xFF = 255 |
Green value | 0x9A = 154 |
Blue value | 0x00 = 0 |
Timeout time | 10 minutes |
The hex color 0xff9a00 is a yellow.
Configure Scene (LED and Buzzer)
Configure an LED scene by changing its color and timeout time. Additionally, configure the buzzer melody for this specific scene.
Message type T = 0x84 and length L = 0x09.
Byte | Size | Description | Format | Value Range |
---|---|---|---|---|
0 | 1 | Message length (0x09) | 0x09 | |
1 | 1 | Message type (0x84) | 0x84 | |
2 | 1 | Scene to configure | 1-4 | 0..21 |
3 | 1 | Red value | uint8 | 0..0xFF |
4 | 1 | Green value | uint8 | 0..0xFF |
5 | 1 | Blue value | uint8 | 0..0xFF |
6-7 | 2 | Timeout time of scene (0=no timeout) | uint8, minutes | 0..0xFFFF |
8 | 1 | Melody: 0 = None 1 = Fast 2 = Medium 3 = Slow 4 = Ascending 5 = DoubleUp 6 = Double 7 = Triple |
enum | 0..7 |
9 | 1 | Repeat [0=disabled, 1=enabled] | bool | 0,1 |
Example
payload 09:84:02:FF:9A:00:00:0A:03:01 will configure scene 2 with following values
Parameter | Value |
---|---|
Red value | 0xFF = 255 |
Green value | 0x9A = 154 |
Blue value | 0x00 = 0 |
Timeout time | 10 minutes |
Melody | slow |
Repeat | enabled |
The hex color 0xff9a00 is a yellow.
Decoder example
function decodeMiroAlarm(fPort, bytes) {
// Decode an uplink message from a buffer
// (array) of bytes to an object of fields.
var decoded = {};
if (fPort == 15) {
n = bytes.length;
idx = 0;
while (n > idx) {
s = bytes[idx++];
decoded.type = bytes[idx];
if (bytes[idx] == 4) {
decoded.current_scene = bytes[idx + 1];
}
if (bytes[idx] == 2) {
decoded.uah = bytes[idx + 1] + (bytes[idx + 2] << 8) + (bytes[idx + 3] << 16) + (bytes[idx + 4] << 24);
}
if (bytes[idx] == 3) {
decoded.battery_v = (bytes[idx + 1] + (bytes[idx + 2] << 8))/1000;
}
idx += s;
}
}
return decoded;
}