h2zero / NimBLE-Arduino

A fork of the NimBLE library structured for compilation with Arduino, for use with ESP32, nRF5x.
https://h2zero.github.io/NimBLE-Arduino/
Apache License 2.0
700 stars 145 forks source link

change address and payload #585

Open beckmx opened 1 year ago

beckmx commented 1 year ago

hello there, i was reading the docs and studying the code, I was wondering if it is possible to define a custom Bluetooth address for the device and then advertise a custom payload, at least the payload part from what i can see is somehow achievable with the beacon example, thanx a lot for this lib!! :)

h2zero commented 1 year ago

Sorry for the late response. Yes, a custom MAC address is able to be set with calls to the esp controller:

uint8_t new_mac[8] = {0x01,0x02,0x03,0x04,0x05,0x06};
esp_base_mac_addr_set(new_mac);

I'm not sure what you mean by a custom payload but most anything is possible here.

beckmx commented 1 year ago

And should it work the same for the nrf 51?

Koxx3 commented 3 weeks ago

hello. I also need to change address periodically to advertise with rotating MACs. esp_base_mac_addr_set doesn't seem to be taken into account dynamically. is there any solution ?

an equivalent of esp_ble_gap_ext_adv_set_rand_addr (bluedroid) would be perfect ;)

h2zero commented 2 weeks ago

For nRF and others you can use this:

ble_addr_t addr;
ble_hs_id_gen_rnd(0, &addr); // Set first arg to 1 if you want NRPA
ble_hs_id_set_rnd(addr.val);