From 2a84361facde2fbdbd9ddc13819be6de3f282afa Mon Sep 17 00:00:00 2001 From: Matthias Prinke <83612361+matthias-bs@users.noreply.github.com> Date: Thu, 13 Jun 2024 17:38:02 +0200 Subject: [PATCH] Fixed using BLE addresses from preferences (#71) --- BresserWeatherSensorLWCfg.h | 14 +++++++++----- src/PayloadBLE.cpp | 14 +++++++------- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/BresserWeatherSensorLWCfg.h b/BresserWeatherSensorLWCfg.h index b513397..b133426 100644 --- a/BresserWeatherSensorLWCfg.h +++ b/BresserWeatherSensorLWCfg.h @@ -301,16 +301,20 @@ const uint8_t UBATT_SAMPLES = 10; // BLE battery o.k. threshold in percent #define BLE_BATT_OK 5 +/* // List of known sensors' BLE addresses -// #define KNOWN_BLE_ADDRESSES \ -// { \ -// "a4:c1:38:b8:1f:7f" \ -// } -// #endif +#define KNOWN_BLE_ADDRESSES \ + { \ + "a4:c1:38:b8:1f:7f" \ + } +*/ + +// Empty list - BLE disabled #define KNOWN_BLE_ADDRESSES \ { \ \ } + #endif /// Maximum number of 868 MHz sensors - should match the default configuration below diff --git a/src/PayloadBLE.cpp b/src/PayloadBLE.cpp index 3d09e96..e9bc89e 100644 --- a/src/PayloadBLE.cpp +++ b/src/PayloadBLE.cpp @@ -91,7 +91,7 @@ std::vector PayloadBLE::getBleAddr(void) for (size_t i = 0; i < size; i += 6) { char addr[18]; - snprintf(addr, 18, "%02X:%02X:%02X:%02X:%02X:%02X", + snprintf(addr, 18, "%02x:%02x:%02x:%02x:%02x:%02x", addrBytes[i], addrBytes[i + 1], addrBytes[i + 2], addrBytes[i + 3], addrBytes[i + 4], addrBytes[i + 5]); bleAddr.push_back(addr); } @@ -106,19 +106,19 @@ void PayloadBLE::bleAddrInit(void) { knownBLEAddressesDef = KNOWN_BLE_ADDRESSES; knownBLEAddresses = getBleAddr(); - if (knownBLEAddresses.size() == 0) + if (knownBLEAddresses.size() != 0) + { + log_d("Using BLE addresses from Preferences:"); + } + else if (knownBLEAddressesDef.size() != 0) { // No addresses stored in Preferences, use default knownBLEAddresses = knownBLEAddressesDef; log_d("Using BLE addresses from BresserWeatherSensorLWCfg.h:"); } - else if (knownBLEAddressesDef.size() == 0) - { - log_d("No BLE addresses specified."); - } else { - log_d("Using BLE addresses from Preferences:"); + log_d("No BLE addresses specified."); } bleSensors = BleSensors(knownBLEAddresses);