BLE advertisement cache

Greetings!

I am making a weather sensor integration app for Homey. Sensors use Bluetooth Low Energy (BLE) to communicate with Homey.

The problem is that Homey.ManagerBLE.discover() and Homey.ManagerBLE.find() both return cached advertisements and do not refresh them in a reasonable time (several minutes at max).

It is crucial for the advertisements to be refreshed every time Homey discovers them from the sensors in my app, as the sensor BLE advertisement contains data about current sensor state (calibrating, updating firmware, disabled integration, etc.) and availability to be connected to.

Restarting the app seems to be one way to clear cached advertisements and after that the next discover returns fresh advertisements, but is not an appropriate solution to the problem.

So my question is:

  • Is there a way to clear app cache or get fresh advertisements from BLE device?

Thank you in advance.

I don’t think there are any API’s that you can use to clear the cache, so you’d have to ask Athom (through the support form) if there are any “hidden” ways to clear the cache (or, if there aren’t, explain your use case and ask them to provide for methods to clear it, or to simply not cache at all if so requested).

Maybe @Koktail can tell you something about it

Hi

I have the same problem with a RuuviTag device ; I need to refresh the manufacturerData field. Does someone have a way to get updated (and not cached) values ?

Thanks

Hi

If anybody else has this problem : using cache for find() is correct, but it’s not for discover(). See here for the bug report : https://github.com/athombv/homey-apps-sdk-issues/issues/154
Good news is : it’s possible to clear the cache. In my app, before discover(), it works with :

            //listing all devices
            let devices = Homey.ManagerDrivers.getDriver('ruuvitag').getDevices();

            //clear BLE cache for each device
            devices.forEach(device => delete Homey.ManagerBLE.__advertisementsByPeripheralUUID[device.getData().uuid]);

(uuid is stored in the data field, at device creation)

2 Likes

Thanks for the tip. My app is now much more responsive.