naugehyde / bt-sensors-plugin-sk

0 stars 0 forks source link

Polling frequency #2

Open sveinhansen opened 1 week ago

sveinhansen commented 1 week ago

Hi

I was pleased to see this plugin for SignalK.

Would it be an idea to be able to configure a polling frequency for a BLE device? I seems that it is currently sampling data every 6 seconds or so.

I suspect that polling it often will drain the battery of the Xiaomi LYWSD03MMC device. I use these devices to monitor temp/humid during the winter i Norway to ensure that I do not have too much condensation etc. I typically need 1-2 hours frequency for sampling the data. Currently one battery lasts from October to May.

Thanks!

Regards, Svein

naugehyde commented 14 hours ago

Hi Svein.

Glad you're finding the plugin useful. Lots of work still to do and a new version with support for more devices is coming.

Leaving a Xiaomi LYWSD03MMC connected will indeed drain its battery in about two weeks. The manufacturer's firmware doesn't broadcast the device's data but demands a GATT connection that's responsible for the battery drain.

You have two alternatives:

1) flashing the device per https://github.com/atc1441/ATC_MiThermometer and using the ATC class instead 2) deactivating the device when its not in use on your boat

Highly recommend the first option. I did it on my boat and the now connection-less LYWSD03MMC runs happily with precious little battery loss. The problem is that not all LYWSD03MMCs can be flashed over the air. Xiaomi rewrote the device's firmware to prevent OTA flashing. If you are successful flashing it, my plugin supports the ATC firmware.

Also, just an FYI, I've noticed that my Xiaomi LYWSD03MMC in connection mode (GATT) can cause havoc on the Bluetooth stack on my Rpi4B. It works fine in isolation but when you try to connect any second device, the Bluetooth stack fails. Also, in some configurations, the Xiaomi device will, after being connected to, shut down the 4B's scanner without notification. The problem appears to originate somewhere deep in my Linux distribution's firmware so it's beyond me how to fix. That said, if all you're doing is connecting to one LYWSD03MMC, the plugin should work fine-- albeit with significant battery loss. I've been meaning to put a warning up about this but I don't have comprehensive information outside of my configuration. To that end, could you tell me what hardware you are running SK on and what Bluetooth adapter you're using? I'd appreciate that.

Future versions of the plugin will allow for selective GATT connection polling on the LYWSD03MMC and other GATT-only devices but in some configurations it won't work reliably for the LYWSD03MMC owing to the platform issues discussed above.

I'm aiming to get a Beta of the plugin out soon and will implement a polling option for the LYWSD03MMC. It'll be difficult for me to test it owing to platform issues but if you're in a position to test it that'd be great.

Best,

Andrew Gerngross

naugehyde commented 11 hours ago

Svein,

As of today, I have a working pre-beta that includes a polling option for the LYWSD03MMC. If you want to test it, let me know and I'll walk you through setting it up.

-Andrew