Post topics, source code that relate to the Arduino Platform

User avatar
By yutonet
#26190 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
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 allString 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);
}
User avatar
By yutonet
#26599 Actually it doesn't really do the request when i change the code as you quoted. I used to be able to get the request work (it changes the string accordingly) now it doesn't really finish sending the request i guess since the text doesn't change on the server side.

So i get a full string when i use a serial adapter, but through arduino i get half of the feedback messages.

So this is what i get through arduino:
AT+CIFSR


+CIFSR:STAIP,"192.168.1.22"
+CIFSR:STAMAC,"18:fe:34:fb


And when i get through the serial adapter:
AT+CIFSR

+CIFSR:STAIP,"192.168.1.20"
+CIFSR:STAMAC,"18:fe:34:fb:24:e9"

OK


the thing is my arduino keeps listening to the serial ports repeatedly, so if the listening process would be too fast, device would still be able to read the rest of the text in the next cycle.

I also added this to my code to increase the buffer but it didn't work:
Code: Select all#define _SS_MAX_RX_BUFF 128


What am i missing?