-->
Page 1 of 2

ESP unable to read long Strings returned by HTTP GET request

PostPosted: Sun May 17, 2015 5:57 pm
by nate4495
Hello ESP world! I am working on getting the ESP to send a GET request and get reply back from website. I have been able to send the request but the reply from the website is always truncated, so I cannot extract any information from the HTML reply. My code accesses google.com, then waits 5 seconds and prints the HTTP GET reply to the Serial Monitor, but it always ends up being cut short!!! :shock: Here is the part of my code that handles the GET and reply

Code: Select allString cmd2 = "AT+CIPSTART=\"TCP\",\"";  //make this command: AT+CIPSTART="TCP","107.180.3.137",80
  cmd2 += DST_IP;
  cmd2 += "\",80";
 
   altSerial.println(cmd2);  //send command to device
    delay(1000);
   
    if(altSerial.find("OK"))   {
      Serial.println("link good");
     String cmd="GET http://www.google.com HTTP/1.0\r\n\r\n";
     
      altSerial.print("AT+CIPSEND=");
altSerial.println(cmd.length());

if(altSerial.find(">"))  {
  //Serial.println(cmd.length());
  //Serial.print(cmd);
  delay(500);
  altSerial.print(cmd);
}
delay(5000);

  while(altSerial.available()) //get command line
  {   
    char c=altSerial.read();
    Serial.print(c);
  }
  Serial.println();


And here is some sample output to the Serial Monitor,
Code: Select allNetwork recognized!
resetting . . . . .ready to go
link good
 GET http://www.google.com HTTP/1.0


SEND OK

+IPD,1460:HTTP/1.1 200 OK
Da
resetting . . . . .ready to go
link good
 GET http://www.google.com HTTP/1.0


SEND OK

+IPD,1460:HTTP/1.1 200 OK
Da
resetting . . . . .ready to go


Any help appreciated I love this forum!~ :D

Re: ESP unable to read long Strings returned by HTTP GET req

PostPosted: Sun May 17, 2015 9:18 pm
by ricg
Without seeing the entire program my guess is that it could be dropping out of the while loop recving from the esp.
if your baud rate is 9600 the code will execute much faster than the chars can be sent. Even at 115200 this can happen.
current code:
while(altSerial.available()) //get command line
{
char c=altSerial.read();
Serial.print(c);
}
---------------------------------
replace with:
unsigned long t=millis()+500; // give the esp 500 mS to send the entire string
while( t > millis() )
while( altSerial.available())
Serial.print(altSerial.read());
---------------------------------------------------------

Re: ESP unable to read long Strings returned by HTTP GET req

PostPosted: Mon May 18, 2015 7:45 am
by nate4495
Thank you very much for the help! I tried your solution and it still had the same issue, but I found the problem! Oddly enough, it was my "delay(5000)" before I read the output. When I took that out, it started printing the entire HTTP response string :mrgreen: :ugeek:

Re: ESP unable to read long Strings returned by HTTP GET req

PostPosted: Tue May 19, 2015 11:10 pm
by ricg
yes, interesting that removing a delay would allow capturing all of the input. But i looked at the altserial code and it uses a circular 80 byte buffer to capture input. That could explain why the 5s delay would make it look like you were only getting part of your data. In other words all of the 1460 chars were recv'd by the arduino, but you would only see what the circular buffering algorithm could capture in it's 80 byte buffer. Interfacing with these modules has been a learning experience for me, often frustrating, but many times rewarding in unexpected ways. best to you.