My esp32 cannot receive data in a RF24network

I have been working on a smart irrigation system project for a long time. For this I use soil moisture sensors for the data to receive and a nRF24l01 radio module for communication. And since I have several plants in my mini garden, I decided to use the RF24network. So I have a central node and several peripheral nodes. I tried it on my Arduino Uno and it worked successfully.

I later wanted to develop the project by adopting an esp-32 as a central node. To have weather data and more storage (when I need it).

This is where the problem comes. Indeed when I uploaded the code to my esp-32, I simply do not receive any data.

This is an esp-32S: Cdiscount

the radio module is the nRF24l01

And here is the receiver code (central node):

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

RF24 radio(25, 26);               // nRF24L01 (CE, CSN)
RF24Network network(radio);       // Include the radio in the network

const uint16_t node_bii = 00;     // Address of this node in octal format (00)
const uint16_t node1 = 01;        // Address of another node in octal format (01)
const uint16_t node2 = 011;       // Address of another node in octal format (012)

bool nafay = 0;

const unsigned long commandTimeout = 10000; // 10-second timeout to reset the state
unsigned long ltdecisionTime = 0;
float dataToReceive[3];  // Array to store humidity and temperature

void setup(void) {
 SPI.begin();
 Serial.begin(115200);
 
 while (!Serial) {
   // Some boards require this due to native USB capabilities
 }
 
 Serial.print(F("let's go"));

 radio.setChannel(90);
 network.begin(node_bii);
}

void loop(void) {

 network.update();
 unsigned long ltdecisionTime = 0;
 unsigned long montre = millis();

 //===== Receiving data =====//
 
 bool ok = 0;
 
 while (network.available()) { // Are there incoming data?
   RF24NetworkHeader header;
   ok = network.read(header, &dataToReceive, sizeof(dataToReceive)); // Read incoming data
   Serial.println("radio hears");
 }

 delay(500);

 // bool nice = 0;
 // RF24NetworkHeader header3(node1);
 // bool yeglee = network.write(header3, &nice, sizeof(nice)); // This data will be a character next time
 // Serial.println(yeglee ? F("The message has been sent.") : F("The message failed to send."));

 if (ok && dataToReceive[0] == node1 && dataToReceive[1] != 0 && montre - ltdecisionTime >= 2000) {
   ltdecisionTime = montre;
   Serial.print("The data comes from node: ");
   Serial.println(dataToReceive[0]);

   Serial.print("The soil humidity value is: ");
   Serial.print(dataToReceive[1]);
   Serial.println("%");

   RF24NetworkHeader header3(node1);

   if (dataToReceive[1] < 49) {
     bool natak = !nafay;
     bool tak = network.write(header3, &natak, sizeof(natak));
     Serial.println(natak ? F("The message has been sent.1<") : F("The message failed to send.1<"));
   } else if (dataToReceive[1] >= 60) {
     bool fay = network.write(header3, &nafay, sizeof(nafay));
     Serial.println(fay ? F("The message has been sent.1>") : F("The message failed to send.1>"));
   }
 }
 
 delay(500);

 // Check if no data has been received for the defined timeout period
 if (!ok && (montre - ltdecisionTime >= commandTimeout)) {
   ltdecisionTime = montre;
   Serial.println("data unavailable");
 }

 delay(20);
}```



And here is a transmitter code (coming from an Arduino UNO):


``` #include <RF24.h>

#include <RF24Network.h>

#include <SPI.h>

#define pompe 3

#define actualiser 2

RF24 radio(7, 8);

RF24Network network(radio);

const uint16_t nodebase = 00;

const uint16_t nodebii = 01;

const uint16_t node2 = 011; // Added another node

const uint16_t node3 = 03; // Added another node

bool seet = 0;

bool ndigueul = 0;

#define min 198

#define max 467

int htPin = A1;

int sensorValue = 0;

unsigned long int avgValue;

int hsvaleurmax = 85;

unsigned long ltUpdate = 0;

void setup() {

Serial.begin(115200);

SPI.begin();

pinMode(htPin, INPUT);

pinMode(pompe, OUTPUT);

while (!Serial) {

// Some boards require this due to native USB capabilities

}

Serial.println(F("Let's get started!"));

if (!radio.begin()) {

Serial.println(F("The radio module is not responding!"));

while (1) {

// Stuck in an infinite loop

}

}

radio.setChannel(90);

network.begin(nodebii);

}

void loop() {

network.update();

unsigned long montre = millis();

if (montre - ltUpdate >= 1500) {

ltUpdate = montre;

affichervhum(); // Display soil humidity value

sendhumsol(); // Send soil humidity data

do {

arroser(); // Watering process

} while (seet != 0 && ltUpdate >= 15000);

}

}

void affichervhum() {

sensorValue = analogRead(htPin);

float humsol = map(sensorValue, min, max, 100, 0);

Serial.println("Soil humidity value:");

Serial.print(humsol);

Serial.println("%");

}

void sendhumsol() {

sensorValue = analogRead(htPin);

float humsol = map(sensorValue, min, max, 100, 0);

float data[2] = {nodebii, humsol};

RF24NetworkHeader header(nodebase);

bool ok = network.write(header, &data, sizeof(data));

Serial.println(ok ? F("The message was sent.") : F("The message failed to send."));

}

void arroser() {

RF24NetworkHeader header;

Serial.print("Watering...");

while (network.available()) {

RF24NetworkHeader header;

seet = network.read(header, &ndigueul, sizeof(ndigueul));

}

Serial.print(ndigueul);

if (seet != 0) {

digitalWrite(pompe, LOW);

Serial.print("Executing value: ");

Serial.println(ndigueul);

digitalWrite(pompe, ndigueul == 0 ? LOW : HIGH);

delay(3000);

digitalWrite(pompe, LOW);

delay(500);

sensorValue = analogRead(htPin);

int humsol = map(sensorValue, 210, 510, 100, 0);

if (humsol > 75) {

digitalWrite(actualiser, HIGH);

delay(75);

digitalWrite(actualiser, LOW);

delay(75);

}

}

seet = 0;

}

void reinitialiser() {

seet = 0;

ndigueul = 0;

Serial.println("Data is unavailable! Stay calm.");

}```

Help me please it's been a week I'm here

If there is any other additional information to put to better enlighten me let me know please

I moved your topic to a more appropriate forum category @diaby03 .

The Nano ESP32 category you chose is only used for discussions directly related to the Arduino Nano ESP32 board.

In the future, please take the time to pick the forum category that best suits the subject of your question. There is an "About the _____ category" topic at the top of each category that explains its purpose.

Thanks in advance for your cooperation.

In the ESP32 code, you are not calling radio.begin() before calling radio.setChannel() and network.begin() and not checking the return value of radio.begin() to see if it is working properly.

Try that.

following on from post by @TMRh20 I find it is a good idea after radio.begin() to check if the SPI connection to the NRF24 is working, e.g.

void setup() {
  Serial.begin(115200);
  delay(1000);
  Serial.println("ESP32 > NRF24L01 Receive text");
  radio.begin();
  if (radio.isChipConnected())
    Serial.println("Receiver NF24 connected to SPI");
  else {
    Serial.println("NF24 is NOT connected to SPI");
    while (1)
      ;
  }
  radio.setChannel(125);

I forgot to say that my esp32 hates the '''while(1)''' . It starts to restart in a loop if I put it in the setup. Nevertheless I will try it without the '''while(1)'' '' and I will come back to you

My bad, I will see to it soon

1 Like

try calling yield() in the loop

{
    Serial.println("NF24 is NOT connected to SPI");
    while (1) yield() ;

sound as though the ESP32 is not connecting to the NRF24
the connections I use are

// ESP32 connections
// ESP32 SCK pin GPIO18 goes to NRF24L10_pin SCK
// ESP32 MISO pin GPIO19 goes to NRF24L10_pin MI
// ESP32 MOSI pin GPIO23 goes to NRF24L10_pin MO
// NRF24L10 CE to ESP32 pin GPIO4
// NRF24L10 CSN to ESP32 pin GPIO 5

I had already written a block of code like this

    Serial.println(F("nRF24L01 failed to initialize! Check wiring or module."));
    while (1); // Halt if the radio is not working
  }``` but it restarted the esp32 in a loop. So I deleted it

but this restarted the esp32 infinitely. So I deleted it

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