7

I'm working on BLE project with espressif library. And It returns me founded BLE device.

std::string getManufacturerData();
std::string getName();
int         getRSSI();
BLEScan*    getScan();

When I want to print device name to serial port

BLEAdvertisedDevice founded_dev;
founded_dev=foundDevices.getDevice(0);
Serial.println("Name -> " + founded_dev.getName());

It gives me error like this

no matching function for call to 'HardwareSerial::println(std::__cxx11::basic_string<char>)'

So how can i convert to std:string to String in Arduino?

7

Don't. Instead just access the underlying C string:

Serial.print(F("Name -> "));
Serial.println(founded_dev.getName().c_str());
| improve this answer | |
  • That works for getName() but not some of the other methods such as BLEAdvertisedDevice::getAddress() or BLEAdvertisedDevice::getServiceUUID() – Tom Auger Jan 31 at 2:04
  • @TomAuger That's because they don't return a string. The first returns a BLEAddress, the second a BLEUUID. Custom types that will need special handling. – Majenko Jan 31 at 9:53
  • 1
    For the UUID you can use getServiceUUID().toString().c_str(), For the address you can use: getAddress().toString().c_str(). – Majenko Jan 31 at 9:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.