Post topics, source code that relate to the Arduino Platform

User avatar
By peter-bos
#90880 Hi,

As a (former) Pascal user I have trouble with all those different string and char types in Arduino. For string manipulation I the String type since it reminds me most of Pascal strings :-). But in using ESP-Now I have to use the uint8_f type, ESP-Now uses that type for the esp_now_send and esp_now_receive functions, How do I send and receive a String (with a capitol S) with ESP-Now? Or in different words: how do I convert a String to uint8_t before sending and how do I convert it back to String after receiving?

Since the ESP8266 in this case goes into deep sleep (and thus restarts when waking up) after each message there will be no memory issues using String.

Peter
User avatar
By RichardS
#90883 You can use .c_str() method to convert to const char string, if it then needs to be uint_8 string you might need to cast it to (uint8_t*)

String s = "string";
uint8_t *buffer;
buffer = (uint8_t*)s.c_str();

RichardS