0

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)) ;

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.enter image description here

Thanks in advance :)

2

Did you actually 'instantiate' the struct in the TX and construct sensor1 as payload.sensor1 = ...? Anyways, there's still a problem.

You are using String in your payload. The third argument to read is the maximum message length that can be stored in payload. In your read call, you passed the size of payload as MAX_LEN. You will receive incomplete payloads since the String object in the RX payload struct has no content in it yet and thus payload's size, which you passed as MAX_LEN, will be less than that of the actual payload that was transmitted. Just ditch the Strings and try:

TX:

int vals = {x, y, z};   // guessing they are ints

network.write(header, &vals, sizeof(vals));

RX:

int vals[3];
network.read(header, &vals, sizeof(vals));

Serial.print(vals[0]); Serial.print(',');
Serial.print(vals[1]); Serial.print(',');
Serial.println(vals[2]);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.