# ESP8266 HTTP Response Time, timeout

**URL:** <https://forum.arduino.cc/t/esp8266-http-response-time-timeout/622521>\
**Category:** Programming\
**Created:** [November 24, 2019, 9:18pm UTC](https://forum.arduino.cc/t/esp8266-http-response-time-timeout/622521 "2019-11-24T21:18:47Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![petrbroza](https://avatars.discourse-cdn.com/v4/letter/p/f08c70/32.png) [@petrbroza](https://forum.arduino.cc/u/petrbroza)\
**Post date:** [November 24, 2019, 9:18pm UTC](https://forum.arduino.cc/t/esp8266-http-response-time-timeout/622521/1 "2019-11-24T21:18:47Z")

</div>

Hi,

I'm trying to read out some data from heater, which share data on it's own webserver. I'm using example program HTTP basic client, from ESP8266 library. It's reading fine, but there is delay 5 second between reading. Delay is caused by _String payload = http.getString();_ function. I suspect there is something timing out. Any ideas? Thanks

ESP8266 NodeMcu V3 (china)

```cpp
#include <Arduino.h>

#include <ESP8266WiFi.h>
#include <ESP8266WiFiMulti.h>

#include <ESP8266HTTPClient.h>

#include <WiFiClient.h>

ESP8266WiFiMulti WiFiMulti;

void setup() {

  Serial.begin(115200);
  // Serial.setDebugOutput(true);

 

  WiFi.mode(WIFI_STA);
  WiFiMulti.addAP("Brozapetr", "");

}

void loop() {
  // wait for WiFi connection
  if ((WiFiMulti.run() == WL_CONNECTED)) {

    WiFiClient client;

    HTTPClient http;

    if (http.begin(client, "http://192.168.1.3/ext/daqdata.cgi?key=asdfas595ds")) {  // HTTP

      int httpCode = http.GET();

      if (httpCode > 0) {
        // HTTP header has been send and Server response header has been handled
        Serial.printf("[HTTP] GET... code: %d\n", httpCode);

        // file found at server
        if (httpCode == HTTP_CODE_OK || httpCode == HTTP_CODE_MOVED_PERMANENTLY) {
          [b]String payload = http.getString();[/b]
          Serial.println(payload);
        }
      } else {
        Serial.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str());
      }

      http.end();
    } else {
      Serial.printf("[HTTP} Unable to connect\n");
    }
  }

//  delay(10000);
}

```

Content of web page (plain text):

```cpp
["PLNE ZATIZENI",69.86,5.12,56,70.93,68.12,32.69,99,9.80,1,true,120.00,0,-20.00,0,-20.00,0,true,60.00,24.68,36.33,true,7.91,31.92,true,true,-9.00,-9.00,-20.00,true,-9.00,70.00,true,true,-9.00,-9.00,-20.00,true,-9.00,70.00,true," ",120.00,"NORMAL","VYPNUTO","VYPNUTO","VYPNUTO","VYPNUTO","VYPNUTO","VYPNUTO","VYPNUTO","VYPNUTO","VYPNUTO",1181724,2466,344,120.00,-20.00,-20.00,true,true,true,70.00,70.00,70.00,-20.00,-20.00,-20.00,-20.00,-20.00,-20.00,true,true,true]

```

---

<div class="post-metadata">

**Author:** ![pylon](https://avatars.discourse-cdn.com/v4/letter/p/59ef9b/32.png) [@pylon](https://forum.arduino.cc/u/pylon)\
**Post date:** [November 25, 2019, 6:08pm UTC](https://forum.arduino.cc/t/esp8266-http-response-time-timeout/622521/2 "2019-11-25T18:08:30Z")

</div>

Does the server send a content length header?

---

<div class="post-metadata">

**Author:** ![petrbroza](https://avatars.discourse-cdn.com/v4/letter/p/f08c70/32.png) [@petrbroza](https://forum.arduino.cc/u/petrbroza)\
**Post date:** [November 25, 2019, 6:29pm UTC](https://forum.arduino.cc/t/esp8266-http-response-time-timeout/622521/3 "2019-11-25T18:29:22Z")

</div>

Is this the right command to get header length?

_http.contentLength();_

or should I use

_http.collectHeaders();_

Thanks

> **[ESP8266 Arduino: Getting HTTP Response headers - techtutorialsx](https://techtutorialsx.com/2018/06/08/esp8266-arduino-getting-http-response-headers/)**
>
> In this post we are going to check how to obtain the headers of the response of an HTTP request, using the Arduino core on the ESP8266. The tests of this

---

<div class="post-metadata">

**Author:** ![pylon](https://avatars.discourse-cdn.com/v4/letter/p/59ef9b/32.png) [@pylon](https://forum.arduino.cc/u/pylon)\
**Post date:** [November 25, 2019, 7:07pm UTC](https://forum.arduino.cc/t/esp8266-http-response-time-timeout/622521/4 "2019-11-25T19:07:32Z")

</div>

Do a request manually (command line):

```cpp
telnet 192.168.1.3 80

```

then

```cpp
GET /ext/daqdata.cgi?key=asdfas595ds HTTP/1.0

```

End that line by hitting the return key twice. Post the result you get!

---

<div class="post-metadata">

**Author:** ![petrbroza](https://avatars.discourse-cdn.com/v4/letter/p/f08c70/32.png) [@petrbroza](https://forum.arduino.cc/u/petrbroza)\
**Post date:** [November 29, 2019, 10:22am UTC](https://forum.arduino.cc/t/esp8266-http-response-time-timeout/622521/5 "2019-11-29T10:22:34Z")

</div>

Here is the result

![telnet.JPG](https://europe1.discourse-cdn.com/arduino/original/4X/4/5/a/45a4546be758e4dd64303157dce9b8b5651a7dbc.jpeg)

![telnet.JPG](https://europe1.discourse-cdn.com/arduino/original/4X/4/5/a/45a4546be758e4dd64303157dce9b8b5651a7dbc.jpeg)

---

<div class="post-metadata">

**Author:** ![pylon](https://avatars.discourse-cdn.com/v4/letter/p/59ef9b/32.png) [@pylon](https://forum.arduino.cc/u/pylon)\
**Post date:** [November 29, 2019, 5:53pm UTC](https://forum.arduino.cc/t/esp8266-http-response-time-timeout/622521/6 "2019-11-29T17:53:51Z")

</div>

As I suspected the server doesn't provide a content-length header, so the ESP8266 code doesn't know when the end of the transfer is reached. So it waits for the timeout.  
The easiest way to solve your problem is to teach the server to send a correct content-length header and your delay will probably disappear immediately.  
The other way, to change the ESP8266 core library code to check for a closed connection without waiting for the timeout is much more work and I doubt that you're able to do it.

---

<div class="post-metadata">

**Author:** ![petrbroza](https://avatars.discourse-cdn.com/v4/letter/p/f08c70/32.png) [@petrbroza](https://forum.arduino.cc/u/petrbroza)\
**Post date:** [November 29, 2019, 7:07pm UTC](https://forum.arduino.cc/t/esp8266-http-response-time-timeout/622521/7 "2019-11-29T19:07:32Z")

</div>

Thanks for advice.

As this is 3rd party device, I can't change behavior of that webserver. What I read online, it's good practice to add content-length to header, right?

Page content (size) is always the same, just values are changing, could I specify content-length manually from Arduino?

---

<div class="post-metadata">

**Author:** ![pylon](https://avatars.discourse-cdn.com/v4/letter/p/59ef9b/32.png) [@pylon](https://forum.arduino.cc/u/pylon)\
**Post date:** [December 2, 2019, 6:22pm UTC](https://forum.arduino.cc/t/esp8266-http-response-time-timeout/622521/8 "2019-12-02T18:22:55Z")

</div>

> Page content (size) is always the same, just values are changing, could I specify content-length manually from Arduino?

No, at least not easily. But you can just not use the http.getString() call and use low level calls instead, like this code:

```arduino
uint16_t size = 64; // replaces content-length value
uint8_t * buff = (uint8_t *) malloc(size);
int bytesRead = http.getStream().eadBytes(buff, size);

```

---

<div class="post-metadata">

**Author:** ![petrbroza](https://avatars.discourse-cdn.com/v4/letter/p/f08c70/32.png) [@petrbroza](https://forum.arduino.cc/u/petrbroza)\
**Post date:** [December 2, 2019, 7:46pm UTC](https://forum.arduino.cc/t/esp8266-http-response-time-timeout/622521/9 "2019-12-02T19:46:52Z")

</div>

Alright it's little too complex for me. I can't see, where incoming data are being stored, as bytesRead is just integer.

I think you got typo in code:

int bytesRead = http.getStream(). **r** eadBytes(buff, size);

---

<div class="post-metadata">

**Author:** ![petrbroza](https://avatars.discourse-cdn.com/v4/letter/p/f08c70/32.png) [@petrbroza](https://forum.arduino.cc/u/petrbroza)\
**Post date:** [December 2, 2019, 8:38pm UTC](https://forum.arduino.cc/t/esp8266-http-response-time-timeout/622521/10 "2019-12-02T20:38:56Z")

</div>

I was able to parse the stream with help of this tutorial: [https://www.instructables.com/id/ESP8266-Parsing-JSON/](https://www.instructables.com/id/ESP8266-Parsing-JSON/)

just instead of  
JsonObject& root = jsonBuffer.parseObject(http.getString());  
use:  
JsonObject& root = jsonBuffer.parseObject(http.getStream());

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [May 6, 2021, 12:09am UTC](https://forum.arduino.cc/t/esp8266-http-response-time-timeout/622521/11 "2021-05-06T00:09:11Z")

</div>


