A
A
Alexey Poloz2016-02-08 17:55:58
Arduino
Alexey Poloz, 2016-02-08 17:55:58

Arduino How to loop fetching a web page?

There is a working code for getting a web page from ESP8266, here:

#include <SoftwareSerial.h>
SoftwareSerial mySerial(10, 11);

void setup()
{
Serial.begin(9600);
mySerial.begin(9600);
mySerial.println("AT+RST");
mySerial.println("AT+GMR");
mySerial.println("AT+CWMODE_DEF=1");//_DEF
delay(50);
mySerial.println("AT+CWJAP_DEF=\"routerr\",\"1029384756\"");
delay(6000);
mySerial.println("AT+CIPSTART=\"TCP\",\"192.168.1.11\",80");
delay(50);
mySerial.println("AT+CIPSEND=43");
delay(50);
mySerial.println("GET / HTTP/1.1\r\nHost: 192.168.1.11\r\n\r\n\r\n\r\n");
//delay(5000);
//mySerial.println("AT+CIPCLOSE");
}

void loop()
{
if (Serial.available()) mySerial.write(Serial.read());
if (mySerial.available()) Serial.write(mySerial.read());
delay(10);
}

But here, the receipt occurs once, and it is necessary that this page come every second, when I push the functions of obtaining the page into the loop, some kind of nonsense occurs: either the receipt starts before connecting to the server, or the received information does not have time to be displayed, or simply is not displayed / not it turns out, in general, what to do to make the receiving happen all the time, I already tried to put the receiving code into a separate function and tried to loop directly in setup, apparently I don’t understand something in the order of the functions, in general, show an example code so that the receiving happens all the time

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
svd71, 2016-02-09
@svd71

It's all about processing speed and buffer sizes.
It is better to organize a ring buffer for uart reception with interrupt filling. In the main loop, only check the change of pointers in the buffer and immediately process the received characters.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question