Skip to content

Commit

Permalink
[BT] Continuous active scanning when adaptive scanning is false (#1448)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
1technophile authored Feb 10, 2023
1 parent 159d362 commit 7c0fafd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
4 changes: 3 additions & 1 deletion docs/use/ble.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
:::
Expand Down
11 changes: 8 additions & 3 deletions main/ZgatewayBT.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 7c0fafd

Please sign in to comment.