NimBLE-Arduino icon indicating copy to clipboard operation
NimBLE-Arduino copied to clipboard

Specifying Client Address

Open miag676 opened this issue 4 years ago • 5 comments
trafficstars

Hello, first of all thanks for making and maintaining the library. I would like to connect to a specific BLE beacon. Currently I am using this command and it's working perfectly: pClient = NimBLEDevice::createClient(NimBLEAddress("49:42:06:00:20:4e")); However, if I substitute it with a variable I get the error: no matching function for call to 'NimBLEAddress::NimBLEAddress(String)'. This is the code: pClient = NimBLEDevice::createClient(NimBLEAddress(String(value)));

Can the command accept such values or must it be specified like in the first case?

Any help would be appreciated! Kind regards, Mia

miag676 avatar Jul 14 '21 09:07 miag676

I've managed to resolve the error by using an integer: pClient = NimBLEDevice::createClient(NimBLEAddress(value.toInt()));, however, it also truncates the address from 49:42:06:00:20:4e to 49. Do you know what could be the solution?

miag676 avatar Jul 14 '21 17:07 miag676

Hi @miag676, the NimBLEAddress constructor takes a std::string parameter. If you change the code in the first post to std::string(value) instead of String(value) it should work.

h2zero avatar Jul 14 '21 18:07 h2zero

Thanks for your response! I tried using it like this: pClient = NimBLEDevice::createClient(NimBLEAddress(std::string(value)));, but get the following error: no matching function for call to 'std::__cxx11::basic_string::basic_string(String&)'. Did I write anything wrong in this line of code?

miag676 avatar Jul 14 '21 19:07 miag676

Try this: NimBLEDevice::createClient(NimBLEAddress(std::string(value.c_str())));

A std::string needs a char* for initialization

sivar2311 avatar Jul 14 '21 19:07 sivar2311

Thank you very much. This solved the issue!

miag676 avatar Jul 14 '21 19:07 miag676