How to set string in the structure part of NRF24?

Can anyone help me on how to correct my program ? I want to transmit value in string form.

I put this to TX code

struct payload_t
{

 String sensor1;
};

At the loop part I put this code

String sensor1 = (String(x) + "," + String(y) + "," + String(z)) ;
payload_t payload = {sensor[b][/b]1};

In the RX part I put this code

 struct payload_t
{

 String sensor1;
};

At the loop part

RF24NetworkHeader header;
payload_t payload;
network.read(header,&payload,sizeof(payload)); 

Serial.println("Sensor1 "); 

Serial.println(payload.sensor1);

Below is the Attach picture result of RX code.

You just can not send objects that contain pointers and hope to receive something useful. Strings contain pointers. Use char[] to transfer text.

hi whandall,

can you show what you mean ? If it's ok to you.

Thank you :)

You want to send three values somewhere. Obviously you control both sides of the communication. I see no reason to convert the values to a string and concatenate them for transmission, unless the receiving side only uses the information for display. If you want to use the values as values, its better not to convert them, because you don't have to parse them.

Avoid Strings wherever possible, use char[]. An example for packing different things in a payload

struct Payload {
  byte PWM;
  int credits;
  float uselessFloatVal;
  char tag[9];
} pack;

  pack.PWM = 234;
  pack.credits = 1000;
  pack.uselessFloatVal = PI;
  strncpy(pack.tag, "URGENT", sizeof(pack.tag));

strncpy()