My aim and task is creation BLE device list, show it at the TFT, choose one to connect by MAC-address.
Main part preparation is:
#define SCAN_TIME 10 // seconds
std::stringstream ss;
BLEScan* pBLEScan = BLEDevice::getScan(); //create new scan
pBLEScan->setAdvertisedDeviceCallbacks(new MyAdvertisedDeviceCallbacks());
pBLEScan->setActiveScan(true); //active scan uses more power, but get results faster
pBLEScan->setInterval(0x50);
pBLEScan->setWindow(0x30);
BLEScanResults foundDevices = pBLEScan->start(SCAN_TIME);
int count = foundDevices.getCount();
for (int i = 0; i < count; i++) {
BLEAdvertisedDevice d = foundDevices.getDevice(i);
BLEAdvertisedDevice d = foundDevices.getDevice(i);
ss << d.getAddress().toString() << ";" << d.getRSSI() << "\n";
}
const char* out = ss.str().c_str();
Than I do this:
Serial.printf("out = %s\n\n",out);
if ( out[0] == 'a' ) {
Serial.printf("c=%c\n",out[0]);
Serial.printf("c=%c\n",out[1]);
Serial.printf("c=%c\n",out[2]);
}
And it shows correctly:
out = a4:c1:38:4f:cb:0c;-47
c=a
c=4
c=:
But if I do this:
out2=String(out);
Serial.printf("out2 = %s\n",out2);
I give strange unicode symbols
out2 = ?
The same result if I change to:
Serial.printf("out2 = %c\n",out2);
The question is how can I get for example array of mac-addresses with normally String variables without strange behaviour. I already three day try many methods with no success.