nRF24 / RF24Network

OSI Layer 3 Networking for nRF24L01(+) and nRF52x on Arduino and Raspberry Pi
https://nrf24.github.io/RF24Network/
GNU General Public License v2.0
358 stars 163 forks source link

My esp32 cannot receive data in a RF24network #236

Closed 1D-geek closed 1 hour ago

1D-geek commented 1 hour ago

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

include

include

include

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

include

include

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

Important : 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

TMRh20 commented 1 hour ago

This is not a library issue, this is the same issue posted in the Arduino forums.

Please continue your inquiry there, this area is for reporting issues with the library.

1D-geek commented 1 hour ago

for the block I deleted it was:

`if (!radio.begin()) { // Check if radio initialization is successful
Serial.println(F("nRF24L01 failed to initialize! Check wiring or module."));
while (1); // Halt if the radio is not working

}`

My bad !