diff --git a/BresserWeatherSensorLW.ino b/BresserWeatherSensorLW.ino index 78e7e55..0bc414b 100644 --- a/BresserWeatherSensorLW.ino +++ b/BresserWeatherSensorLW.ino @@ -79,6 +79,8 @@ // 20240416 Added enabling of 3.3V power supply for FeatherWing on ESP32-S3 PowerFeather // 20240423 Removed rtcSyncReq & runtimeExpired, added rtcTimeSource // 20240424 Added appLayer.begin() +// 20240525 PowerFeather: added BATTERY_CAPACITY_MAH to init() +// Added BresserWeatherSensorLWCmd.h // // ToDo: // - @@ -151,6 +153,7 @@ using namespace PowerFeather; #include #include #include "BresserWeatherSensorLWCfg.h" +#include "BresserWeatherSensorLWCmd.h" #include "src/AppLayer.h" #include "src/adc/adc.h" @@ -463,7 +466,7 @@ void setup() #if defined(ARDUINO_ESP32S3_POWERFEATHER) delay(2000); - Board.init(); // Note: Battery capacity / type has to be set for voltage measurement + Board.init(BATTERY_CAPACITY_MAH); // Note: Battery capacity / type has to be set for voltage measurement Board.enable3V3(true); // Power supply for FeatherWing Board.enableVSQT(true); // Power supply for battery management chip (voltage measurement) #endif diff --git a/BresserWeatherSensorLWCfg.h b/BresserWeatherSensorLWCfg.h index 0827507..a227c7e 100644 --- a/BresserWeatherSensorLWCfg.h +++ b/BresserWeatherSensorLWCfg.h @@ -44,6 +44,8 @@ // for ARDUINO_heltec_wifi_lora_32_V3 // Added BLE configuration/status via LoRaWAN // 20240430 Modified battery voltage measurement +// 20240504 PowerFeather: added BATTERY_CAPACITY_MAH +// Moved LoRaWAN command interface to BresserWeatherSensorLWCmd.h // // Note: // Depending on board package file date, either @@ -59,248 +61,6 @@ #if !defined(_LWCFG_H) #define _LWCFG_H -//#include -//#include - -// =========================== -// LoRaWAN command interface -// =========================== - -// --------------------------- -// -- LoRaWAN network layer -- -// --------------------------- - -// CMD_GET_DATETIME -// ----------------- -#define CMD_GET_DATETIME 0x86 - -// Downlink (command): -// byte0: 0x00 - -// Uplink (response): -// byte0: unixtime[31:24] -// byte1: unixtime[23:16] -// byte2: unixtime[15: 8] -// byte3: unixtime[ 7: 0] -// byte4: rtc_source[ 7: 0] - - -// CMD_SET_DATETIME -// ----------------- -// Port: CMD_SET_DATETIME -#define CMD_SET_DATETIME 0x88 - -// Downlink (command): -// byte0: unixtime[31:24] -// byte1: unixtime[23:16] -// byte2: unixtime[15: 8] -// byte3: unixtime[ 7: 0] - -// Uplink: n.a. - -// CMD_SET_SLEEP_INTERVAL -// ----------------------- -// Note: Set normal sleep interval in seconds -// Port: CMD_SET_SLEEP_INTERVAL -#define CMD_SET_SLEEP_INTERVAL 0xA8 - -// Downlink (command): -// byte0: sleep_interval[15:8] -// byte1: sleep_interval[ 7:0] - -// Response: n.a. - -// CMD_SET_SLEEP_INTERVAL_LONG -// ---------------------------- -// Note: Set long sleep interval in seconds (energy saving mode) -// Port: CMD_SET_SLEEP_INTERVAL_LONG -#define CMD_SET_SLEEP_INTERVAL_LONG 0xA9 - -// Downlink (command): -// byte0: sleep_interval_long[15:8] -// byte1: sleep_interval_long[ 7:0] - -// Uplink: n.a. - -// CMD_GET_LW_CONFIG -// ------------------ -// Port: CMD_GET_LW_CONFIG -#define CMD_GET_LW_CONFIG 0xB1 - -// Downlink (command): -// byte0: 0x00 - -// Uplink (response): -// byte0: sleep_interval[15: 8] -// byte1: sleep_interval[ 7:0] -// byte2: sleep_interval_long[15:8] -// byte3: sleep_interval_long[ 7:0] - -// ----------------------- -// -- Application layer -- -// ----------------------- - -// CMD_GET_WS_TIMEOUT -// ------------------- -// Note: Get weather sensor RX timeout in seconds -// Port: CMD_GET_WS_TIMEOUT -#define CMD_GET_WS_TIMEOUT 0xC0 - -// Downlink (command) -// byte0: 0x00 - -// Uplink (response): -// byte0: ws_timeout[ 7: 0] - -// CMD_SET_WS_TIMEOUT -// ------------------- -// Note: Set weather sensor RX timeout in seconds -// Port: CMD_SET_WS_TIMEOUT -#define CMD_SET_WS_TIMEOUT 0xC1 - -// Downlink (command): -// byte0: ws_timeout[ 7: 0] - -// Uplink: n.a. - -// CMD_RESET_RAINGAUGE -// -------------------- -// Port: CMD_RESET_RAINGAUGE -#define CMD_RESET_RAINGAUGE 0xC3 - -// Downlink (command): -// byte0: flags[7:0] (optional) - -// Uplink: n.a. - -// Reset Lightning??? -// ------------------- - - -// CMD_GET_SENSORS_INC -// -------------------- -// Note: Get sensors include list (0...12 IDs) -// Port: CMD_GET_SENSORS_INC -#define CMD_GET_SENSORS_INC 0xC4 - -// Downlink (command): -// byte0: 0x00 - -// Uplink (response): -// byte0: sensors_inc0[31:24] -// byte1: sensors_inc0[23:16] -// byte2: sensors_inc0[15: 8] -// byte3: sensors_inc0[ 7: 0] -// ... - -// CMD_SET_SENSORS_INC -// -------------------- -// Note: Set sensors include list (0...12 IDs) -// Port: CMD_SET_SENSORS_INC -#define CMD_SET_SENSORS_INC 0xC5 - -// Downlink (command): -// byte0: sensors_inc0[31:24] -// byte1: sensors_inc0[23:16] -// byte2: sensors_inc0[15: 8] -// byte3: sensors_inc0[ 7: 0] -// ... - -// Uplink: n.a. - -// CMD_GET_SENSORS_EXC -// -------------------- -// Note: Get sensors exclude list (0...12 * 4 bytes) -// Port: CMD_GET_SENSORS_EXC -#define CMD_GET_SENSORS_EXC 0xC6 - -// Downlink (command): -// byte0: 0x00 - -// Uplink (response): -// byte0: sensors_exc0[31:24] -// byte1: sensors_exc0[23:16] -// byte2: sensors_exc0[15: 8] -// byte3: sensors_exc0[ 7: 0] -// ... - -// CMD_SET_SENSORS_EXC -// -------------------- -// Note: Set sensors exclude list (0...12 * 4 bytes) -// Port: CMD_SET_SENSORS_EXC -#define CMD_SET_SENSORS_EXC 0xC7 - -// Downlink (command): -// byte0: sensors_exc0[31:24] -// byte1: sensors_exc0[23:16] -// byte2: sensors_exc0[15: 8] -// byte3: sensors_exc0[ 7: 0] -// ... - -// Uplink: n.a. - -// CMD_GET_BLE_ADDR -// ----------------- -// Note: Get BLE sensors MAC addresses (0..8 * 6 bytes) -// Port: CMD_GET_BLE_ADDR -#define CMD_GET_BLE_ADDR 0xC8 - -// Downlink (command): -// byte0: 0x00 - -// Uplink (response): -// byte0: ble_addr0[47:24] -// byte1: ble_addr0[23:32] -// byte2: ble_addr0[31:24] -// byte3: ble_addr0[23:16] -// byte4: ble_addr0[15: 8] -// byte5: ble_addr0[ 7: 0] -// ... - -// CMD_SET_BLE_ADDR -// ----------------- -// Note: Set BLE sensors MAC addresses (0..8 * 6 bytes) -// Port: CMD_SET_BLE_ADDR -#define CMD_SET_BLE_ADDR 0xC9 - -// Downlink (command): -// byte0: ble_addr0[47:24] -// byte1: ble_addr0[23:32] -// byte2: ble_addr0[31:24] -// byte3: ble_addr0[23:16] -// byte4: ble_addr0[15: 8] -// byte5: ble_addr0[ 7: 0] -// ... - -// Response: n.a. - -// CMD_GET_BLE_CONFIG -// ------------------- -// Note: Scan time in seconds -// Port: CMD_GET_BLE_CONFIG -#define CMD_GET_BLE_CONFIG 0xCA - -// Downlink (command): -// byte0: 0x00 - -// Uplink (response): -// byte0: 0x01 (active scan) / 0x00 (passive scan) -// byte1: scan_time[7:0] - -// CMD_SET_BLE_CONFIG -// ------------------- -// Note: Scan time in seconds -// Port: CMD_SET_BLE_CONFIG -#define CMD_SET_BLE_CONFIG 0xCB - -// Uplink (command): -// byte0: active_scan - 0x01 (active scan) / 0x00 (passive scan) -// byte1: scan_time[7:0] - -// Response: n.a. - -// =========================== - // Enable debug mode (debug messages via serial port) // Arduino IDE: Tools->Core Debug Level: "Debug|Verbose" @@ -424,7 +184,12 @@ #elif defined(ARDUINO_heltec_wifi_32_lora_V3) || defined(ARDUINO_heltec_wifi_lora_32_V3) // On-board VB #define PIN_ADC_IN A0 -#elif defined(ESP32S3_POWERFEATHER) +#elif defined(ARDUINO_ESP32S3_POWERFEATHER) +// Set battery capacity in mAh +#define BATTERY_CAPACITY_MAH 0 +#if BATTERY_CAPACITY_MAH == 0 +#pragma message("Battery capacity set to 0 - battery voltage measurement disabled.") +#endif // unused #define PIN_ADC_IN -1 #elif defined(ARDUINO_M5STACK_Core2) || defined(ARDUINO_M5STACK_CORE2) diff --git a/BresserWeatherSensorLWCmd.h b/BresserWeatherSensorLWCmd.h new file mode 100644 index 0000000..d1e3615 --- /dev/null +++ b/BresserWeatherSensorLWCmd.h @@ -0,0 +1,285 @@ +/////////////////////////////////////////////////////////////////////////////// +// BresserWeatherSensorLWCmd.h +// +// LoRaWAN Command Interface +// +// Definition of control/configuration commands and status responses for +// LoRaWAN network layer and application layer +// +// created: 05/2024 +// +// +// MIT License +// +// Copyright (c) 2024 Matthias Prinke +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. +// +// +// History: +// +// 20240504 Extracted from BresserWeatherSensorLWCfg.h +// +// ToDo: +// - +// +/////////////////////////////////////////////////////////////////////////////// + +#if !defined(_LWCMD_H) +#define LWCMD_H + +// =========================== +// LoRaWAN command interface +// =========================== + +// --------------------------- +// -- LoRaWAN network layer -- +// --------------------------- + +// CMD_GET_DATETIME +// ----------------- +#define CMD_GET_DATETIME 0x86 + +// Downlink (command): +// byte0: 0x00 + +// Uplink (response): +// byte0: unixtime[31:24] +// byte1: unixtime[23:16] +// byte2: unixtime[15: 8] +// byte3: unixtime[ 7: 0] +// byte4: rtc_source[ 7: 0] + + +// CMD_SET_DATETIME +// ----------------- +// Port: CMD_SET_DATETIME +#define CMD_SET_DATETIME 0x88 + +// Downlink (command): +// byte0: unixtime[31:24] +// byte1: unixtime[23:16] +// byte2: unixtime[15: 8] +// byte3: unixtime[ 7: 0] + +// Uplink: n.a. + +// CMD_SET_SLEEP_INTERVAL +// ----------------------- +// Note: Set normal sleep interval in seconds +// Port: CMD_SET_SLEEP_INTERVAL +#define CMD_SET_SLEEP_INTERVAL 0xA8 + +// Downlink (command): +// byte0: sleep_interval[15:8] +// byte1: sleep_interval[ 7:0] + +// Response: n.a. + +// CMD_SET_SLEEP_INTERVAL_LONG +// ---------------------------- +// Note: Set long sleep interval in seconds (energy saving mode) +// Port: CMD_SET_SLEEP_INTERVAL_LONG +#define CMD_SET_SLEEP_INTERVAL_LONG 0xA9 + +// Downlink (command): +// byte0: sleep_interval_long[15:8] +// byte1: sleep_interval_long[ 7:0] + +// Uplink: n.a. + +// CMD_GET_LW_CONFIG +// ------------------ +// Port: CMD_GET_LW_CONFIG +#define CMD_GET_LW_CONFIG 0xB1 + +// Downlink (command): +// byte0: 0x00 + +// Uplink (response): +// byte0: sleep_interval[15: 8] +// byte1: sleep_interval[ 7:0] +// byte2: sleep_interval_long[15:8] +// byte3: sleep_interval_long[ 7:0] + +// ----------------------- +// -- Application layer -- +// ----------------------- + +// CMD_GET_WS_TIMEOUT +// ------------------- +// Note: Get weather sensor RX timeout in seconds +// Port: CMD_GET_WS_TIMEOUT +#define CMD_GET_WS_TIMEOUT 0xC0 + +// Downlink (command) +// byte0: 0x00 + +// Uplink (response): +// byte0: ws_timeout[ 7: 0] + +// CMD_SET_WS_TIMEOUT +// ------------------- +// Note: Set weather sensor RX timeout in seconds +// Port: CMD_SET_WS_TIMEOUT +#define CMD_SET_WS_TIMEOUT 0xC1 + +// Downlink (command): +// byte0: ws_timeout[ 7: 0] + +// Uplink: n.a. + +// CMD_RESET_RAINGAUGE +// -------------------- +// Port: CMD_RESET_RAINGAUGE +#define CMD_RESET_RAINGAUGE 0xC3 + +// Downlink (command): +// byte0: flags[7:0] (optional) + +// Uplink: n.a. + +// Reset Lightning??? +// ------------------- + + +// CMD_GET_SENSORS_INC +// -------------------- +// Note: Get sensors include list (0...12 IDs) +// Port: CMD_GET_SENSORS_INC +#define CMD_GET_SENSORS_INC 0xC4 + +// Downlink (command): +// byte0: 0x00 + +// Uplink (response): +// byte0: sensors_inc0[31:24] +// byte1: sensors_inc0[23:16] +// byte2: sensors_inc0[15: 8] +// byte3: sensors_inc0[ 7: 0] +// ... + +// CMD_SET_SENSORS_INC +// -------------------- +// Note: Set sensors include list (0...12 IDs) +// Port: CMD_SET_SENSORS_INC +#define CMD_SET_SENSORS_INC 0xC5 + +// Downlink (command): +// byte0: sensors_inc0[31:24] +// byte1: sensors_inc0[23:16] +// byte2: sensors_inc0[15: 8] +// byte3: sensors_inc0[ 7: 0] +// ... + +// Uplink: n.a. + +// CMD_GET_SENSORS_EXC +// -------------------- +// Note: Get sensors exclude list (0...12 * 4 bytes) +// Port: CMD_GET_SENSORS_EXC +#define CMD_GET_SENSORS_EXC 0xC6 + +// Downlink (command): +// byte0: 0x00 + +// Uplink (response): +// byte0: sensors_exc0[31:24] +// byte1: sensors_exc0[23:16] +// byte2: sensors_exc0[15: 8] +// byte3: sensors_exc0[ 7: 0] +// ... + +// CMD_SET_SENSORS_EXC +// -------------------- +// Note: Set sensors exclude list (0...12 * 4 bytes) +// Port: CMD_SET_SENSORS_EXC +#define CMD_SET_SENSORS_EXC 0xC7 + +// Downlink (command): +// byte0: sensors_exc0[31:24] +// byte1: sensors_exc0[23:16] +// byte2: sensors_exc0[15: 8] +// byte3: sensors_exc0[ 7: 0] +// ... + +// Uplink: n.a. + +// CMD_GET_BLE_ADDR +// ----------------- +// Note: Get BLE sensors MAC addresses (0..8 * 6 bytes) +// Port: CMD_GET_BLE_ADDR +#define CMD_GET_BLE_ADDR 0xC8 + +// Downlink (command): +// byte0: 0x00 + +// Uplink (response): +// byte0: ble_addr0[47:24] +// byte1: ble_addr0[23:32] +// byte2: ble_addr0[31:24] +// byte3: ble_addr0[23:16] +// byte4: ble_addr0[15: 8] +// byte5: ble_addr0[ 7: 0] +// ... + +// CMD_SET_BLE_ADDR +// ----------------- +// Note: Set BLE sensors MAC addresses (0..8 * 6 bytes) +// Port: CMD_SET_BLE_ADDR +#define CMD_SET_BLE_ADDR 0xC9 + +// Downlink (command): +// byte0: ble_addr0[47:24] +// byte1: ble_addr0[23:32] +// byte2: ble_addr0[31:24] +// byte3: ble_addr0[23:16] +// byte4: ble_addr0[15: 8] +// byte5: ble_addr0[ 7: 0] +// ... + +// Response: n.a. + +// CMD_GET_BLE_CONFIG +// ------------------- +// Note: Scan time in seconds +// Port: CMD_GET_BLE_CONFIG +#define CMD_GET_BLE_CONFIG 0xCA + +// Downlink (command): +// byte0: 0x00 + +// Uplink (response): +// byte0: 0x01 (active scan) / 0x00 (passive scan) +// byte1: scan_time[7:0] + +// CMD_SET_BLE_CONFIG +// ------------------- +// Note: Scan time in seconds +// Port: CMD_SET_BLE_CONFIG +#define CMD_SET_BLE_CONFIG 0xCB + +// Uplink (command): +// byte0: active_scan - 0x01 (active scan) / 0x00 (passive scan) +// byte1: scan_time[7:0] + +// Response: n.a. + +// =========================== +#endif \ No newline at end of file diff --git a/package.json b/package.json index fb3c95a..0a5dd81 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "BresserWeatherSensorLW", - "version": "0.3.0", + "version": "0.3.1", "description": "Bresser 868 MHz Weather Sensor Radio Receiver; provides data via LoRaWAN", "main": "BresserWeatherSensorLW.ino", "frameworks": "arduino", diff --git a/src/AppLayer.h b/src/AppLayer.h index 15f75b5..d81d6c4 100644 --- a/src/AppLayer.h +++ b/src/AppLayer.h @@ -37,6 +37,7 @@ // 20240419 Modified downlink decoding // 20240424 Fixed BLE address initialization from Preferences, added begin() // 20240426 Moved bleAddrInit() out of begin() +// 20240504 Added BresserWeatherSensorLWCmd.h // // ToDo: // - @@ -51,6 +52,7 @@ #include #include #include "../BresserWeatherSensorLWCfg.h" +#include "../BresserWeatherSensorLWCmd.h" #include "adc/adc.h" #include