title: Unstable or slow communication between ESP8266 server and web browser client
body: <p>I am using an ESP8266 Thing Dev board configured as an access point and server to store data from temperature sensors.
  The goal is to access this data with an Android application, but for now, the client used is my computer running Chrome.</p>
  
  <p>The sensors provide new temperatures every 250 ms, which are added to a string (JSON formatted).
  When the client requests the data, the string is ended (closing JSON structure), and printed on the server.</p>
  
  <p>The client should be able to access up to 2*50 values at a time. However, each time a request is send, either only 2 or 4 values are printed, either the page is not working.</p>
  
  <p>My Arduino code, using ESP8266 and TMP102 libraries for arduino :</p>
  
  <pre><code>#include &lt;ESP8266WiFi.h&gt;
  #include &lt;Wire.h&gt;
  #include &lt;Ticker.h&gt;
  #include "tmp102.h"
  
  #define NB_MAX_TEMP 50
  #define MAX_INPUT 20
  
  const byte sensorAddress1 = 0x90;  // ADD0 -&gt; GND
  const byte sensorAddress2 = 0x92;  // ADD0 -&gt; V+
  tmp102 *thermometer1 = new tmp102(&amp;Wire);
  tmp102 *thermometer2 = new tmp102(&amp;Wire);
  
  // Timer
  Ticker ticker;
  bool flag = false;
  
  // Wifi
  const char WiFiAPPSK[] = "sparkfun"; // Wifi password
  WiFiServer server(80);
  
  int count = 0;
  String s;
  
  void setupWiFi()
  {
    WiFi.mode(WIFI_AP);
  
    // Do a little work to get a unique-ish name. Append the
    // last two bytes of the MAC (HEX'd) to "ThingDev-":
    uint8_t mac[WL_MAC_ADDR_LENGTH];
    WiFi.softAPmacAddress(mac);
    String macID = String(mac[WL_MAC_ADDR_LENGTH - 2], HEX) +
    String(mac[WL_MAC_ADDR_LENGTH - 1], HEX);
    macID.toUpperCase();
    String AP_NameString = "ThingDev-" + macID;
  
    char AP_NameChar[AP_NameString.length() + 1];
    memset(AP_NameChar, 0, AP_NameString.length() + 1);
  
    for (int i = 0; i &lt; AP_NameString.length(); i++)
    AP_NameChar[i] = AP_NameString.charAt(i);
  
    WiFi.softAP(AP_NameChar, WiFiAPPSK);
  }
  
  void timer_done()
  {
    flag = true;
  }
  
  void acquire()
  {
    int temp1 = 0, temp2 = 0;
    if (thermometer1-&gt;readTemp(temp1))
    {
      // If we're reading pins, print out those values:
      // first temp
      s += String(temp1 * 0.0625);
    }
    s += ",";
    if (thermometer2-&gt;readTemp(temp2))
    {
      // If we're reading pins, print out those values:
      // second temp
      s += String(temp2 * 0.0625);
    }
    return;
  }
  
  void setup()
  {
    Wire.begin(); // start the I2C library
    Serial.begin(115200);
    thermometer1-&gt;init(sensorAddress1);
    thermometer2-&gt;init(sensorAddress2);
  
    //Set default config.
    thermometer1-&gt;writeConf(TMP102_DEFAULT_CONF);
    thermometer2-&gt;writeConf(TMP102_DEFAULT_CONF);
  
    setupWiFi();
    server.begin();
  
    // timer every 0.25s
    ticker.attach(0.25, timer_done);
  }
  
  void loop()
  {
    // Check if a client has connected
    WiFiClient client = server.available();
    if (!client) {
      return;
    }
  
    if (flag) {
      flag = false;
  
      int temp1 = 0, temp2 = 0;
  
      if (count == 0) {
        // prepare string
        s = "HTTP/1.1 200 OK\r\n";
        s += "Content-Type: text/html\r\n\r\n";
        s += "{temp:[";
      }
      delay(1);
      // add a measurement
      s += "[";
      acquire();
      s += "],";
  
      count += 1;
      if (count == NB_MAX_TEMP) {
        // Prevent the string to become infinite
        count = 0;
        s = s.substring(0, s.length() - 1);
        s += "]};";
      }
    }
     if (client.available() &gt; 0) {
        // Read the first line of the request
        String req = client.readStringUntil('\r');
        client.flush();
        Serial.println(req);
  
        if (req.indexOf("/read") != -1) {
          // End the string
          s.setCharAt(s.length() - 1, '\0'); 
          s += "]};";
          client.print(s);
          Serial.println(s);
          count = 0;
        }
      }
      delay(1);
      Serial.println("Client disconnected");
  
      // The client will actually be disconnected
      // when the function returns and 'client' object is detroyed
  }
  </code></pre>
  
  <p>And a sample of what I get on the Serial console (the JSON string is the same I read on the server page) :</p>
  
  <pre><code>GET /read HTTP/1.1
  HTTP/1.1 200 OK
  Content-Type: text/html
  
  {temp:[[24.00,24.56],[24.00,24.56];
  Client disconnected
  GET /favicon.ico HTTP/1.1
  Client disconnected
  GET /read HTTP/1.1
  HTTP/1.1 200 OK
  Content-Type: text/html
  
  {temp:[[24.00,24.56];
  Client disconnected
  </code></pre>
  
  <p>What am I doing wrong ? Am I using a blocking function ? Are the /favicon.ico requests causing trouble ?</p>
  
  <p>For information, the access point part, and the sensor part of my code have been tested separately and work as expected.</p>
  
  <p>Thanks in advance.</p>