ESP Response data is not complete on Arduino
Posted: Sun Aug 16, 2015 12:29 pm
Hey there, I'm trying to connect an ESP8266-1 module to my Arduino Uno using software serial to be able to use hardware serial for debugging.
My ESP works at 9600 baud, commands seem to work on it, i get responses etc. But when it comes to long responses like CIPSTART or GET commands, I get only the half of the data coming from the device.
It's like
Or like
I've tried changing the baud rate, I also tried using the hardware serial (debugging through software serial & a usb serial adapter. Still no luck.
So here's my code, I'd really appreciate some help (I translated some of the function names to English to make them more obvious, there might be some typos though)
My ESP works at 9600 baud, commands seem to work on it, i get responses etc. But when it comes to long responses like CIPSTART or GET commands, I get only the half of the data coming from the device.
It's like
AT+CIPSTART="TCP","dev.somerandomwsite.com",80
busy p...
C
Or like
GET http://dev.somerandomwsite.com/esp.php?data=ardunden HTTP/1.
I've tried changing the baud rate, I also tried using the hardware serial (debugging through software serial & a usb serial adapter. Still no luck.
So here's my code, I'd really appreciate some help (I translated some of the function names to English to make them more obvious, there might be some typos though)
Code: Select all
String wifi_WebRequest(String URL) {
if(!wifi_Busy)
{
wifi_Busy= true;
String wifi_Response = "";
String wifi_Command = "";
wifi_CheckConnection();
if(wifi_Connected){
DEBUG.println("Going to get data from the internet..");
int Slash = URL.indexOf('/');
String Domain;
if(Slash>0){ Domain = URL.substring(0,Slash); }
else{ Domain = URL; }
String Path;
if(Slash>0){ Path = URL.substring(Slash); }
else{ Path = "/"; }
wifi_Command = "AT+CIPCLOSE";
ESP.println(wifi_Command);
wifi_Wait(true);
wifi_Response = wifi_Read();
DEBUG.println(wifi_Answer);
wifi_Command = "AT+CIPSTART=\"TCP\",\""+Domain+"\",80\r\n";
ESP.println(wifi_Command);
wifi_Wait(true);
wifi_Response = wifi_Read();
DEBUG.println("Cipstart cmd:\n"+wifi_Response);
wifi_Command = "GET http://"+ Domain + Path + " HTTP/1.0\r\n\r\n\r\n";
ESP.print("AT+CIPSEND=");
ESP.println(wifi_Command.length());
wifi_Wait(true);
wifi_Response = wifi_Read();
DEBUG.println("Cipsend cmd:\n"+wifi_Response);
ESP.println(wifi_Command);
delay(1000);
wifi_Wait(true);
wifi_Response = wifi_Oku();
DEBUG.println("Response:\n"+wifi_Response);
}
else{ "Get Error: Wifi not connected."; }
wifi_Busy = false;
}
else{ DEBUG.println("WiFi chip busy.."); }
}
void wifi_CheckConnection() {
ESP.println("AT+CWJAP?");
wifi_Wait(true);
if(ESP.find("No AP")){ wifi_Connected = false; }
}
String wifi_Read() {
String Serial_Text = "";
wifi_Timeout_Current = 0;
while(!ESP.available() > 0)
{
wifi_Timeout_Current = wifi_Timeout_Current +1;
if(wifi_Timeout_Current >= wifi_Timeout){ break; }
}
if(ESP.available() > 0)
{
char Serial_Char;
ReRead:
while(ESP.available() > 0){ Serial_Char = ESP.read(); Serial_Text +=Serial_Char; }
delay(100); if(ESP.available() > 0){ goto ReRead; }
}
else{ Serial_Text = "nO"; }
return Serial_Text;
}
void wifi_Wait(bool Debug) {
wifi_Timeout_Current = 0;
if(Debug){led_Output(true, true, true, 2);}
while (!ESP.available() > 0) {
if(Debug){led_Output(false, false, true, 0);}
delay(50);
wifi_Timeout_Current = wifi_Timeout_Current + 1;
if (wifi_Timeout_Current >= wifi_Timeout) { break; }
}
if(Debug){led_Output(true, true, true, 2);}
delay(100);
}