| So I have some experience with this. I decided to add BLE beacons to my vehicles and bicycles, and an RPI to listen for the pings and retransmit them over mqtt. The idea was I could setup some Home Assistant alerts for things like "multiple vehicles are absent at once" or "vehicle went from home to away at odd hour" where "odd hour" is something like 12AM-5AM, a time when I wouldn't expect me or my vehicles to be departing. The way I implemented it was to have each beacon transmit on I think 1s (might have been 5s to save power) intervals, and some python code on an RPI that listens for them, with a timeout for each. If the listener gets a ping it immediately forwards it to mqtt as a "home" ping, using the beacon id to set the topic. If it doesn't get a ping within the timeout then the rpi generates and sends an "away" mqtt message for that beacon. My expectation was to have it alert me within ~2-3 minutes of a vehicle going from "home" to "away". In practice: - BLE beacons aren't very popular really, most of them are made by small foreign companies who don't sell them in places like Amazon. The ones Amazon does sell are kind of crappy. Setting them up usually involves downloading a vaguely-sketchy app to your phone (I haven't figured out how to configure them from the rpi). They all seem kind of janky honestly. - Bluetooth and Wifi use the same (some) hardware on an rpi, meaning if you start rapidly scanning for BLE tokens your wifi performance will drop to the point of the rpi being unusable (ssh sessions timing out). I fixed this by buying a separate USB bluetooth dongle, although even that was a pain to get working in the pybluez module - in general bluetooth under linux along with the python bindings are finicky and crap out easily, it seems. - I have my dmesg and syslog spammed with "Bluetooth: hci0: advertising data len corrected" when using bluetooth scanning, I managed to find a couple bug references to it and other people complaining about it but no fixes over multiple system updates. - It's just... Not reliable. I don't know why. I've tried really hard to make it reliable, and maybe the problem is the RPI-as-bluetooth (maybe if I used a microcontroller as the receiver it would work better?), but I've tried all variations of scanning windows and such and dug down into the code for Bluez without figuring out either what I'm doing wrong or where the issue is. Beacons will supposedly not ping for minutes at a time despite being on a 5s interval no matter what I do, and this is for beacons maybe 6 feet from the receiver (although ones further away do timeout more). The last thing is what finally killed the project for me. I had it (still have it) all setup in HA with notifications and schedules and such, but I just turned off all the automation for it until I get a chance to tear it down. Failed experiment. |