- Overall Message Format
- Bitmap fields and associated fields
- Data Formats
- Test Vectors
- Node-RED Decoding Script
- The Things Network Console decoding script
Port 2 uplink messages are used by Catena4612_simple
and related sketches. They're designed to minimize power use and maximize battery life; so instead of using a port code plus a message discriminator, these simply use port 2.
Each message has the following layout.
byte | description |
---|---|
0 | bitmap encoding the fields that follow |
1..n | data bytes; use bitmap to decode. |
Each bit in byte 0 represents whether a corresponding field in bytes 1..n is present. If all bits are clear, then no data bytes are present. If bit 0 is set, then field 0 is present; if bit 1 is set, then field 1 is present, and so forth. If a field is omitted, all bytes for that field are omitted.
The bitmap byte has the following interpretation. int16
, uint16
, etc. are defined after the table.
Bitmap bit | Length of corresponding field (bytes) | Data format | Description |
---|---|---|---|
0 | 2 | int16 | Battery voltage |
1 | 2 | int16 | System voltage |
2 | 1 | uint8 | Boot counter |
3 | 5 | int16, uint16, uint8 | Temperature, pressure, humidity |
4 | 2 | uint16, uint16, uint16 | Ambient Light |
5 | 2 | int16 | Bus voltage |
6 | n/a | reserved | Reserved for future use. |
7 | n/a | reserved | Reserved for future use. |
Field 0, if present, carries the current battery voltage. To get the voltage, extract the int16 value, and divide by 4096.0. (Thus, this field can represent values from -8.0 volts to 7.998 volts.)
Field 1, if present, carries the current System voltage. Divide by 4096.0 to convert from counts to volts. (Thus, this field can represent values from -8.0 volts to 7.998 volts.)
Note: this field is not transmitted by V0.1.0 of the Catena4612_simple sketch.
Field 2, if present, is a counter of number of recorded system reboots, modulo 256.
Field 3, if present, has three environmental readings.
-
The first two bytes are a
int16
representing the temperature (divide by 256 to get degrees C). -
The next two bytes are a
uint16
representing the barometric pressure (divide by 25 to get millibars). This is the station pressure, not the sea-level pressure. -
The last byte is a
uint8
representing the relative humidity (divide by 2.56 to get percent). (This field can represent humidity from 0% to 99.6%.)
Field 4, if present, has three light readings as six bytes of data.
- The first two bytes are a
uint16
representing the IR measurement. - Bytes two and three are a
uint16
representing the white light measurement. - Bytes four and five are a
uint16
representing the UV light measurement.
The measurements range from 0 to 65536, but must be calibrated to obtain engineering units.
Field 5, if present, carries the current voltage from USB VBus. Divide by 4096.0 to convert from counts to volts. (Thus, this field can represent values from -8.0 volts to 7.998 volts.)
All multi-byte data is transmitted with the most significant byte first (big-endian format). Comments on the individual formats follow.
an integer from 0 to 65536.
a signed integer from -32,768 to 32,767, in two's complement form. (Thus 0..0x7FFF represent 0 to 32,767; 0x8000 to 0xFFFF represent -32,768 to -1).
an integer from 0 to 255.
The following input data can be used to test decoders.
01 18 00
{
"vBat": 1.5
}
01 F8 00
{
"vBat": -0.5
}
3D 43 A7 2B 19 8D 5F 88 8E 00 2E 00 49 00 03 21 23
{
"boot": 43,
"irradiance": {
"IR": 46,
"UV": 3,
"White": 73
},
"p": 978.24,
"rh": 55.46875,
"tDewC": 15.979071186474535,
"tHeatIndexC": 25.609765625000005,
"tempC": 25.55078125,
"vBat": 4.228271484375,
"vBus": 2.071044921875
}
A Node-RED script to decode this data is part of this repository. You can download the latest version from GitHub:
The repository contains a generic script that decodes all formats, including port 2, for The Things Network console.
You can get the latest version on GitHub: