-
Notifications
You must be signed in to change notification settings - Fork 151
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added BTHome advertising field "packet id" for deduplication #211
Conversation
Thanks @seime. Have you tested this change? I'm asking because I think it would go over the maximum possible payload of 23 bytes (full packet defined here). We currently (before this PR) have 19 bytes of service data plus the "prst" device name in the advertisement packet. I have a feeling this change will bump the device name out of the packet. Can you try to verify? If that's the case, we would have to either:
Let me know your thoughts. I'm interested in learning about what issues you faced without the counter. |
It works fine - at least for me :) I've implemented the BTHome binding for openHAB, and with short enough update interval I can see the counter increase from 0 and upwards. Sometimes it skips a number, but that just means I've lost a packet. I'm using a set of ESP32s running ESPHome to sniff traffic, and I think there are more than 200 BLE devices in range. So no wonder why packets are lost ;) Are you sure about the 23 byte limit? And that it isn't 27? I'm not gonna say I'm right on this one, I've not studied the format recently. But I'm farily certain that in a previous project we pushed 27 bytes (and we did your option 3 - splitting and merging multiple advertisements into one larger - quite a few things to think about). |
I dug a little deeper and, as far as I understand, here's what's happening: We have a maximum of 31 bytes for the whole advertising packet (assuming no extended adv for max compatibility), split into the following AD components: 3 bytes: flags (length: 2 + It leaves us with 22 bytes for advertising data. For the BTHome service, we must have:
This leaves us with a 20 bytes hard limit for the actual service data. To validate these assumptions, I modified bleak's detection_callback.py -- my version here:
It's nice to see the counter increments on the last byte of the adv data, but unfortunately as expected the local name got chopped into |
OK, I didn't realize the name got chopped as I tested it on an already registered device in my system. Thanks for the detailed analysis though, your support is highly appreciated! |
See https://bthome.io/format/
While most home automation system have some deduplication, not all do.