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
#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