Problem with my RF24Network

Howdy ,

I got stuck with my project. I want to make a network of sensors, consisting of 5 transmitters and a master as receiver.
I manage to send the data from one transmitter to the master, but I fail to send from two transmitters, the second one appears in the serial monitor with 0 values, if I only transmit it, I manage to read it correctly.
Thank you

Transmiter code

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


Adafruit_AHTX0 aht;

RF24 radio(9, 10);
RF24Network network(radio);     
const uint16_t this_node = 01;   
const uint16_t master00 = 00;      

float voltage;
int bat_percentage;
int analogInPin  = A0;   
int sensorValue;
float calibration = 0.40; // Check Battery voltage using multimeter & add/subtract the value

short int IntervCitire  =   1  ;   //exprimat in Minute
unsigned long currentMillis = 0;
unsigned long previousMillis_readandsendTemperatura = 0;

typedef struct{
float E;
float F;
float G;
float H;
}
B_t;

B_t duino1;  


void setup() {
  Serial.begin(115200);
  pinMode(2, OUTPUT);
  digitalWrite(2, HIGH);
  radio.begin();
  radio.setDataRate(RF24_250KBPS);
  network.begin(92, this_node);  //(channel, node address)
  //radio.setPALevel(RF24_PA_MAX);

  if (! aht.begin()) {
    Serial.println("Could not find AHT? Check wiring");
    while (1) delay(10);
  }
  Serial.println("AHT10 or AHT20 found"); 
}



void loop()
{
  currentMillis = millis();
  if(( currentMillis - previousMillis_readandsendTemperatura ) > ( IntervCitire * 60000 )) {
    previousMillis_readandsendTemperatura = currentMillis;  
    readandsendTemperatura();
  }
}

void readandsendTemperatura()
{
  //radio.powerUp();
  sensors_event_t humidity, temp;
  aht.getEvent(&humidity, &temp);// populate temp and humidity objects with fresh data
  duino1.E = temp.temperature;
  duino1.F = humidity.relative_humidity;
  sensorValue = analogRead(analogInPin);
  voltage = (((sensorValue * 3.3) / 1024) * 2 + calibration); //multiply by two as voltage divider network is 100K & 100K Resistor

  bat_percentage = mapfloat(voltage, 2.8, 4.2, 0, 100); //2.8V as Battery Cut off Voltage & 4.2V as Maximum Voltage
  
  if (bat_percentage >= 100)
  {
    bat_percentage = 100;
  }
  if (bat_percentage <= 0)
  {
    bat_percentage = 1;
  }

  duino1.G = voltage;
  duino1.H = bat_percentage;

  RF24NetworkHeader header(master00);    // (Address where the data is going)
  bool ok = network.write(header, &duino1, sizeof(duino1)); // Send the data
  Serial.print("Temperature: "); Serial.print(duino1.E); Serial.println(" degrees C");
  Serial.print("Humidity: "); Serial.print(duino1.F); Serial.println("% rH");
  Serial.print("Analog Value = ");
  Serial.println(sensorValue);
  Serial.print("Output Voltage = ");
  Serial.println(voltage);
  Serial.print("Battery Percentage = ");
  Serial.println(bat_percentage);
  //radio.powerDown();
}

float mapfloat(float x, float in_min, float in_max, float out_min, float out_max)
{
  return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}

Receiver code


// Fill-in information from your Blynk Template here
#define BLYNK_TEMPLATE_ID "xxxxxx"
#define BLYNK_DEVICE_NAME "xxxxx"

#define BLYNK_FIRMWARE_VERSION        "xx"

#define BLYNK_PRINT Serial
//#define BLYNK_DEBUG

#define APP_DEBUG

// Uncomment your board, or configure a custom board in Settings.h
//#define USE_SPARKFUN_BLYNK_BOARD
//#define USE_NODE_MCU_BOARD
//#define USE_WITTY_CLOUD_BOARD
#define USE_WEMOS_D1_MINI

#include "BlynkEdgent.h"
#include <SPI.h>
#include <RF24Network.h>
#include <RF24.h>
#include <Wire.h>

BlynkTimer timer;

//float temp1;

#define D3 0  // SI
#define D0  16  // NO I2C Bus SCL (clock)

// Set the pins up
#define CE_PIN D3
#define CSN_PIN D0
RF24 radio(0, 16);
RF24Network network(radio);      // Include the radio in the network
const uint16_t this_node = 00;   // Address of our node in Octal format ( 04,031, etc)
const uint16_t node01 = 01;      // Address of the other node in Octal format
const uint16_t node02 = 02;
const uint16_t node03 = 03;
const uint16_t node04 = 04;
//BLYNK_CONNECTED() {
  //  Blynk.syncAll();
//}

typedef struct{
  float A;
  float B;
  float C;
  float D;
  float E;
  float F;
  float G;
  float H;
}
A_t;

A_t duino1; 


void setup()
{
Serial.begin(9600);
  radio.begin();
  radio.setDataRate(RF24_250KBPS);
  network.begin(92, this_node); //(channel, node address)
  BlynkEdgent.begin();
  //timer.setInterval(6000, checkNetwork);
}

void loop() {
  
  BlynkEdgent.run();
  timer.run();
  checkNetwork();
}

void checkNetwork()
{    network.update();
  while ( network.available() ) {     // Is there any incoming data?
    RF24NetworkHeader header;
    uint16_t msg_size = network.peek(header);
    float incomingData;
    network.read(header, &duino1, sizeof(duino1)); // Read the incoming data
    //network.read(01, &duino2, sizeof(duino2));
      if (header.from_node == 03) {    // If data comes from Node 02
  //network.read(header, &duino1, sizeof(duino1)); 
  Blynk.virtualWrite(2, duino1.A);
  Blynk.virtualWrite(8, duino1.B);
  Blynk.virtualWrite(6, duino1.C);
  Blynk.virtualWrite(7, duino1.D);
  Serial.print("duino1.A = ");
  Serial.println(duino1.A);
  Serial.print("duino1.B = ");
  Serial.println(duino1.B);
  Serial.print("duino1.C = ");
  Serial.println(duino1.C);
  Serial.print("duino1.D = ");
  Serial.println(duino1.D);
    }
    if (header.from_node == 01) {    // If data comes from Node 012
  //network.read(header, &duino2, sizeof(duino2));
  Blynk.virtualWrite(1, duino1.E);
  Blynk.virtualWrite(3, duino1.F);
  Blynk.virtualWrite(4, duino1.G);
  Blynk.virtualWrite(5, duino1.H);
  Serial.print("duino1.temp1 = ");
  Serial.println(duino1.E);
  Serial.print("duino1.umid1 = ");
  Serial.println(duino1.F);
  Serial.print("duino1.volt1 = ");
  Serial.println(duino1.G);
  Serial.print("duino1.batPercent1 = ");
  Serial.println(duino1.H);
    }
  }

}

The code for the first transmitter is the same as the second, only the part below and the node number are different

typedef struct{
  float A;
  float B;
  float C;
  float D;
}
A_t;

A_t duino1; 

What is your scheme to keep more than one transmitter from transmitting at the same time?

I haven't thought about it yet. but even if the first transmitter from which the data is correct does not transmit, from the second the readings still show 0.

What is different about the second transmitter? If nothing, are you confident that it is not broken?

Have you verified that each transmitter taken alone works with the receiver?

As I said above, I tested each of them individually, they work, I think the problem is in my code, I can't get readings from more than one sensor...

Answer post # 2, please.

I don't know how I could make it not receive two messages at once, just set one transmitter to send once every 4 minutes and the second one every 5 minutes.

The end result of that is NO messages received.

What cam i do , then?

Look into having your master unit "poll" each of the remote units, asking each if they have a message to send. If they do have a message ready to send, the send it. After the master unit has processed that message, ask the next remote unit, (poll) if it has a message, and so on, for all the remote units. Then start over again with the first.

Do You have an exemple of sketch ?

No. My last networking program was for an Apple IIe and written in 6502 assembly language.
Welcome to networking. Begin by making a diagram showing all the pieces of your network and giving each remote device an address, ie, a number or a letter.

Then design your message text format that includes the device address. Then expand your message definitions to include a message that asks the remote for a message. Another message format will be a response from the remote saying "no" it does not have a message. Another message format will be a response from the remote with the data.

Only when the design part is done can you begin to write programs to accomplish what you want.

Maybe useful:
nRF24l01 multiple transmitters to one receiver - Using Arduino / Networking, Protocols, and Devices - Arduino Forum

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.