ukBaz / python-bluezero

A simple Python interface to Bluez
MIT License
387 stars 112 forks source link

Allow service data advertisement for peripherals #406

Open chadrockey opened 5 months ago

chadrockey commented 5 months ago

The Android version of the NRF Wifi Provisioning app expects Service Data instead of typical advertised service UUIDs.

https://github.com/NordicSemiconductor/Android-nRF-Wi-Fi-Provisioner/blob/0094211ae252745dbd9b7805fb0e41ebd0f91cc6/app/src/main/java/no/nordicsemi/android/wifi/provisioning/scanner/ProvisioningData.kt#L56

Because their UUID is the full 128 bits, the advertisement fails to publish because it won't fit. As far as I can tell, if you publish service data, LightBlue and NRFConnect all still see the service, so having service data should supercede the service advertisements.

I believe this is the most straightforward and user friendly way to do this. I had also considered a "bluez_peripheral" like function call, but it doesn't seem needed right now.

advert = Advertisement(name, [], 0, 0, serviceData={WIFI_COMMISSION_SERVICE_UUID:bytes([0x02, 0x00, 0x00, 0x00])}) await advert.register(bus, adapter)

ukBaz commented 5 months ago

Apologies for taking so long to get to this.

Do you have an example of the calling of the new Peripheral with advertising service data? I'd like to see how you envisage it being used as I'm not sure if it following the complexity guidelines

Passing in detailed service data information at a "level 10" interface feels like people would have to know a bit about how advertisements are created. My intention when I was creating the library was that in situations like this where people wanted to be more sophisticated with what they were doing, they would drop down to the "level 100" apis.

I also think that there are a number of people that would be interested in being able to attach a Raspberry Pi to a WiFi network via Bluetooth, so I could see that this specific application could be shipped with "level 1" API.

If we do agree that putting this in the Peripheral code is correct, I would also like to discuss if having it as part of "publish()" is correct. I'm also confused by your use of await in the text above. I associate that with the asyncio event loop and not the event loop used by BlueZ.