While starting programming my ESP8266 to get continuously changing data (car position) from a server, I encountered a problem: I can't get the ESP8266 to receive the data from the server more than 3 times/second.

The data rate would be preferably 15 times/second. The received data is a string of 47 elements.

#include <ESP8266WiFi.h>
#include <WiFiClient.h>

// WiFi information
const char WIFI_SSID[] = "my-wlan";
const char WIFI_PSK[] = "123qwe123qwe";

// Remote site information
const char http_site[] = "";
const int http_port = 8080;

// Pin definitions
const int LED_PIN = 16;

// Global variables
WiFiClient client;
String readString, readString1 ;
int x=0;
byte led_statuss = 0;
void setup() {

  // Set up serial console to read web page
  Serial.print("Thing GET Example");

  // Set up LED for debugging
  pinMode(LED_PIN, OUTPUT);

  // Connect to WiFi
void loop() {
  int time=millis();


    // If there are incoming bytes, print them

     int lines_received = 0;

      while(client.available()) {
      String line = client.readStringUntil('\n');
      if (lines_received == 7) { 
      String k =(line.substring(0,line.length())); // removes headers from the server response

      Serial.println(k); // prints the raw data
      int time1 = millis()-time;
      Serial.print("Time is ");
      Serial.println(time1); // shows how much time the function takes    


     // Do nothing
    //Serial.println("Finished Thing GET test");

// Attempt to connect toFi///////////////////////////////////////////////////////////
void connectWiFi() {

  byte led_status = 0;

  // Set WiFi mode to station (client)

  // Initiate connection with SSID and PSK
  WiFi.begin(WIFI_SSID, WIFI_PSK);

  // Blink LED while we wait for WiFi connection
  while ( WiFi.status() != WL_CONNECTED ) {
    digitalWrite(LED_PIN, led_status);
    led_status ^= 0x01;

  // Turn LED on when we are connected
  digitalWrite(LED_PIN, HIGH);

// Perform an HTTP GET request to a remote page//////////////////////////////////////////
bool getPage() {

  // Attempt to make a connection to the remote server
  if ( !client.connect(http_site, http_port) ) {
    return false;

  // Make an HTTP GET request
   //client.print("GET /cars" + "HTTP/1.1 \r\n" + "Host: " + "" + "\r\n" + "Connection: close\r\n\r\n");
  client.println("GET /cars HTTP/1.1");
  client.print("Host: ");
  client.println("Connection: Close");
  delay(100); //some put delay, but why and how long?
  return true;

We do a GET request from the server and we filter out the raw data from the headers and the responses are:

Thing GET Example1;62.91;43.55;190.03;5.59;20.00;44.26;861503022
Time is 228
Time is 926
Time is 1050
Time is 1011
Time is 992
Time is 1036
Time is 2020
Time is 222
Time is 1026
Time is 1108
Time is 219
Time is 214
Time is 996

It seems that the ESP can't get the GET responses faster. Time is in ms. I did manage to get it to work evenly if the delays are around 400 ms.

What would be the best way how to improve the speed of the procedure?

  • In your getPage function, what happens if you remove the delay or significantly decrease it? Commented Feb 7, 2017 at 14:57
  • 1
    In general, it doesn't improve the performance, just for some GET's it makes it faster, but then again you have 900, 1000ms delays. I tried to replicate a simple webserver on another ESP and a client on other ESP, and it worked great there. The responses were around 20-50ms. So i'm guessing it has to something with the network. Commented Feb 8, 2017 at 7:47
  • And the communication is done over the workplaces common wi-fi. Commented Feb 8, 2017 at 8:04
  • 2
    Do you really need to connect everytime you need a page? Can't you connect once and keep the connection, and reconnect in case the connection is lost or expired? Commented Feb 9, 2017 at 14:03
  • 2
    Do you have to use HTTP for this? It's incredibly inefficient for this use case, and not just because of the keep-alive problem.
    – Dan Hulme
    Commented Mar 3, 2017 at 13:46

1 Answer 1


You should avoid lenghtly connection resets on your getPage( ) method by using

Connection: Keep-Alive

instead of

Connection: Close

That may save quite a lot.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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