From 7c0fafd48ef82a03b8c556193b65199cb9a14f66 Mon Sep 17 00:00:00 2001 From: Florian Date: Fri, 10 Feb 2023 17:05:52 -0600 Subject: [PATCH] [BT] Continuous active scanning when adaptive scanning is false (#1448) Set `interval` and `intervalacts` to the minimum when adaptive scanning is deactivated. When the user encounters a situation on which a device is not detected due to adaptive scanning, we set the gateway to continuous active to maximize the chance to detect the device. --- docs/use/ble.md | 4 +++- main/ZgatewayBT.ino | 11 ++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/docs/use/ble.md b/docs/use/ble.md index c7ae370..d16c30b 100644 --- a/docs/use/ble.md +++ b/docs/use/ble.md @@ -137,13 +137,15 @@ The gateway will publish only the detected sensors like Mi Flora, Mi jia, LYWSD0 ## Setting if the gateway use adaptive scanning Adaptive scanning lets the gateway decide for you the best passive `interval` and active `intervalacts` scan interval, depending on the characteristics of your devices. -The gateway retrieves your devices' information from [Theengs Decoder](https://decoder.theengs.io) and adapts its parameters accordingly. +The gateway retrieves your devices' information from [Theengs Decoder](https://decoder.theengs.io) and adapts its parameters accordingly if a device that requires it is detected. For example a door or a PIR sensor will require continuous scanning, so if detected the gateway is going to reduce its time between scans to the minimum. Or your devices may also require active scanning to retrieve data, in this case the gateway will also trigger active scans at regular intervals. If you want to change this characteristic (default:true): `mosquitto_pub -t home/OpenMQTTGateway/commands/MQTTtoBT/config -m '{"adaptivescan":false}'` +Setting Adaptive scanning to `false` will automatically put the gateway to continuous active scanning. + ::: tip With Home Assistant, this command is directly available through MQTT auto discovery as a switch into the HASS OpenMQTTGateway device entities list. ::: diff --git a/main/ZgatewayBT.ino b/main/ZgatewayBT.ino index 50299ef..e6727d7 100644 --- a/main/ZgatewayBT.ino +++ b/main/ZgatewayBT.ino @@ -151,12 +151,17 @@ void stateBTMeasures(bool start) { void BTConfig_fromJson(JsonObject& BTdata, bool startup = false) { // Attempts to connect to eligible devices or not BTConfig_update(BTdata, "bleconnect", BTConfig.bleConnect); + // Identify AdaptiveScan deactivation to pass to continuous mode + if (BTdata.containsKey("adaptivescan") && BTdata["adaptivescan"] == false && BTConfig.adaptiveScan == true) { + BTdata["interval"] = MinTimeBtwScan; + BTdata["intervalacts"] = MinTimeBtwScan; + } + BTConfig_update(BTdata, "adaptivescan", BTConfig.adaptiveScan); + // Time before before active scan // Scan interval set if (BTdata.containsKey("interval") && BTdata["interval"] != 0) BTConfig_update(BTdata, "interval", BTConfig.BLEinterval); - // Define if the scan is active or passive - BTConfig_update(BTdata, "adaptivescan", BTConfig.adaptiveScan); - // Time before before active scan + // Define if the scan is adaptive or not BTConfig_update(BTdata, "intervalacts", BTConfig.intervalActiveScan); // Time before a connect set BTConfig_update(BTdata, "intervalcnct", BTConfig.intervalConnect);