I want to send some AT commands to esp8266 using arduino and get the reply from serial monitor. this is the code:(the purpose of this code is to update a thingspeak channel)
#include<SoftwareSerial.h>
SoftwareSerial esp8266(3,2);
#define ID "user"
#define PASS "pass"
String apiKey = "apikey";
void setup() {
Serial.setTimeout(5000);
Serial.begin(9600);
esp8266.begin(9600);
// delay(1000);
String command6="AT+RST";
esp8266.println(command6);
if(esp8266.available())
{
while(esp8266.available())
{
char c=esp8266.read();
Serial.write(c);
}
}
delay(2000);
}
void loop() {
delay(2000);
String command="\nAT";
esp8266.println(command);
if(esp8266.available())
{
while(esp8266.available())
{
char c=esp8266.read();
Serial.write(c);
}
}
String cmd = "\nAT+CIPSTART=\"TCP\",\"";
cmd += "144.212.80.11"; // api.thingspeak.com
cmd += "\",80";
esp8266.println(cmd);
if(esp8266.available())
{
while(esp8266.available())
{
char c=esp8266.read();
Serial.write(c);
}
}
delay(3000);
String command3="\nAT+CIPSEND=200";
esp8266.println(command3);
if(esp8266.available())
{
while(esp8266.available())
{
char c=esp8266.read();
Serial.write(c);
}
}
delay(1000);
String getStr = "GET /update?api_key=";
getStr += apiKey;
getStr += "&field1=10";
esp8266.println(getStr);
esp8266.println("\r\r\r\r\r\r\r\r");
if(esp8266.available())
{
while(esp8266.available())
{
char c=esp8266.read();
Serial.write(c);
}
}
delay(15000);
}
user and pass are my wifi username and password. the problem is, the esp8266 responds "ok" to at commands but when it gets to the last parts, it gives me this:
A))-R¤%%JHÕ¨TUPZ="TCP","144.212.80.11",80
CONNECT
OK
ERROR
AT+CIPSEND=200
OK
> GET /update?api_key=apikey&field1=10
CAT
AT+CIPSTART="TCP","144.212.80.11",80
AT+CIPSEND=200
GET /update?api_key=apikey&field1=10
AT
AT+CIPSTART="TCP","144.212.80.11",80
busy s...
i have put a few delays inside the code but after it inserts the GET it gets back to the loop runs the program again with no delays and then esp8266 resets itself.