-
Notifications
You must be signed in to change notification settings - Fork 189
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
Wrong handling of property 'name' for BLE devices #570
Comments
There are some implementation issues which make passing strings that are not valid UTF-8. I'd like to better understand the use case for device names containing unprintable characters. Why isn't this information in fields designed for binary data like Not updating |
Actually the NUL character is fully valid in UTF-8, although not a printable one. The Bluetooth standard says the following:
It here explicitly lists U+0000 (and all other non-printable characters) as codepoints. This is most likely an implementation bug where NUL-terminated C strings are used somewhere in the pipeline and not a WebBluetooth specification issue. |
Hi, @reillyeon :
Given the constrains below, we get only a 31 bytes (minus IDs and payload bytes) in which to carry an information changing from time to time. It's quite tight and using raw binary values gives a chance to pack data even a bit more, allowing the full range of values to be used whereas b64 or any other kind of encoding won't allow that. Anyway I sacrified 4 bytes just to try, adding an AD block of type SERVICE_DATA (0x16): @Emill : Thanks, Phil |
Hi team,
I currently get troubles interacting with a BLE device from which advertisement data is dynamic.
It runs a scenario where the AD structure LOCAL NAME (AD_TYPE 0x09) needs to update regularly its raw binary content.
Here are the 2 issues encountered:
Web BLE API assumes LOCAL_NAME to be a NULL terminated string whereas the BLE specifications clearly don't.
An AD structure looks like this : (1)[LENGTH] + (LENGTH)[ (N)[AD_TYPE] + (LENGTH-N)[AD_DATA] ]
For an AD structure of type LOCAL_NAME containing 4 bytes : (1)[0x05] (5)[ (1)[0x09] + (4)[0x00 0x01 0x02 0x03] ]
==> Final byte sequence is : (6)[ 0x05 0x09 0x00 0x01 0x02 0x03 ]
But in such case Web BLE API returns a 0 byte long name (empty string) instead of 4 bytes long string
"\x00\x01\x02\x03".
Whatever bytes are non ASCII nor displayable, the AD length byte is the only reliable data telling how long the local
name is, and since it's allowed to pass raw binary data here, null byte should not be interpreted as an 'end of string'.
BluetoothDevice.name always contains the same value while the device dynamically updates advertised data.
Even using watchAdvertisements() and event 'advertisementreceived', property 'name' remains the same. It seems
the value is retrieved at pairing stage, but is never updated anymore after.
Case 1) is trivial to experiment : just introduce a null byte in LOCAL_NAME AD structure of any advertising BLE device...
Case 2) is easily reproduced running this demo page while advertisement gets updated:
https://googlechrome.github.io/samples/web-bluetooth/watch-advertisements.html
Thanks for reading.
Best Regards,
Phil
The text was updated successfully, but these errors were encountered: