[Solved] R24network / nRF24L01: Received sensor data problem

I am at my wit's end - can someone please help me solve this problem:

I am trying to send two simple int values (moisture and battery)
via nRF24L01's from an Arduino Pro mini to a Wemos D1 mini
using TMRh20's RF24network library.

Test-integers 12 and 55 are hard-coded for testing. The receiver spits out

>>>stack>>>
ctx: cont
sp: 3ffffde0 end: 3fffffc0 offset: 01b0
3fffff90:  00000000 00000000 00000001 4020306d  
3fffffa0:  3fffdad0 00000000 3ffee438 402030fc  
3fffffb0:  feefeffe feefeffe 3ffe84f4 401004d1  
<<<stack<<<
H!⸮⸮1⸮D⸮NReceiving ....FS-Value = 1073669068 , Bat-Value = 1075843189
Receiving ....FS-Value = 1 , Bat-Value = 1075851373
Receiving ....FS-Value = 1 , Bat-Value = 1075851373
Receiving ....FS-Value = 1 , Bat-Value = 1075851373

The TX code seems to do its work and gets acknowledgement from the receiver:

edited to delete the data type ‚S‘ when sending<<<

#include <RF24Network.h>
#include <RF24.h>
#include <SPI.h>

RF24 radio(9, 10);                   // nRF24L01(+) pins on Arduino Pro mini

RF24Network network(radio);          // Network uses that radio

const uint16_t fs_sensor = 01;        // Address of our node in Octal format
const uint16_t hub = 00;              // Address of the other node in Octal format

const unsigned long interval = 2000;  //ms  // How often to send data
unsigned long last_sent;              // When did we last send?
unsigned long packets_sent;           // How many have we sent already

//unsigned int senValue;
//unsigned int batValue;

typedef struct payload {                      // Structure of payload
  unsigned int senValue = 12;
  unsigned int batValue = 55;
} data;

void setup(void)
{
  Serial.begin(115200);
  Serial.println("RF24Network Sensor TX");

  SPI.begin();
  radio.begin();
  radio.setPALevel(RF24_PA_MAX);
  radio.setAddressWidth(5);
  radio.setDataRate(RF24_250KBPS);
  radio.setCRCLength(RF24_CRC_16);
  network.begin(/*channel*/ 90, /*node address*/ fs_sensor);
}

void loop() {
  network.update();                          // Check the network regularly
  data snd_data;

  unsigned long now = millis();              // If it's time to send a message, send it!

  if ( now - last_sent >= interval  )
  {
    last_sent = now;
    Serial.print("Sending...senValue ");
    Serial.print (snd_data.senValue);
    Serial.print(" , batValue ");
    Serial.println (snd_data.batValue);
    RF24NetworkHeader header(/*to node*/ hub);                                  //edited
    bool ok = network.write(header, &snd_data, sizeof(unsigned int));
    if (ok)
      Serial.println("ok.");
    else
      Serial.println("failed.");
  }
}

Here is the receiver code:

edited to say ‚sizeof(rec_data)‘ in the while loop<<<

#include <SPI.h>
#include <RF24.h>
#include <RF24Network.h>

#define CE_PIN   4                            //= D2   rf pins on Wemos D1 mini
#define CSN_PIN 15                          //= D8
RF24 radio (CE_PIN, CSN_PIN);

RF24Network network(radio);               // Network uses that radio
const uint16_t hub = 00;                       // Address of this node in Octal format
const uint16_t fs_sensor = 01;              // Address of sensor node in Octal format

typedef struct payload {                         // Structure of payload
  unsigned int senValue;
  unsigned int batValue;
} data;

void setup()
{
  Serial.begin(9600);
  SPI.begin();
  radio.begin();
  radio.setPALevel(RF24_PA_MAX);
  radio.setAddressWidth(5);
  radio.setDataRate(RF24_250KBPS);
  radio.setCRCLength(RF24_CRC_16);
    
  network.begin(90, hub);
}

void loop(void) {

  network.update();                         // Check the network regularly

  while ( network.available() ); {          // Is there anything ready for us?
    yield();
    Serial.print("Receiving ....");
    data rec_data;
    RF24NetworkHeader header;               // If so, grab it and print it out
    network.read(header, &rec_data, sizeof(rec_data));  //edited 

    Serial.print("FS-Value = ");
    Serial.print(rec_data.senValue);
    Serial.print(" , Bat-Value = ");
    Serial.println(rec_data.batValue);
  }
}

I have double and triple checked wiring, looked at examples and .... no success.
The receiver either receives nothing (but acknowledges) or receives garbage or garbles the data.
What to do?

Thank you for looking at this.

Thomas

OK, I made progress.

First, there was a watchdog issue causing the ESP8266 to reset periodically (rst cause:2, boot mode:(3,6)).
Fixed that by inserting a yield() at the start of the while-loop in void loop.
The Wemos D1 mini apparently does not like to wait for longer processes to finish.

Second, I changed the test data I am sending from an unsigned int to a char.
Voilá, the receiver picks that up nicely.

So now my question is:

  • can I send data as int or byte or float and have the receiver "understand" those?
    (When I sent an unsigned int = 55 I received something like 1073669068)
  • or do I need to convert numbers to char's, send those and convert back to numbers?

Any advice is greatly appreciated.

Thomas

Those two micro controllers have a different architecture. I expect that the Wemos is 32 bit. Try making the unsigned int on the pro mini an unsigned long.

You, sir, made my day. And it is only 7:30 a.m. here. Thank you! It works. Onwards!

Have a great day - Thomas