From 115a17cbcc4fe78fc310c4b44c4ec7069fffe034 Mon Sep 17 00:00:00 2001 From: DigiH Date: Wed, 17 Apr 2024 15:32:27 +0200 Subject: [PATCH] [BT] Prevent intervalacts from being lower than interval (#1932) Prevent intervalacts from being lower than interval to avoid untrue non-sensical intervalacts values. --- docs/use/ble.md | 4 ++++ main/ZgatewayBT.ino | 17 +++++++++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/docs/use/ble.md b/docs/use/ble.md index e534e1c..3b25a04 100644 --- a/docs/use/ble.md +++ b/docs/use/ble.md @@ -222,6 +222,10 @@ If you want to change the time between active scans you can change it by MQTT. F `mosquitto_pub -t home/OpenMQTTGateway/commands/MQTTtoBT/config -m '{"intervalacts":300000}'` +::: warning Note +The active scan interval `intervalacts` can only bet set equal to or higher than the passive scan interval `interval`, as any lower value would not make any sense. +::: + ## Setting the duration of a scan (available with HA discovery) If you want to change the default duration of each scan cycle to 5 seconds diff --git a/main/ZgatewayBT.ino b/main/ZgatewayBT.ino index 8a91458..a72c489 100644 --- a/main/ZgatewayBT.ino +++ b/main/ZgatewayBT.ino @@ -195,11 +195,20 @@ void BTConfig_fromJson(JsonObject& BTdata, bool startup = false) { btPresenceParametersDiscovery(); # endif // Time before before active scan - // Scan interval set - if (BTdata.containsKey("interval") && BTdata["interval"] != 0) + // Scan interval set - and avoid intervalacts to be lower than interval + if (BTdata.containsKey("interval") && BTdata["interval"] != 0) { Config_update(BTdata, "interval", BTConfig.BLEinterval); - // Define if the scan is adaptive or not - Config_update(BTdata, "intervalacts", BTConfig.intervalActiveScan); + if (BTConfig.intervalActiveScan < BTConfig.BLEinterval) { + Config_update(BTdata, "interval", BTConfig.intervalActiveScan); + } + } + // Define if the scan is adaptive or not - and avoid intervalacts to be lower than interval + if (BTdata.containsKey("intervalacts") && BTdata["intervalacts"] < BTConfig.BLEinterval) { + // Config_update(BTdata, "interval", BTConfig.intervalActiveScan); + BTConfig.intervalActiveScan = BTConfig.BLEinterval; + } else { + Config_update(BTdata, "intervalacts", BTConfig.intervalActiveScan); + } // Time before a connect set Config_update(BTdata, "intervalcnct", BTConfig.intervalConnect); // publish all BLE devices discovered or only the identified sensors (like temperature sensors)