diff --git a/BresserWeatherSensorLW.ino b/BresserWeatherSensorLW.ino index c10e752..b956122 100644 --- a/BresserWeatherSensorLW.ino +++ b/BresserWeatherSensorLW.ino @@ -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: // - @@ -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); } @@ -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); diff --git a/BresserWeatherSensorLWCmd.h b/BresserWeatherSensorLWCmd.h index 668d8f9..99eb58c 100644 --- a/BresserWeatherSensorLWCmd.h +++ b/BresserWeatherSensorLWCmd.h @@ -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: // - @@ -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 -- // ----------------------- diff --git a/README.md b/README.md index 1305e4f..5127f8f 100644 --- a/README.md +++ b/README.md @@ -371,6 +371,8 @@ Many software parameters can be defined at compile time, i.e. in [BresserWeather | | Weather sensor receive timeout in seconds; 0...255 | | | Sleep interval (regular) in seconds; 0...65535 | | | Sleep interval (energy saving mode) in seconds; 0...65535 | +| | Battery voltage in mV | +| | 0: regular sleep interval / 1: long sleep interval (depending on U_batt) | | \ | Unix epoch time, see https://www.epochconverter.com/ ( \ / "0x....") | | | Raingauge reset flags; 0...15 (1: hourly / 2: daily / 4: weekly / 8: monthly) / "0x0"..."0xF" | | | Real time clock source; 0x00: GPS / 0x01: RTC / 0x02: LORA / 0x03: unsynched / 0x04: set (source unknown) | @@ -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]
sleep_interval[7:0] | n.a. | | CMD_SET_SLEEP_INTERVAL_LONG | 0xA9 (169) | sleep_interval_long[15:8]
sleep_interval_long[7:0] | n.a. | | CMD_GET_LW_CONFIG | 0xB1 (177) | 0x00 | sleep_interval[15:8]
sleep_interval[7:0]
sleep_interval_long[15:8]
sleep_interval_long[7:0] | +| CMD_GET_LW_STATUS | 0xB2 (178) | 0x00 | ubatt_mv[15:8]
ubatt_mv[7:0]
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. | @@ -466,6 +469,7 @@ Many software parameters can be defined at compile time, i.e. in [BresserWeather | CMD_SET_SLEEP_INTERVAL | {"sleep_interval": } | n.a. | | CMD_SET_SLEEP_INTERVAL_LONG | {"sleep_interval_long": } | n.a. | | CMD_GET_LW_CONFIG | {"cmd": "CMD_GET_LW_CONFIG"} | {"sleep_interval": , "sleep_interval_long": } | +| CMD_GET_LW_STATUS | {"cmd": "CMD_GET_LW_STATUS"} | {"ubatt_mv": , "long_sleep": } | | CMD_GET_WS_TIMEOUT | {"cmd": "CMD_GET_WS_TIMEOUT"} | {"ws_timeout": } | | CMD_SET_WS_TIMEOUT | {"ws_timeout": } | n.a. | | CMD_RESET_RAINGAUGE | {"reset_flags": } | n.a. | diff --git a/scripts/downlink_formatter.js b/scripts/downlink_formatter.js index 4e5e04a..0bdc72d 100644 --- a/scripts/downlink_formatter.js +++ b/scripts/downlink_formatter.js @@ -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: // - @@ -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; @@ -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], @@ -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: diff --git a/scripts/uplink_formatter.js b/scripts/uplink_formatter.js index 0ab3ddc..9158109 100644 --- a/scripts/uplink_formatter.js +++ b/scripts/uplink_formatter.js @@ -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: // - @@ -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; @@ -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,