Skip to content

Use runtime BLE name based on MAC address#108

Merged
zjwhitehead merged 6 commits intomasterfrom
unique-ble
Apr 1, 2026
Merged

Use runtime BLE name based on MAC address#108
zjwhitehead merged 6 commits intomasterfrom
unique-ble

Conversation

@zjwhitehead
Copy link
Copy Markdown
Member

Build a runtime advertising name from the device MAC and use it for BLE advertising instead of the hardcoded kAdvertisingName. Add gAdvertisingName buffer and kAdvertisingNameCapacity, plus initAdvertisingName() to construct a per-device name (and return an uppercase unique ID string). Replace earlier setName usages to reference gAdvertisingName and move the advertising name assignment into the payload configuration path. Change include from to to use snprintf, and update NimBLEDevice::init() to initialize NimBLE before the advertising-name initialization (initAdvertisingName() must be called after NimBLEDevice::init()). Also add prototypes for helper functions shouldAdvertiseWhilePowered() and startAdvertising().

Build a runtime advertising name from the device MAC and use it for BLE advertising instead of the hardcoded kAdvertisingName. Add gAdvertisingName buffer and kAdvertisingNameCapacity, plus initAdvertisingName() to construct a per-device name (and return an uppercase unique ID string). Replace earlier setName usages to reference gAdvertisingName and move the advertising name assignment into the payload configuration path. Change include from <cctype> to <cstdio> to use snprintf, and update NimBLEDevice::init() to initialize NimBLE before the advertising-name initialization (initAdvertisingName() must be called after NimBLEDevice::init()). Also add prototypes for helper functions shouldAdvertiseWhilePowered() and startAdvertising().
Display a Bluetooth symbol on the main LVGL screen to indicate BLE pairing mode and add a flashing indicator for it. Declares ble_pairing_icon in the header, creates the label in lvgl_main_screen (font, color, alignment, hidden by default), and adds ble_pairing_flash_timer and isFlashingBLEPairingIcon state in lvgl_updates. Implements ble_pairing_flash_timer_cb, startBLEPairingIconFlash and stopBLEPairingIconFlash with mutex protection, proper timer creation/deletion and error handling. Wire up start/stop calls: start when pairing is entered via button hold, and stop on pairing timeout and on new BLE connections in ble_core. This provides a visible, thread-safe pairing-mode indicator for users.
Add BLE_PAIR_ON_BOOT build flag and conditional logic to automatically enter BLE pairing mode during setup. platformio.ini now defines -D BLE_PAIR_ON_BOOT, and setupBLE() prints a notice and calls enterBLEPairingMode() and startBLEPairingIconFlash() when the flag is set, enabling firmware builds that start pairing on boot.
Change the BLE advertising name format to include only the last two MAC bytes and wrap them in brackets. The snprintf call was updated from "%s %02X%02X%02X" using mac[3],mac[4],mac[5] to "%s [%02X%02X]" using mac[4],mac[5], shortening and reformatting the device name.
Adjust BLE pairing icon placement in the main screen (use lv_obj_set_pos(103,72) instead of lv_obj_align) and add test coverage for the BLE pairing indicator. Tests include light and dark screenshot cases plus reference BMPs. Also update the emulator teardown to clear ble_pairing_icon, its flash timer and flash state so tests start from a clean state.
@zjwhitehead zjwhitehead marked this pull request as ready for review April 1, 2026 18:02
@zjwhitehead zjwhitehead merged commit 2d408f3 into master Apr 1, 2026
9 checks passed
@zjwhitehead zjwhitehead deleted the unique-ble branch April 1, 2026 18:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant