Your new topic does not fit any of the above??? Check first. Then post here. Thanks.

Moderator: igrr

User avatar
By grhhm
#93168 Hello,

This guide provides pretty good explanation how to transmit popular data types over ESP-NOW, including String and 'char *'

The structure used:
Code: Select alltypedef 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 allmyData.d = "HelloHelloHello";
also transmit gibberish. The problem is in special treatment of strings of 11 bytes or less in class String.
2.
Code: Select allstrcpy(myData.a, temp.c_str());  // Transmits nothing
This was my bug in generating the variable. Fixed it.

Thanks!