Skip to content

Commit

Permalink
Added LoRaWAN device status message (CMD_GET_LW_STATUS) (#59)
Browse files Browse the repository at this point in the history
  • Loading branch information
matthias-bs committed Jun 8, 2024
1 parent d2fbf89 commit 443acb4
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 0 deletions.
14 changes: 14 additions & 0 deletions BresserWeatherSensorLW.ino
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
// 20240530 Updated to RadioLib v6.6.0
// 20240603 Added AppLayer status uplink
// 20240606 Changed appStatusUplinkInterval from const to variable
// 20240608 Added LoRaWAN device status uplink
//
// ToDo:
// -
Expand Down Expand Up @@ -609,6 +610,12 @@ uint8_t decodeDownlink(uint8_t port, uint8_t *payload, size_t size)
return CMD_GET_LW_CONFIG;
}

if ((port == CMD_GET_LW_STATUS) && (payload[0] == 0x00) && (size == 1))
{
log_d("Get device status");
return CMD_GET_LW_STATUS;
}

log_d("appLayer.decodeDownlink(port=%d, payload[0]=0x%02X, size=%d)", port, payload[0], size);
return appLayer.decodeDownlink(port, payload, size);
}
Expand Down Expand Up @@ -649,6 +656,13 @@ void sendCfgUplink(uint8_t uplinkReq)
encoder.writeUint8(prefs.sleep_interval_long >> 8);
encoder.writeUint8(prefs.sleep_interval_long & 0xFF);
}
else if (uplinkReq == CMD_GET_LW_STATUS)
{
uint8_t status = longSleep ? 1 : 0;
log_d("Device Status: U_batt=%u mV, longSleep=%u", getBatteryVoltage(), status);
encoder.writeUint16(getBatteryVoltage());
encoder.writeUint8(status);
}
else
{
appLayer.getConfigPayload(uplinkReq, port, encoder);
Expand Down
15 changes: 15 additions & 0 deletions BresserWeatherSensorLWCmd.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
// 20240508 Updated description of CMD_GET_SENSORS_CFG/CMD_SET_SENSORS_CFG
// 20240603 Added CMD_GET_SENSORS_STAT
// 20240606 Added CMD_GET_STATUS_INTERVAL/CMD_SET_STATUS_INTERVAL
// 20240608 Added CMD_GET_LW_STATUS
//
// ToDo:
// -
Expand Down Expand Up @@ -122,6 +123,20 @@
// byte2: sleep_interval_long[15:8]
// byte3: sleep_interval_long[ 7:0]

// CMD_GET_LW_STATUS
// ------------------
// Port: CMD_GET_LW_STATUS
// Note: Get LoRaWAN device status
#define CMD_GET_LW_STATUS 0xB2

// Downlink (command):
// byte0: 0x00

// Uplink (response):
// byte0: u_batt[15:8]
// byte1: u_batt[ 7:0]
// byte2: flags[ 7:0]

// -----------------------
// -- Application layer --
// -----------------------
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,8 @@ Many software parameters can be defined at compile time, i.e. in [BresserWeather
| <ws_timeout> | Weather sensor receive timeout in seconds; 0...255 |
| <sleep_interval> | Sleep interval (regular) in seconds; 0...65535 |
| <sleep_interval_long> | Sleep interval (energy saving mode) in seconds; 0...65535 |
| <ubatt_mv> | Battery voltage in mV |
| <long_sleep> | 0: regular sleep interval / 1: long sleep interval (depending on U_batt) |
| \<epoch\> | Unix epoch time, see https://www.epochconverter.com/ ( \<integer\> / "0x....") |
| <reset_flags> | Raingauge reset flags; 0...15 (1: hourly / 2: daily / 4: weekly / 8: monthly) / "0x0"..."0xF" |
| <rtc_source> | Real time clock source; 0x00: GPS / 0x01: RTC / 0x02: LORA / 0x03: unsynched / 0x04: set (source unknown) |
Expand Down Expand Up @@ -420,6 +422,7 @@ Many software parameters can be defined at compile time, i.e. in [BresserWeather
| CMD_SET_SLEEP_INTERVAL | 0xA8 (168) | sleep_interval[15:8]<br>sleep_interval[7:0] | n.a. |
| CMD_SET_SLEEP_INTERVAL_LONG | 0xA9 (169) | sleep_interval_long[15:8]<br>sleep_interval_long[7:0] | n.a. |
| CMD_GET_LW_CONFIG | 0xB1 (177) | 0x00 | sleep_interval[15:8]<br>sleep_interval[7:0]<br>sleep_interval_long[15:8]<br>sleep_interval_long[7:0] |
| CMD_GET_LW_STATUS | 0xB2 (178) | 0x00 | ubatt_mv[15:8]<br>ubatt_mv[7:0]<br>long_sleep[7:0] |
| CMD_GET_WS_TIMEOUT | 0xC0 (192) | 0x00 | ws_timeout[7:0] |
| CMD_SET_WS_TIMEOUT | 0xC1 (193) | ws_timeout[7:0] | n.a. |
| CMD_RESET_RAINGAUGE | 0xC3 (195) | flags[7:0] | n.a. |
Expand Down Expand Up @@ -466,6 +469,7 @@ Many software parameters can be defined at compile time, i.e. in [BresserWeather
| CMD_SET_SLEEP_INTERVAL | {"sleep_interval": <sleep_interval>} | n.a. |
| CMD_SET_SLEEP_INTERVAL_LONG | {"sleep_interval_long": <sleep_interval_long>} | n.a. |
| CMD_GET_LW_CONFIG | {"cmd": "CMD_GET_LW_CONFIG"} | {"sleep_interval": <sleep_interval>, "sleep_interval_long": <sleep_interval_longC>} |
| CMD_GET_LW_STATUS | {"cmd": "CMD_GET_LW_STATUS"} | {"ubatt_mv": <ubatt_mv>, "long_sleep": <long_sleep>} |
| CMD_GET_WS_TIMEOUT | {"cmd": "CMD_GET_WS_TIMEOUT"} | {"ws_timeout": <ws_timeout>} |
| CMD_SET_WS_TIMEOUT | {"ws_timeout": <ws_timeout>} | n.a. |
| CMD_RESET_RAINGAUGE | {"reset_flags": <reset_flags>} | n.a. |
Expand Down
11 changes: 11 additions & 0 deletions scripts/downlink_formatter.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@
// 20240530 Added decoding of CMD_GET_APP_PAYLOAD_CFG/CMD_SET_APP_PAYLOAD_CFG
// 20240603 Added CMD_GET_SENSORS_STAT
// 20240607 Added CMD_GET_STATUS_INTERVAL/CMD_SET_STATUS_INTERVAL
// 20240608 Added CMD_GET_LW_STATUS
//
// ToDo:
// -
Expand All @@ -137,6 +138,7 @@ const CMD_SET_SLEEP_INTERVAL_LONG = 0xA9;
const CMD_GET_DATETIME = 0x86;
const CMD_SET_DATETIME = 0x88;
const CMD_GET_LW_CONFIG = 0xB1;
const CMD_GET_LW_STATUS = 0xB2;
const CMD_GET_WS_TIMEOUT = 0xC0;
const CMD_SET_WS_TIMEOUT = 0xC1;
const CMD_RESET_RAINGAUGE = 0xC3;
Expand Down Expand Up @@ -270,6 +272,14 @@ function encodeDownlink(input) {
errors: []
};
}
else if (input.data.cmd == "CMD_GET_LW_STATUS") {
return {
bytes: [0],
fPort: CMD_GET_LW_STATUS,
warnings: [],
errors: []
};
}
else if (input.data.cmd == "CMD_GET_WS_TIMEOUT") {
return {
bytes: [0],
Expand Down Expand Up @@ -559,6 +569,7 @@ function decodeDownlink(input) {
switch (input.fPort) {
case CMD_GET_DATETIME:
case CMD_GET_LW_CONFIG:
case CMD_GET_LW_STATUS:
case CMD_GET_WS_TIMEOUT:
case CMD_GET_STATUS_INTERVAL:
case CMD_GET_SENSORS_STAT:
Expand Down
11 changes: 11 additions & 0 deletions scripts/uplink_formatter.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@
// 20240605 Fixed decoding of NaN values, fixed flags for compatibility mode
// 20240606 Changed naming of post-processed lightning data
// 20240607 Added CMD_GET_STATUS_INTERVAL
// 20240608 Added CMD_GET_LW_STATUS
//
// ToDo:
// -
Expand All @@ -151,6 +152,7 @@ function decoder(bytes, port) {

const CMD_GET_DATETIME = 0x86;
const CMD_GET_LW_CONFIG = 0xB1;
const CMD_GET_LW_STATUS = 0xB2;
const CMD_GET_WS_TIMEOUT = 0xC0;
const CMD_GET_SENSORS_INC = 0xC4;
const CMD_GET_SENSORS_EXC = 0xC6;
Expand Down Expand Up @@ -607,6 +609,15 @@ function decoder(bytes, port) {
['sleep_interval', 'sleep_interval_long'
]
);
} else if (port === CMD_GET_LW_STATUS) {
return decode(
port,
bytes,
[uint16, uint8
],
['ubatt_mv', 'long_sleep'
]
);
} else if (port === CMD_GET_WS_TIMEOUT) {
return decode(
port,
Expand Down

0 comments on commit 443acb4

Please sign in to comment.