OpenMQTTGateway v1.4.0

What’s Changed

Adaptive scanning

This release brings a very interesting feature for Bluetooth Low Energy scanning.
You may have already asked yourself, what should I set for the interval between my scans? Do I use passive or active scanning? Or how do these parameters impact the battery life of my sensors?
To remove these questions, @DigiH and I have integrated an innovative function - Adaptive scanning

Adaptive scanning will decide automatically following your devices if you need to use passive/active/continuous scanning.

For example, a door or a PIR sensor will require continuous scanning, so if detected, the gateway will reduce its time between scans to the minimum. Or your devices may also require active scanning to retrieve data. The gateway will trigger active scans at regular intervals in this case.
Behind the scenes, a big work on device categorization and analysis has been done in Theengs Decoder to enable this feature.

Why are we doing this?
Increase your sensors’ battery life, decrease network traffic, and reduce gateway power consumption.

See below in Home Assistant how the interval is automatically adapted after the detection of a PIR sensor nearby.

OpenMQTTGateway-adaptive-scan

This new feature is activated by default, you can deactivate it, and the gateway will go directly into continuous active scanning.
Consequently, the esp32ble-dev-cont environment has been merged into esp32ble-dev, and the “Active scan” command has been removed. You can remove the topic from your broker to delete it from the controller.

Theengs Plug

Also, this release brings support for the second RGB Led of the Theengs Plug alongside the capability to reset at the start. I encourage Theengs Plug users to update following this guide.

New boards

New BLE devices

Devices Model Measurements
Polar H10 Chest strap activity heart rate

Features

Docs

Miscellaneous

New Contributors

Full Changelog: v1.3.0…v1.4.0

2 Likes

Dear Florian,

Can you adapt the maximum time between active scan to 600 sec for Temp/Hr sensor ?
If yes, I would like to install it and set the active scan to 5 minutes and check if batteries will last a bit more.

Thanks
Eric

Hello,

You can adapt it with the following MQTT command:
home/OpenMQTTGateway/commands/MQTTtoBT/config -m '{"interval":600000}'

1 Like

Hi Florian, DigiH,

A request about the new Adaptive scanning.

It mean if it detect a PIR, it will reduce the scan to +/- 1sec ?
In this case all other devices like Sensor will be scanned every same period of 1 Sec.
Is it correct ?
If yes, is it a good think ?

You say “a door or a PIR sensor will require continuous scanning”.
For this kind of sensor, it should itself send multiple time spontaneously an alarm.

If I install the last version, I suppose I have to enable Adaptive Scan to make it scan T° sensors.
I don’t want it detect something which will reduce the scan to 1 sec.
Is it possible to lock the scan period to 5 minutes.

Thanks

Eric

Hello,

You still can deactivate the adaptive scanning and adjust the interval as you want, like 5 minutes.

The interval will go to 100ms if it detects a PIR BLE device.

1 Like

I think there was a bit of confusion :wink: sounds as if @esa66 wants it similar to how I have it set, only have active scanning every 5 minutes, but more frequent, or even continuous passive scanning.

So with adaptive scanning true or false, interval is or can be set to 100 ms if a PIR is present.

Then set the active scan interval with

mosquitto_pub -t home/OpenMQTTGateway/commands/MQTTtoBT/config -m '{"intervalacts":300000}'

to only have one active scan every 5 minutes.

1 Like

Hi,
If I set {“interval”:50000}
I can see it is accepted by OMG :

image

But I can’t see a value bigger than 100 s

I set to 600000, it stay at 50 s

It is like it refuses to set a value bigger than 100 s.

Can you confirm the value is accepted even if I see another value on the OMG interface ?

@DigiH

Correct, 5 minutes is enough for T° Sensor.
For other sensor like a PIR, listening can be every time (I suppose listening is passive scanning).
Because I suppose a PIR will transmit is status directly if there is a change. It seems logic.

Remark : I suppose ‘{“intervalacts”:300000}’ is for the last version V1.4.0
And {“interval”:50000} is for precedent version.

As long as you see it in the broker is is accepted

1 Like

{"interval":50000} is for passive scanning, so you would want that to 100 ms if you have a PIR - assuming that your PIR works fine with passive scanning. Adaptive scan would do that automatically now.

{"intervalacts":300000} is the additional separate interval for active scanning, which allows such sensors to be actively scanned at a lower frequency.

How did you set it to 600000? I just set mine to 1200000 and it sticks fine. Is it only a display issue in HA, what does it say in the BTtoMQTT message in MQTT Explorer? I can see 600000 in your screenshot above.

1 Like

Hi Florian,

I confirm it works based on a period of 10 minutes (I exaggerate to see it on the plot).

Now, I’ll check the battery discharge for a period of +/- 1 week

Thanks

2 Likes

Hi,

I make the upgrade to 1.4.0

I create a beacon with my phone to test the difference between active and passive scan.

I can see it with MQTT Explorer and it is updated at same frequency as SB Meter at rate of 60 sec (for test).

It should be transmitted and discovered into HA. But I don’t see new entity or device in HA.
My configuration is as follow :

{
“bleconnect”: false,
“interval”: 50000,
“adaptivescan”: false,
“intervalacts”: 61000,
“intervalcnct”: 3600000,
“onlysensors”: false,
“hasspresence”: false,
“presenceTopic”: “presence/”,
“presenceUseBeaconUuid”: true,
“minrssi”: -100,
“extDecoderEnable”: false,
“extDecoderTopic”: “undecoded”,
“filterConnectable”: false,
“pubadvdata”: true,
“pubBeaconUuidForTopic”: true,
“ignoreWBlist”: false,
“btqblck”: 1,
“btqsum”: 419,
“btqsnd”: 391,
“btqavg”: 1.071611
}

So, I decided to activate “Adaptive scan” and set
{“interval”:60000} for the beacon and {“intervalacts”:600000} for the Meter Plus.

In this case, it seems the SB Meter are scanned each minute.
I suppose the battery of Meter plus will be more solicited and I don’t want this.

I read the documentation about the new adaptive scan.
I try to understand how it works and differences between all mode.
What I understand : correct me

Braodcast : is a message send by the gateway to all devices to transmit their data. It is used by passive mode : Correct ?

passive scan scanning is controlled by {“interval”:60000}. It is for Beacon, PIR, Door status which require high rate of scanning (using broadcast ?).

active scan : controlled by {“intervalacts”:600000} . It is for Meter with a low scan period.

BLE connect controlled by intervalcnct. What is the specific need of this type of connection ?

Adaptive Scan
I understand that if it is deactivated, it will not do “passive passive” scan.
Below information’s is a bit contradicting ?

I also noticed that if I disable adaptive scan it always scan at rate of the “passive scan”.

And I can also see it is scanned as “active scan”

Remark :

  1. In scan BLE, it is related to interval and not ‘intervalacts’ which is now for active scan
  2. When Active scan is disable, period for both scan is set to minimum 100mS which can dry battery very quick if you don’t see it.

image

I have the same issue after a power lost. Is it possible to load the last configuration.
I know how to restore, {"load":true}, but if I’m not there it can run a lot of time.
Presence :
I can see the Meter are also scanned in the presence Topic. I though it was only for beacon ?

For my purpose, I only use Meter at scanning rate of 10 minutes.
So, I set :

  • Passive scan to 5 minutes : for test purpose, so I can see it also scan the Meter but without measure.
  • Active scan to 10 minutes to retrieve Measure from Meter.

A few questions :

  1. This is not important for me as it was only for a test, but why I don’t see the iBeacon in HA
  2. If I want a simple ibeacon not in real time. Is it enough to use “active scan” at the same rate as the Meter (+/- 10 minutes).
  3. As it is for slow rate, can you set “active scan” in minute like you do for “Connect BT” ?

Have a nice day
Best regards.

I have propsed some additions to the documentation, which you can view at

Let us know if this clears up your above confusion about adaptive, passive, active and continuous scanning, or if it possibly needs further information.

Hi,

I noticed the battery discharge a bit quick and noticed that adaptive scan and interval come back to 100mS

I don’t know what happens, but :

  • When you toggle the “Adaptive scan”, it reset both period scan to 100mS. I don’t do it.
  • When you restart (Button SYS Restart Gateway) or lost of current. Default period is 100mS

After setting again both scan period, I do a save : {“save”:true}
After a restart, I can restore with the command reload {“load”:true}.
How can I force to reload the saved value at restart ?
I want to be sure it stay at 10 minutes scan because 100mS is too quick and will discharge the battery.

Best Regard

Hi @esa66,

what happens if you don’t toggle adaptive scanning, leave "adaprivescan":false, set both interval and intervalacts to your liking, then {“save”:true}, and it should stick over any restart without having to load.

Do you, by any chance, also have a SwitchBot Moteion Sensor or SwitchBot Contact Sensor? As these do actually require constant active scanning (“intervalacts”:100).

Hi,

I make a short video to show the issue.
Maybe it will show something I do wrongly.

Remark : After the SYS restart, I wrongly set the value again + save, but it is enough to make a “load”
This is what I make after the power restart.

Video

Best Regards

Hi @esa66,

The video is not showing, only a still image - I think due to the restrictions of the forum software.

Could you try the latest development build, to see if you issue has been remedied with the latest changes, some made after your initial report.

Please let us know how it is working for you with this version.

For any videos to show properly they world need to be uploaded to YouTube or similar else and then linked to here.

Hi,
I was still busy to upload a video, after I see the simple picture :thinking:
Now, there is a link to download the video.
Can you check the same I do in your LAB ?
You are too quick :wink:

Thanks for the video, and one thing which immediately strikes me as odd is the fact that you still have BT Active Scan present in your HA OMG gateway interface. A legacy property which should not be present any longer with adaptive scanning, and which I suspect might cause the reset to the 100ms for both interval and intervalacts after a restart.

I’m not that knowledgeable about the HA discovery and therefore HA interface options, so someone else will have to have a look at this oddity.

Just to see what happens, could you set your Active Scan switch to OFF the whole time, and see if it makes any difference?

Did you also try the above mentioned test development buidl, to see if it makes any changes for you?

Hi digiH,
I have understood the shape for the gateway isn’t correctly updated.
I have disabled the “Active Scan”. I didn’t understand that it is no more active. It continue to scan with periodic request of 10 minutes

I make a sysrestart and noticed that default scan of 100mS is restored.

To reproduce the issue, you can do the following :
Topic : home/OpenMQTTGateway_ESP32_BLE/commands/MQTTtoBT/config

Step 1 : Save a new value : {“interval”:600001,“intervalacts”:600002,“save”:true}
Step 2 : Set a new value without save : {“interval”:600001,“intervalacts”:600003}
Step 3 : Check saved value : {“load”:true} ==> it restores “intervalacts”: 600002,
Step 4 : SYSRESTART ==> Default value of 100mS is activated : “intervalacts”: 100
Step 5 : Load saved value : {“load”:true}

Conclusion, After a restart, saved values are not restored.
Hope it help.

Next step :
I have decided to build a LAB environment for testing latest development build.
I’ll reinstall everything on Debian but it will take +/- 1 week.

Have a nice week-end

My problem is, that after step 4 (even without step 3) I get

“interval”:600001,
“adaptivescan”:false,
“intervalacts”:600002

as expected, without having to do step 5 to load anything. Admittedly with the development branch, as suggested above, which you can also install at

The issue remaining is, do you also have "adaptivescan":false, as otherwise you might well have a device being scanned which does require continuous active scanning, in which case adaptive scanning would correctly set the values back to "interval":100 and "intervalacts": 100.

1 Like