-->
Page 1 of 1

Send a String with ESP-Now

PostPosted: Thu Mar 18, 2021 6:14 pm
by peter-bos
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

Re: Send a String with ESP-Now

PostPosted: Fri Mar 19, 2021 11:03 am
by RichardS
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