From 03a54bc78586e777b80df206371565542ab5aa13 Mon Sep 17 00:00:00 2001 From: Matthias Prinke Date: Fri, 26 Apr 2024 09:38:39 +0200 Subject: [PATCH] Refactored BLE address initialization --- src/AppLayer.cpp | 3 ++- src/AppLayer.h | 18 ++++++++++++++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/AppLayer.cpp b/src/AppLayer.cpp index f185a6c..1065e65 100644 --- a/src/AppLayer.cpp +++ b/src/AppLayer.cpp @@ -41,6 +41,7 @@ // 20240424 Fixes in decodeDownlink() // Fixed getBleAddr() // Implemented resetting of knownBLEAddresses to defaults +// 20240426 Added BLE address initialization after updating via downlink // // // ToDo: @@ -141,8 +142,8 @@ AppLayer::decodeDownlink(uint8_t port, uint8_t *payload, size_t size) payload[i + 5]); } - // Note: New addresses will be applied only after restart. setBleAddr(payload, size); + bleAddrInit(); return 0; } diff --git a/src/AppLayer.h b/src/AppLayer.h index a61029b..cc378e9 100644 --- a/src/AppLayer.h +++ b/src/AppLayer.h @@ -36,6 +36,7 @@ // 20240417 Added sensor configuration functions // 20240419 Modified downlink decoding // 20240424 Fixed BLE address initialization from Preferences, added begin() +// 20240426 Moved bleAddrInit() out of begin() // // ToDo: // - @@ -140,11 +141,23 @@ class AppLayer /*! * \brief AppLayer initialization * + */ + void begin(void) + { + bleAddrInit(); + }; + + /* + * \brief Initialize list of known BLE addresses from defaults or Preferences + * + * If available, addresses from Preferences are used, otherwise defaults from + * BresserWeatherSensorLWCfg.h. + * * BleSensors() requires Preferences, which uses the Flash FS, * which is not available before the sketches' begin() is called - - * thus the following cannot be handled by the constructor. + * thus the following cannot be handled by the constructor! */ - void begin(void) + void bleAddrInit(void) { #if defined(MITHERMOMETER_EN) || defined(THEENGSDECODER_EN) knownBLEAddressesDef = KNOWN_BLE_ADDRESSES; @@ -167,6 +180,7 @@ class AppLayer #endif }; + /*! * \brief Decode app layer specific downlink messages *