Arduino to esp8266 multiple data send in nrf24l01

hello, i am amila udayanga..

I need to send data from two arduino boards to one esp8266 board.Data comes when an arduino board is used as a receiver. But when esp8266 is used as receiver, no data can be seen in the serial monitor. When I use one transceiver and send "hello world", the data comes into the esp 8266. please help me ..

arduino tranceiver code

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

const uint64_t pipes[2] = {0xE8E8F0F0E1LL,0xE8E8F0F0E2LL};
#define DHTPIN 4
#define DHTTYPE DHT11 
DHT dht(DHTPIN, DHTTYPE);
RF24 radio(7, 8); //  CN and CSN  pins of nrf
int sensorPin = A0; //soil moister pin
 
struct sensor {
 int hum;// humidity
  byte tem;// tempereture
  byte soil;// soil moisture
  byte sensorNum;
  
  //byte y; //soil moisture
};
sensor amila;
void setup()
{
  Serial.begin(115200); 
  dht.begin();
  radio.begin();
  radio.setAutoAck(false);
  radio.setDataRate(RF24_250KBPS);
  radio.openWritingPipe(pipes[1]);
  amila.sensorNum=1; 
}
void loop()
{
  delay(1000);
  amila.hum = dht.readHumidity();
  amila.tem = dht.readTemperature();
  amila.soil = analogRead(sensorPin);
//  data1.h1 = 90;
//  data1.t1 = 30;

  if (isnan(amila.hum) || isnan(amila.tem)){
   Serial.println(F("Failed to read from DHT sensor!"));
   return;

    
  }
  Serial.print("Humidity: ");
  Serial.print(amila.hum);
  Serial.println("Temperature: ");
  Serial.print(amila.tem);
  Serial.println("moisture");
  Serial.print(amila.soil);
 
 
  radio.write(&amila, sizeof(amila));
  delay(1000);
}

tranceiver 2 arduino uno

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

const uint64_t pipes[2] = {0xE8E8F0F0E1LL,0xE8E8F0F0E2LL};
#define DHTPIN 4
#define DHTTYPE DHT11 
 DHT dht(DHTPIN, DHTTYPE);
RF24 radio(7, 8); //  CN and CSN  pins of nrf
int sensorPin = A0; //soil moister pin
 
struct sensor {
  byte hum;// humidity
  byte tem;// tempereture
  byte soil;//soil moisture
  byte sensorNum;
  
  
  //byte y; //soil moisture
};
sensor hirusha;
void setup()
{
  Serial.begin(115200); 
  dht.begin();
  radio.begin();
  radio.setAutoAck(false);
  radio.setDataRate(RF24_250KBPS);
  radio.openWritingPipe(pipes[1]);
  hirusha.sensorNum=2; 
}
void loop()
{
  delay(1000);
  hirusha.hum = dht.readHumidity();
  hirusha.tem = dht.readTemperature();
  hirusha.soil = analogRead(sensorPin);
//  data1.h1 = 90;
//  data1.t1 = 30;

  if (isnan(hirusha.hum) || isnan(hirusha.tem)){
   Serial.println(F("Failed to read from DHT sensor!"));
   return;

    
  }
  Serial.print("Humidity: ");
  Serial.print(hirusha.hum);
  Serial.println("Temperature: ");
  Serial.print(hirusha.tem);
  Serial.println("moisture");
  Serial.print(hirusha.soil);
 
 
  radio.write(&hirusha, sizeof(hirusha));
  delay(1000);
}

receiver arduino uno/esp8266 (esp8266 not working)

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
//#include <SoftwareSerial.h>// for serial communication
//SoftwareSerial espSerial(18, 19);//for serial..

String str1; //for serial ..
String str2; //for serial ..

const uint64_t pipes[2] ={0xE8E8F0F0E1LL,0xE8E8F0F0E2LL};
RF24 radio(7, 8);
struct sensor {
  int hum; 
  int tem;
  int soil;
  int sensorNum;
  //byte y;
};
sensor sensorData;
void setup()
{
  Serial.begin(115200);
  espSerial.begin(115200); //for serial..  
  radio.begin(); 
  radio.setAutoAck(false);
  radio.setDataRate(RF24_250KBPS);
  radio.openReadingPipe(1, pipes[1]);
  radio.openReadingPipe(2, pipes[2]);
  radio.startListening();

  
//   Serial.print(".......Amila udayanga .....\n");
//   Serial.println(".....smart irrigation system.....\n\n\n");

}
//void recvData()
//{
//  if ( radio.available() ){ 
//    radio.read(&data1, sizeof(MyData1)); 
//    delay(500);
//     radio.read(&data2, sizeof(MyData2));
//  
//}
//}
void loop()
{
  if ( radio.available() )
  {
   radio.read(&sensorData, sizeof(sensorData)); 
   disp_sensor_data();
   radio.read(&sensorData, sizeof(sensorData)); 
  disp_sensor_data();
   radio.read(&sensorData, sizeof(sensorData)); 
  disp_sensor_data();
   radio.read(&sensorData, sizeof(sensorData)); 
  disp_sensor_data();
  }
}
  void disp_sensor_data()
 {
    if(sensorData.sensorNum == 1)
  {
   Serial.print("NODE 1 \n"); 
   Serial.print("HUMIDITY SENSOR 1:");
   Serial.println(sensorData.hum);
   Serial.print("TEMPERATURE 1:");
   Serial.println(sensorData.tem);
   Serial.print("soil moisture 1:");
   Serial.println(sensorData.soil);
   

  }

  
     if(sensorData.sensorNum == 2)
  {
    
    Serial.print("NODE 2  !!!!!\n");
    Serial.print("HUMIDITY SENSOR 2: ");
    Serial.println(sensorData.hum);
    Serial.print("TEMPERATURE SENSOR 2: ");
    Serial.println(sensorData.tem);
     Serial.print("soil moisture 2:");
    Serial.println(sensorData.soil);
    Serial.print("\n\n");
    

  }
  
  }   

Why do you switch the ACK off?

Why do you use a deprecated method for the pipe addresses?

Why do you use three different structures to represent a packet?

AVR Arduinos pack structs, ESP does not,
ints on an ESP have a different size than on ESPs.

If a packet is available, read four of them. Not so clever.

1 Like

I tried using only one but failed.

I tried to help, but failed.

1 Like

Had success using an arduino uno instead of the esp8266.

I want to replace arduino receiver to esp8266. uno is working but nodemcu is not working

To keep it simple, define one struct for data in this mixed 8bit/32bit environment. Use it consistently in all sketches.
It may be a bit wasteful but solves any byte boundary and data type representation problems and you have enough room for it because it is still under the 32 byte limit.

struct sensor {
  uint32_t hum; // humidity
  uint32_t tem; // tempereture
  uint32_t soil; // soil moisture
  uint32_t sensorNum;
};
2 Likes

It was successful ..bro very thank ..

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