10

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?

askedSep 25, 2018 at 7:36
BK52's user avatar

1 Answer1

11

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

Serial.print(F("Name -> "));Serial.println(founded_dev.getName().c_str());
answeredSep 25, 2018 at 8:22
Majenko's user avatar
3
  • That works for getName() but not some of the other methods such asBLEAdvertisedDevice::getAddress() orBLEAdvertisedDevice::getServiceUUID()CommentedJan 31, 2020 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.CommentedJan 31, 2020 at 9:53
  • 2
    For the UUID you can usegetServiceUUID().toString().c_str(), For the address you can use:getAddress().toString().c_str().CommentedJan 31, 2020 at 9:54

Your Answer

Sign up orlog in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

By clicking “Post Your Answer”, you agree to ourterms of service and acknowledge you have read ourprivacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.