Skip to content

BLEDevice::getAddress() can't be used prior to init / no way to change device name after ::init() #1199

@spbwgit

Description

@spbwgit

Perhaps not a common use case, but I was trying to embed the BT mac address in the name of my ESP32 device (ie. "gizmo-112233445566") when initializing BLEDevice, for uniqueness.
Unfortunately, BLEDevice::getAddress() crashes if it's called before ::init().
Just a bit of a chicken and egg problem for my use case... It's entirely likely this is the desired behaviour -- ie. do not call getAddress() until after initialized.

In BLEDevice::getAddress(), there's a call to esp_bt_dev_get_address(), and this isn't allowed prior to calling esp_bluedroid_init(), which isn't invoked until BLEDevice::init().
I checked whether it's possible to call ::init() twice to update the device name, since there is no utility method to do so, however the call to esp_ble_gap_set_device_name() is within the if (!initialized){} block.

My workarounds for the moment could be:
-call esp_bluedroid_init() prior to calling BLEDevice::getAddress(), since the function won't be called a second time. but it's possible btStart(), esp_bt_controller_enable() and others should be called first. I haven't looked too far into it.
-find another way to get the mac prior to ::init(). e.g., with esp_read_mac(xxx, ESP_MAC_BT).

Anyhow.. just thought I'd mention that it'd be nice if there were an in-band way to either retrieve the mac in advance of init, or a way to set the name after the fact. Maybe this is an esoteric corner case though :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions