[SOLV] ESP-NOW: how to transmit String or 'char *' variable?
Posted: Sat Dec 25, 2021 1:44 pm
Hello,
This guide provides pretty good explanation how to transmit popular data types over ESP-NOW, including String and 'char *'
The structure used:
It works really well as in provided example:
However, attempt to transmit variable data fails. Examples:
I think my lack of C++ understanding blocks me to resolve the problem of transmission of variable string or bytearray.
Update:
1.
2.
Thanks!
This guide provides pretty good explanation how to transmit popular data types over ESP-NOW, including String and 'char *'
The structure used:
Code: Select all
typedef struct struct_message {
char a[32];
int b;
float c;
String d;
bool e;
} struct_message;
It works really well as in provided example:
Code: Select all
strcpy(myData.a, "THIS IS A CHAR");
myData.b = random(1,20);
myData.c = 1.2;
myData.d = "Hello";
myData.e = false;
However, attempt to transmit variable data fails. Examples:
Code: Select all
strcpy(myData.a, "THIS IS A CHAR");
myData.b = random(1,20);
myData.c = 1.2;
String temp = "Hello" + String(5);
myData.d = temp; // This transmits gibberish
myData.e = false;
Code: Select all
String temp = "Hello" + String(5);
strcpy(myData.a, temp.c_str()); // Transmits nothing
myData.b = random(1,20);
myData.c = 1.2;
myData.d = "Hello";
myData.e = false;
I think my lack of C++ understanding blocks me to resolve the problem of transmission of variable string or bytearray.
Update:
1.
Code: Select all
also transmit gibberish. The problem is in special treatment of strings of 11 bytes or less in class String.myData.d = "HelloHelloHello";
2.
Code: Select all
This was my bug in generating the variable. Fixed it.strcpy(myData.a, temp.c_str()); // Transmits nothing
Thanks!