-
Notifications
You must be signed in to change notification settings - Fork 7.5k
samples: bluetooth: Add sample demonstrating direct advertising #50340
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
Conversation
19e9173
to
6585013
Compare
Hi @morsisko I tried the sample again today on my custom nRF52840 board sporting a Raytac MDBT50Q. The issue I'm reporting may be limited to the fact that I'm testing on iPhone, or the specific board, but for what it is worth here is my experience: Using my iphone I use the nRF Connect app to locate the device, then I pair to it by writing to the characteristic. Within Ozone it is apparent that the bond is stored and the device reboots. After reboot, Ozone outputs that there is targeted advertising occurring, however nRF Connect can no longer connect to it nor can it find it again when scanning. Perhaps this works better with two nRF52 devices rather than an iPhone (maybe iPhone does not support targeted advertisement?). Just some speculation for what it's worth. Anyway if you'd like me to try anything specific on my hardware please let me know and I will gladly try. I do have a few more of these devices that I can try together, and will be getting my hands on an Android device later this week and plan to try this again at that time. Thanks! |
6585013
to
e5fe1be
Compare
Hi @kfatehi What iPhone is it? Not sure about iOS and BLE privacy. You could try to comment out this line: It looks like some devices not fully support this feature, for example:
Unfortunately I don't own modern iPhone. I've got one iPhone 5S somewhere, but I'm afraid it might be too old. It would be nice if you could test other non-zephyr solution with your board. If direct advertising would work in that case, this probably mean that the problem is inside Zephyr itself. In this situation I recommend to file separate issue (unless someone can point what is wrong with this sample), so people with knowledge about Zephyr BLE internals can take a look. |
ce5ba8b
to
a0f79d9
Compare
@morsisko I am using an iPhone 12 Mini. I tried removing
This seems to be consistent with the seemingly arbitrary limitation in Apple's acessory design guidelines (linked in one of the apple forum posts) It's weird to me that Apple says not to use it, doesn't say why, and then says to look at the spec as though the spec will indicate why, but when I look at the spec I don't see any reason why "not to use it" -- now I don't know if this is even relevant or is what the direct advertising in this sample is using, considering how old it is, but the whole situation is confusing. To make matters worse, I borrowed an Android phone from a family member as a hail mary attempt to prove that Apple is broken in some way, but I had the same exact behavior, so I'm throwing my hands up for now. |
bb6f962
a0f79d9
to
bb6f962
Compare
Apple recommendations dates back to Bluetooth 4.0/4.1 and it was not possible to properly handle directed advertising and privacy in those spec versions. So it is likely that this sample will have issues reconnecting with any 4.0 devices (if they use privacy). To handle this, sample should enable directed advertising using RPA as target addr only if remote central indicated support for this (by having Central Address Resolution characteristic with value 1). This is from spec: As you can see this is not requirement but recommendation (should) but it may be confusing to people if it will work only with some devices and won't with others.. |
Thanks for the thorough explanation @sjanc ! |
So should I add this check to the code or leave it as is? |
Do I understand correctly, that Apple devices will resolve RPAs for non-directed advertisement even if Central Address Resolution feature characteristic is not present? Core spec 5.3 says "If the Central Address Resolution characteristic is not present, then it shall be assumed that Central Address Resolution is not supported." EDIT: I assume yes. Since the remote accepted the IRK key distribution. I think it implies that "Central Address Resolution" concerns only directed advertising.
I am for merging this PR as is now. But I welcome another PR that modifies the sample to be more real-world like / define the best-practice that real world applications should follow. EDIT: I think if the Central Address Resolution feature is not available, it would make sense to emulate directed advertising using a connectable, non-scannable advertisement with no data and the highest duty cycle allowed. There is also the question of what a real-world application should do if a peer does not support privacy at all. |
I agree, we should merge this as-is, else it's just scope creep. This sample clearly says it will use directed advertising. |
This sample shows how to run BLE direct advertising towards central with enabled privacy.
On each boot application checks whether any bond exists. If not - it starts casual advertising. After pairing reboot is performed. If bond exists application starts direct advertising towards previously bonded central with enabled privacy.
Additionally the application has got one service with two characteristics, one for reading and another for encrypted writing (and thus it requires devices to be paired)
The sample was tested with EBYTE-TBB board featuring nRF52832 MCU. The central device was modern smartphone with Android >=7.0