I am trying to open the webpage in ESP8266 via Arduino Mega. I have successfully opened the webpage if I use the AT command in the Serial Monitor

The output is perfect

+IPD,382:HTTP/1.1 200 OK
Server: nginx
Date: Sun, 08 May 2016 06:44:47 GMT
Content-Type: text/html
Connection: close
Vary: Accept-Encoding
X-Powered-By: PHP/5.5.26
Set-Cookie: PHPSESSID=rnsmo0b4kq07c5mi3mdsu280g4; path=/
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache


As you can see the output is fine. Now If I issue commands using Arduino Serial1.print() and read the output using following code:

 while( Serial1.available() )
     inChar = Serial1.read();
     //delay(1);         //could play around with this value if buffer overflows are occuring    
 } // while

The output skips character randomly

+IPD,386:HTTP/1.1 200 OK
Server: nginx
Date: Tue, 17 May wed-y: HP/.5.26
SetCooie:PHPESSD=7kameos5kd7aqcn4e54; pth=
Epirs: hu, 19Nov198 0852:0 GT
ach-Cotro: n-stre,no-ach, mst-evaidate,pos-chck=, pe-ceck0
raga: o-cche

I have tried different values of delay() but of no help. My baudrate is 9600 for both arduino Serial and ESP8266 Serial1

Can you please tell me what can be the reason. Thanks

  • Can you share with us the At commands to access a web page ?
    – The Zack
    Dec 21 '18 at 13:43

First things first: never use a delay when reading from serial.

You are just blindly trying to read data and send it out to another port. That's not going to work unless you know how much data you need to read.

And that information is handed to you on a plate - you just need to interpret it.

You are required to read the serial data as it comes in and decide what it means, then do different things depending on that data. For instance, when you read the characters +IPD you know you have an IP Data response to be interpreted. Just after that comes a comma, and following that a number. That number is how many bytes you then have to read to get your data. So you keep looking and reading until you have received all the data you should be receiving.

  • If you notice the output does contain END This is the flag that shows that entire response has been read. The problem is that data is being skipped in middle randomly. Cache-Control is read like ach-Cotro with skipped characters.
    – Sallu
    May 17 '16 at 9:29
  • My guess is it's something happening outside your while loop. That loop won't read the whole of the output - it will just read snippets as they become available, and other things in your program that may consume serial bytes are getting in the way. Follow my instructions and read the output properly.
    – Majenko
    May 17 '16 at 9:32
  • I changed the code like you said and it is working fine. I think Serial.print() is coming in way of reading Serial1.read() I first read output in array and then print and it shows fine.
    – Sallu
    May 17 '16 at 10:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.