Arduino Forum

Using Arduino => Microcontrollers => Topic started by: v_o_i_d on Feb 11, 2019, 12:02 pm

Title: Trying to connect arduino with RF24 using ESP8266
Post by: v_o_i_d on Feb 11, 2019, 12:02 pm
Hi

I have been trying to push data into my API from Arduino UNO with ESP8266 but it's not happening. The device connects to WiFi but fails in performing the data push after acquiring from sensor node via the nRF24L01 module attached to the arduino. Please help!
Title: Re: Trying to connect arduino with RF24 using ESP8266
Post by: AWOL on Feb 11, 2019, 04:23 pm
Please provide details.
Title: Re: Trying to connect arduino with RF24 using ESP8266
Post by: v_o_i_d on Feb 12, 2019, 07:36 am
i am sending here the receiver node code that gets the sent data from a remote node via nRF24L01 module and updates the thingspeak API with the esp8266 module. Arduino Uno is the interface

Code: [Select]
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <Wire.h>
#include <printf.h>
#include <SoftwareSerial.h>

#define RX 10
#define TX 11 //for SoftwareSerial to communicate with the Tx and Rx of the WiFi module

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

const byte address[6] = "00001";

String AP = "*******";
String PASS = "******";

String API = "9O1EQOC9QR5LMSS9";
String HOST = "api.thingspeak.com";
String PORT = "80";
String field1 = "field1";

int countTrueCommand;
int countTimeCommand;
boolean found = false;

int data;

SoftwareSerial esp8266(RX, TX);

void setup() {
 Serial.begin(9600);
 Serial.println(F("This is the central receiving node"));

 esp8266.begin(115200);
 sendCommand("AT",5,"OK");
 sendCommand("AT+CWMODE=1",5,"OK");
 sendCommand("AT+CWJAP=\""+AP+"\",\""+PASS+"\"",20,"OK");
 countTrueCommand = 0;
   
 radio.begin();
 radio.openReadingPipe(0, address);  //setting the address at which we will receive the data
 radio.setPALevel(RF24_PA_MIN);  //can set this as minimum or maximum depending on the distance between the transmitter and the receiver
 radio.startListening(); //it sets the module to receiver mode
 Serial.print("Radio set for communication");
 radio.printDetails();
}

void loop() {
 if (radio.available())  //looking for the data
 {
   radio.read(&data, sizeof(data));  //reading the data
   sendCommand("AT+CWJAP?=0",5,"OK");
   String getData1 = "GET /update?api_key="+ API +"&"+ field1 +"="+String(data);
   Serial.print("data received: ");
   Serial.println(getData1);
   sendCommand("AT+CIPMUX=1",5,"OK");
   sendCommand("AT+CIPSTART=0,\"TCP\",\""+ HOST +"\","+ PORT,15,"OK");
   sendCommand("AT+CIPSEND=0," +String(getData1.length()+4),4,">");
 }
 delay(5);
}

void sendCommand(String command, int maxTime, char readReply[])
{
 Serial.print(countTrueCommand);
 Serial.print(". at command => ?");
 Serial.print(command);
 Serial.print(" ");
 Serial.print("inside sendCommand loop");
 while(countTimeCommand < (maxTime*1))
 {
   esp8266.println(command); //at+cipsend
   if(esp8266.find(readReply)) //ok
   {
     found = true;
     break;
   }
   countTimeCommand++;
 }
 if(found == true)
 {
   Serial.println("Found!");
   countTrueCommand++;
   countTimeCommand = 0;
 }
 if(found == false)
 {
   Serial.println("Fail");
   countTrueCommand = 0;
   countTimeCommand = 0;
 }
 delay(500);
 found = false;
}

The device fetches the senor node data, connects to internet but fails in responding to the TCP process.
This is the simpler version of what I am trying. I have to implement the same with pipes for simultaneous receiving by the receiver node. But that kept apart, this shows problem too
Title: Re: Trying to connect arduino with RF24 using ESP8266
Post by: Robin2 on Feb 13, 2019, 09:39 am
Have a look at this Simple nRF24L01+ Tutorial (http://forum.arduino.cc/index.php?topic=421081).

Wireless problems can be very difficult to debug so get the wireless part working on its own before you start adding any other features.

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

I have never tried to get an nRF24 to work with an ESP8266 but the idea of getting the nRF24 communication working in its simplest form still holds.

...R
Title: Re: Trying to connect arduino with RF24 using ESP8266
Post by: v_o_i_d on Feb 13, 2019, 11:19 am
Have a look at this Simple nRF24L01+ Tutorial (http://forum.arduino.cc/index.php?topic=421081).

...R
I tried the examples and they worked all fine with pipes even. when i worked with the esp8266 alone then too the device successfully communicates the API. the sketch below is working
Code: [Select]

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <Wire.h>
#include <printf.h>
#include <SoftwareSerial.h>

#define RX 10
#define TX 11 //for SoftwareSerial to communicate with the Tx and Rx of the WiFi module

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

const byte address[6] = "00001";

String AP = "*****";
String PASS = "******";

String API = "9O1EQOC9QR5LMSS9";
String HOST = "api.thingspeak.com";
String PORT = "80";
String field1 = "field1";

int countTrueCommand;
int countTimeCommand;
boolean found = false;

int data = 0;
int value = 1;

SoftwareSerial esp8266(RX, TX);

void setup() {
  Serial.begin(9600);
  Serial.println(F("This is the central receiving node"));

  esp8266.begin(115200);
  sendCommand("AT",5,"OK");
  sendCommand("AT+CWMODE=1",5,"OK");
  sendCommand("AT+CWJAP=\""+AP+"\",\""+PASS+"\"",20,"OK");
  countTrueCommand = 0;
   
//  radio.begin();
//  radio.openReadingPipe(0, address);  //setting the address at which we will receive the data
//  radio.setPALevel(RF24_PA_MAX);  //can set this as minimum or maximum depending on the distance between the transmitter and the receiver
//  radio.startListening(); //it sets the module to receiver mode
//  Serial.print("Radio set for communication");
//  radio.printDetails();
}

void loop() {
    String getData1 = "GET /update?api_key="+ API +"&"+ field1 +"="+String(data);
   
    Serial.println(getData1);
    switch (countTrueCommand)
    {
      case 0: {
        sendCommand("AT", 5,"OK");
        break;
      }
//      case 1: {
//        sendCommand("AT+RST", 10, "invalid");
//        break;
//      }
      case 1: {
        sendCommand("AT+CIPMUX=1",10,"OK");
        break;
      }
      case 2: {
        sendCommand("AT+CIPSTART=0,\"TCP\",\""+ HOST +"\","+ PORT,15,"OK");
        break;
      }
      case 3: {
        sendCommand("AT+CIPSEND=0," +String(getData1.length()+4),4,">");
        break;
      }
      case 4: {
        esp8266.println(getData1);
        delay(1500);
        countTrueCommand++;
        break;
      }
      case 5: {
        sendCommand("AT+CIPCLOSE=0",5,"OK");
        break;
      }
      case 6: {
        Serial.println(data);
        Serial.print(getData1);
        Serial.print(",");
        if (radio.available())
        {
          radio.read(&value, sizeof(value));
          data = value;
        }
        else{
          data = data;
        }
        countTrueCommand = 0;
        delay(10000);
        break;
      }
    }
  delay(2000);
}

void sendCommand(String command, int maxTime, char readReply[])
{
  Serial.print(countTrueCommand);
  Serial.print(". at command => ?");
  Serial.print(command);
  Serial.print(" ");
  //Serial.print("inside sendCommand loop");
  while(countTimeCommand < (maxTime*1))
  {
    esp8266.println(command); //at+cipsend
    if(esp8266.find(readReply)) //ok
    {
      found = true;
      break;
    }
    countTimeCommand++;
  }
  if(found == true)
  {
    Serial.println("Found!");
    countTrueCommand++;
    countTimeCommand = 0;
  }
  if(found == false)
  {
    Serial.println("Fail");
    countTrueCommand = 0;
    countTimeCommand = 0;
  }
  //delay(500);
  found = false;
}

 

But when I remove the comment lines from the setup function(i.e the radio setup) further WiFi action fail, failing to even reconnect with Access point