feat(ble): Set device name at runtime
This allows for the device name to be set at runtime, possible uses for this include a custom display screen that lets you type it in using the keycode state event, future configuration in zmk studio, or altering it per profile as per #1169
Testing shows restarting advertising was necessary to update the new name, although some host OS's don't reflect the name change properly even with this in mind, also of note is some hosts don't update the name after pairing too
Should this change the USB device name as well?
I can probably make a function to do it for USB, I don't think one function should do both as there's no logical place for that one function to live, whatever system the developer is using at the other end should call both to change both. I think there's also a good argument for keeping them separate as there are good reasons to want to change them independently e.g. per profile naming
Ah neat I didn't know that. I did find in my testing that results from this were inconsistent. iOS and Linux reflected the name change whilst scanning, android didn't. That should probably sort this. I've also got it saving and restoring from flash, and will incorporate that too
Ah neat I didn't know that. I did find in my testing that results from this were inconsistent. iOS and Linux reflected the name change whilst scanning, android didn't. That should probably sort this. I've also got it saving and restoring from flash, and will incorporate that too
Yeah, bt_set_name implementation will store to settings if it's enabled. See hci_core.c:bt_set_name
I've got it working now using CONFIG_BT_DEVICE_NAME_DYNAMIC. If i'm reading the PR associated with this function properly i think we get up to 27 chars for device name now too which is a neat bonus. The saving to flash can't be debounced, because it's outside of our control but i cant imagine that as a major problem. The advertising packet had to be changed, as ZMK used the advertising packet to report the name previously.
I suppose the final question is do we want the name to be writable by the host device? There's no downsides to it i guess
Just checked and CONFIG_BT_DEVICE_NAME_GATT_WRITABLE is enabled even when only enabling CONFIG_BT_DEVICE_NAME_DYNAMIC. Name can sucessfully be read and written using nRF connect. all seems to be working properly
@ReFil Check the BLE test error.. maybe advertising data changes?
Yes I think that's the issue, name is now at the end of the ad packet not the beginning. Will sort that when I have a mo
Yes I think that's the issue, name is now at the end of the ad packet not the beginning. Will sort that when I have a mo
@ReFil Nudge.
@petejohanson Sorry for the delay in addressing it. I've tweaked the tests to remove the offending line from the logs and they all pass now