- Thu Feb 18, 2016 3:14 am
#41340
Hi volthaus,
I expereince some problems with the webserver, sometimes a request from the browser is intterupted during send out data with :er -8
I tried your sketch, modified it to stream out a table with data and was very happy to see that about 200 requests were processed correctly. BUT at about 350 request the same error appeared
here is the modified code:
Code: Select all/*********
Rui Santos
Complete project details at http://randomnerdtutorials.com
*********/
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>
MDNSResponder mdns;
// needed to avoid link error on ram check
extern "C"
{
#include "user_interface.h"
}
// Replace with your network credentials
const char* ssid = "SSID";
const char* password = "PASSWORD";
unsigned long ulReqcount; // how often has a valid page been requested
ESP8266WebServer server(80);
String webPage = "";
const char* createTable()
{
ulReqcount++;
webPage = F("<!DOCTYPE HTML>");
webPage += F("\r\n<html>\r\n<head>\r\n<meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\">");
webPage += F("\r\n\t<meta http-equiv=\"refresh\" content=\"2; url=/\">");
webPage += F("\r\n\t<style>");
webPage += F("\r\n\t\tbody {background-color: #dfdfdf;}");
webPage += F("\r\n\t\tfont {color: #000000;}");
webPage += F("\r\n\t\ttable {font-size: large; width:100%;}");
webPage += F("\r\n\t\ttable, th, td {border: 2px solid black; border-collapse: collapse;}");
webPage += F("\r\n\t\tth, td {padding: 5px;}");
webPage += F("\r\n\t\tth {text-align: left;}");
webPage += F("\r\n\t</style>\r\n<title>Test</title>\r\n</head>\r\n<body>");
webPage += F("\r\n<h1>Testdata</h1>");
webPage += F("\r\n<table>");
webPage += F("\r\n\t<tbody><tr><th>#</th><th>Time</th><th>Calibration used</th><th>Sesnor 1</th><th>Sensor2</th></tr>");
webPage += F("\r\n\t<tr><td>1</td><td>04.02.2016 09:40:12</td><td>Standard</td><td>25,12</td><td>10,60</td></tr>");
webPage += F("\r\n\t<tr><td>1</td><td>04.02.2016 09:40:14</td><td>Standard</td><td>25,14</td><td>10,67</td></tr>");
webPage += F("\r\n\t<tr><td>1</td><td>04.02.2016 09:40:16</td><td>Standard</td><td>25,09</td><td>10,58</td></tr>");
webPage += F("\r\n\t<tr><td>1</td><td>04.02.2016 09:40:18</td><td>Standard</td><td>25,11</td><td>10,62</td></tr>");
webPage += F("\r\n\t<tr><td>1</td><td>04.02.2016 09:40:20</td><td>Standard</td><td>25,12</td><td>10,61</td></tr>");
webPage += F("\r\n\t<tr><td>1</td><td>04.02.2016 09:40:22</td><td>Standard</td><td>25,15</td><td>10,70</td></tr>");
webPage += F("\r\n\t<tr><td>1</td><td>04.02.2016 09:40:24</td><td>Standard</td><td>25,10</td><td>10,63</td></tr>");
webPage += F("\r\n\t<tr><td>1</td><td>04.02.2016 09:40:26</td><td>Standard</td><td>25,13</td><td>10,67</td></tr>");
webPage += F("\r\n</tbody></table>");
webPage += F("\r\n<div style=\"font-size:x-small\">");
webPage += F("\r\n\t<BR>requests: ");
webPage += ulReqcount;
webPage += F("\r\n\t<BR>free RAM: ");
webPage += (uint32_t)system_get_free_heap_size();
webPage += F("\r\n</div>\r\n</body>\r\n</html>");
return webPage.c_str();
}
void setup(void)
{
ulReqcount = 0;
delay(1000);
Serial.begin(38400);
Serial1.begin(38400);
WiFi.begin(ssid, password);
Serial.println("");
// Wait for connection
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.print("Connected to ");
Serial.println(ssid);
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
if (mdns.begin("esp8266", WiFi.localIP())) {
Serial.println("MDNS responder started");
}
server.on("/", [](){
server.send(200, "text/html", createTable());
});
server.begin();
Serial.println("HTTP server started");
}
void loop(void){
server.handleClient();
}
Any ideas what is wrong here?
I have asked a question here regarding the same issue, but that it is not reviewed by mod yet.
Greetz,
Bob