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?
asked Sep 25, 2018 at 7:36
1 Answer 1
Don't. Instead just access the underlying C string:
Serial.print(F("Name -> "));
Serial.println(founded_dev.getName().c_str());
answered Sep 25, 2018 at 8:22
-
That works for getName() but not some of the other methods such as
BLEAdvertisedDevice::getAddress()
orBLEAdvertisedDevice::getServiceUUID()
Tom Auger– Tom Auger01/31/2020 02:04:47Commented Jan 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.Majenko– Majenko01/31/2020 09:53:21Commented Jan 31, 2020 at 9:53
-
2For the UUID you can use
getServiceUUID().toString().c_str()
, For the address you can use:getAddress().toString().c_str()
.Majenko– Majenko01/31/2020 09:54:38Commented Jan 31, 2020 at 9:54
lang-cpp