Received Data saves in wrong Variable

Hi, I need help to better understand why the data received on the Master Node00, using RF24L01 modules gets saved in the wrong variable. I am trying to read from Node03 all other nodes are off, however the data received gets assigned to Sensor01 and Sensor02 variable. Is my issue incorrect header assignment? The baud rate or timing of the writing vs read time? What can possibly be done to ensure the correct assignments are made? Thanks in advance for your assistance.

Node03.ino (1.39 KB)

Node00.ino (1.84 KB)

Hey mate, welcome to board.

You mind pasting your code into your post? You may paste it into
[ code ] tags so it is nice and tidy :slight_smile: Many of the users are on their mobile phones and cant download and open ino files :wink:

Have a great evening

Thanks.

Master Node00:

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

int sensorPin = A1;

int Sensor00 = 0;
float Sensor01= 0;
float Sensor02 = 0;
float Sensor03 = 0;
float Moist0 = 0;

RF24 radio(9, 10); // CE, CSN

RF24Network network(radio); // Include the radio in the network
const uint16_t this_node = 00; // Address of this node in Octal format ( 04,031, etc)
const uint16_t node1 = 01; // Address of the other node in Octal format
const uint16_t node2 = 02;
const uint16_t node3 = 03;

void setup() {
Serial.begin(9600);
radio.begin();
network.begin(90, this_node); //(channel, node address)
radio.setDataRate(RF24_2MBPS);

}
void loop()
{
network.update();
Sensor00 = analogRead(sensorPin);
Moist0 = map(Sensor00,300,1023,100,0);

if ( network.available() )
{ // Is there any incoming data?
RF24NetworkHeader header(node1,‘A’);

delay(2000);

network.read(header, &Sensor01, sizeof(Sensor01)); // Read the incoming data
Serial.print("node1 - ");

delay(1000);

Serial.println(Sensor01);

delay(2000);

RF24NetworkHeader header2 (node2);
network.read(header2, &Sensor02, sizeof(Sensor02)); // Read the incoming data

delay(1000);

Serial.print("node2 - ");
Serial.println(Sensor02);
delay(2000);

RF24NetworkHeader header3 (node3,‘C’);
network.read(header3, &Sensor03, sizeof(Sensor03)); // Read the incoming data

delay(1000);

Serial.print("node3 - ");
Serial.println(Sensor03);

delay(1000);

Serial.print("Master - ");
Serial.println(Sensor00);

delay(1000);

Serial.print("Map - ");
Serial.println(Moist0);

delay(1000);

}
}

Node03:

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

int Sensor03 =0;
float Moist3 =0;
float Moist5 = 0;
int sensorPin = A1;

RF24 radio(9, 10); // CE, CSN
RF24Network network(radio); // Include the radio in the network
const uint16_t this_node = 03; // Address of our node in Octal format ( 04,031, etc)
const uint16_t master00 = 00; // Address of the other node in Octal format
const uint16_t node5 = 013;

void setup()
{
Serial.begin(57600);
SPI.begin();
radio.begin();
network.begin(90, this_node); //(channel, node address)
radio.setDataRate(RF24_2MBPS);
}

void loop(){
network.update();
Sensor03 = analogRead(sensorPin);
Moist3 = map(Sensor03,250,1023,100,0);

if ( network.available() ) {

// Is there any incoming data?
RF24NetworkHeader header4(node5);//get data from node5
network.read(header4, &Moist5, sizeof(Moist5)); // Read the incoming data

}

RF24NetworkHeader header3(master00,‘C’); // (Address where the data is going)
network.write(header3, &Moist3, sizeof(Moist3)); // Send the data

Serial.print("My Data - ");
Serial.println(Moist3);

delay (500);

Serial.print("Node5 - ");
Serial.println(Moist5);

delay(5000);
}

like this:

Master Node00:

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

int sensorPin = A1;

int Sensor00 = 0;
float Sensor01 = 0;
float Sensor02 = 0;
float Sensor03 = 0;
float Moist0 = 0;

RF24 radio(9, 10); // CE, CSN

RF24Network network(radio);      // Include the radio in the network
const uint16_t this_node = 00;   // Address of this node in Octal format ( 04,031, etc)
const uint16_t node1 = 01;      // Address of the other node in Octal format
const uint16_t node2 = 02;
const uint16_t node3 = 03;

void setup() {
  Serial.begin(9600);
  radio.begin();
  network.begin(90, this_node);  //(channel, node address)
  radio.setDataRate(RF24_2MBPS);

}
void loop()
{
  network.update();
  Sensor00 = analogRead(sensorPin);
  Moist0 = map(Sensor00, 300, 1023, 100, 0);

  if ( network.available() )
  { // Is there any incoming data?
    RF24NetworkHeader header(node1, 'A');

    delay(2000);

    network.read(header, &Sensor01, sizeof(Sensor01)); // Read the incoming data
    Serial.print("node1 - ");

    delay(1000);

    Serial.println(Sensor01);

    delay(2000);

    RF24NetworkHeader header2 (node2);
    network.read(header2, &Sensor02, sizeof(Sensor02)); // Read the incoming data

    delay(1000);

    Serial.print("node2 - ");
    Serial.println(Sensor02);
    delay(2000);

    RF24NetworkHeader header3 (node3, 'C');
    network.read(header3, &Sensor03, sizeof(Sensor03)); // Read the incoming data

    delay(1000);

    Serial.print("node3 - ");
    Serial.println(Sensor03);

    delay(1000);

    Serial.print("Master - ");
    Serial.println(Sensor00);

    delay(1000);

    Serial.print("Map - ");
    Serial.println(Moist0);

    delay(1000);

  }
}
Node03:

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


int Sensor03 = 0;
float Moist3 = 0;
float Moist5 = 0;
int sensorPin = A1;

RF24 radio(9, 10); // CE, CSN
RF24Network network(radio);      // Include the radio in the network
const uint16_t this_node = 03;   // Address of our node in Octal format ( 04,031, etc)
const uint16_t master00 = 00;    // Address of the other node in Octal format
const uint16_t node5 = 013;

void setup()
{
  Serial.begin(57600);
  SPI.begin();
  radio.begin();
  network.begin(90, this_node); //(channel, node address)
  radio.setDataRate(RF24_2MBPS);
}

void loop() {
  network.update();
  Sensor03 = analogRead(sensorPin);
  Moist3 = map(Sensor03, 250, 1023, 100, 0);

  if ( network.available() )     {

    // Is there any incoming data?
    RF24NetworkHeader header4(node5);//get data from node5
    network.read(header4, &Moist5, sizeof(Moist5)); // Read the incoming data

  }

  RF24NetworkHeader header3(master00, 'C');   // (Address where the data is going)
  network.write(header3, &Moist3, sizeof(Moist3)); // Send the data

  Serial.print("My Data - ");
  Serial.println(Moist3);

  delay (500);

  Serial.print("Node5 - ");
  Serial.println(Moist5);

  delay(5000);
}

Okay, thank you.

@ranalbert, if all of your nRF24 modules are within range of the master you can probably get the project working more simply without using the network feature.

Have a look at this Simple nRF24L01+ Tutorial.

The examples are as simple as I could make them and they have worked for other Forum members. If you get stuck it will be easier to help with code that I am familiar with. Start by getting the first example to work

The Tutorial includes an example for a master and 2 slaves that can easily be extended to a larger number of slaves.

...R

Thank you very Much for you kind assistance and guidance. :slight_smile: