I want to run all AT commands through Arduino Code over the Serial Monitor,and want to fetch data using a Thingspeak Key.
My other AT commands execute well periodically as needed in void loop(), but whenever I place the " +IPD,<len>: " AT command into void loop(), the loop() function runs only once and stops.
Need help in fixing this problem. Reply as soon as you can.
My UNO Code is as follows :
#include <LiquidCrystal.h>
#include <SoftwareSerial.h>
// We'll use a software serial interface to connect to ESP8266
SoftwareSerial ESP8266 (8,9); //rx=8,connected to 9 of arduino. tx=9, connected to 8 of arduino
LiquidCrystal lcd(12,11,5,4,3,2);
String inData;
void setup()
{
Serial.begin(9600);
ESP8266.begin(9600);
lcd.begin(16,2);
delay(1000); // Let the module self-initialize
ESP8266.println("AT");
while(ESP8266.available())
Serial.write(ESP8266.read());
lcd.print("OK");
lcd.clear();
delay(1500);
lcd.setCursor(0,0);
ESP8266.println("AT+CWJAP?");
while(ESP8266.available())
delay(2000);
Serial.write(ESP8266.read());
}
void loop()
{
delay(2500);
ESP8266.println("AT+CIPSTART=\"TCP\",\"api.thingspeak.com\",80\r\n");
while(ESP8266.available())
delay(1500);
Serial.write(ESP8266.read());
delay(1000);
ESP8266.println("AT+CIPSEND=50\r\n");
while(ESP8266.available())
Serial.write(ESP8266.read());
delay(1500);
boolean b = Serial.find(">");
if(b)
{
String hostt = "GET /apps/thinghttp/send_request?api_key=689WYA85WW1VJSBA";
hostt += "\r\n";
hostt += "Host:api.thingspeak.com";
hostt += "\r\n\r\n\r\n\r\n\r\n\r\n";
ESP8266.println(hostt);
delay(3000);
}
ESP8266.print("+IPD,12:");
delay(1500);
String inData = ESP8266.readString();
Serial.write(ESP8266.read());
/*.....................Fetching Data Needed..................*/
int i = ':';
while (inData.charAt(i) != ':') // Character before required data starts.
i++;
inData = inData.substring(i);
int j = 0;
while (inData.charAt(j) != 'C') // Character after required data ends.
j++;
inData = inData.substring(0, j);
Serial.print(inData);
delay(3000);
delay(5000);
ESP8266.println("AT+CIPCLOSE\r\n");
while(ESP8266.available())
Serial.write(ESP8266.read());
delay(4000);
}