Setting Bluetooth MAC address.

I am working on a very simple project. I have modified the bthome_sensor_template zephyr example to send a Bluetooth alert whenever a sensor is triggered, it works well so far. My problem is that whenever I power on the device I have to go in and reconnect to it because it sets up a different MAC address and shows up as a new device. I would like to set up a  persistent MAC address so that it shows up as the same device when being powered on. So far I have tried the suggestions to previous post with similar problems like using bt_id_create(), bt_le_ext_adv_create, bt_addr_le_from_str, bt_addr_le_t, and bt_ctlr_set_public_addr. So far I haven't figured out how to get any of those work. It may be that I'm missing something from my conf file or something like that who knows. I just need someone to point me in the right direction, thanks.

  • Hi,

    The address is private random by default. You can use a static random address by calling bt_id_create() before bt_enable().

  • I did what you said and I was still having trouble so I just went in and did a deeper debug. What I found out was that I needed to make my bt_le_adv_start "param" advertising parameter BT_LE_ADV_NCONN_IDENTITY to match my BT_LE_ADV_PARAM "_options" parameter. I also thought that my bt_addr_le_t address type needed to be BT_ADDR_LE_PUBLIC in order to set up a persistent MAC address, but it actually needed to be BT_ADDR_LE_RANDOM. Anyways using bt_id_create() before bt_enable() worked I just had some set up issues I needed to fix. My device works now, it shows up as the same device on each power up so I don't have to reconnect to it each time. Thanks Einer.

Related