My program is running on ESP32. I'm retrieving some data from Bluetooth, and the Bluetooth string is a C string. I need to save that data in an RTC_DATA_ATTR String, which is a C++ string.
Just doing c++string = cstring.c_str();
won't work, since it will just save a pointer to the location in the memory of the C string, and the purpose is to save the data in the RTC memory, so the ESP32 can go to deep sleep without losing the data.
All other data than RTC gets wiped on deep sleep, so there would just be a pointer, pointing to nothing.
How do I get the data copied from the C string to the C++ string?
Any help would be appreciated. A bit of extra info: this is how it is set up at the moment:
RTC_DATA_ATTR String ssid;
BLECharacteristic *cSsid = NULL;
ssid = cSsid->getValue().c_str();
.c_str()
ofString
returns a constant pointer to the internal C string (zero terminated char array) of String which is in heap. but to save it to RTC memory something must copy it to the RTC memory. it is not neccessary to copy it into 'C string' in memory..c_str()
I believe this is also a c++ string) Because I don't know the library RTC_DATA_ATTR is from I can not say how to copy text into a string of that type. You should at least add the library name to the question or give us some information what that type is like.RTC_DATA_ATTR char ssid[33];
strcpy(ssid, cSsid->getValue().c_str());