I don't know if this is the right board, so feel free to move it wherever it is more appropriate.
I use the ESP-ADC module from In-Circuit with Arduino IDE 1.6.5 and the latest ESP8266 libraries from github (downloaded on 02.02.2016).
The ESP is in Station mode and connects to an Accesspoint. I use my desktop PC to request webpages from the ESP. Don't know if this matters, but since I don't know, I prefer to mention it
The issue I have is that while processing the request from the browser the data transfer from the ESP is interrupted.
If I re-request the page in the browser all is well again, until the next transfer error -8....
I configured the ESP to output debug info on Serial1 and what I see there is:
:wr
:er -8 2108 1
:ww
:wr !_pcb
:wr !_pcb
:wr !_pcb
:ur 1
WS:dis
:del
Client disconnected
ip:192.168.0.100,mask:255.255.255.0,gw:192.168.0.254
wifi evt: 3
A relatively small example to recreate this behaviour (on my hardware):
#include <ESP8266WiFi.h>
#include <WiFiUdp.h>
// WiFi connection
char Receive_ssid[33] = "TP-LINK_791EC4";
char Receive_password[65] = "C2791EC4";
unsigned long ulReqcount; // how often has a valid page been requested
unsigned long ulReconncount; // how often did we connect to WiFi
int WiFiStatus = WL_IDLE_STATUS;
// storage for Measurements; keep some mem free; allocate remainder
#define KEEP_MEM_FREE 10240
// Create an instance of the server on Port 80
WiFiServer server(80);
// needed to avoid link error on ram check
extern "C"
{
#include "user_interface.h"
}
/////////////////////
// the setup routine
/////////////////////
void setup()
{
// setup globals
ulReqcount = 0;
ulReconncount = 0;
// start serial
Serial.begin(115200);
Serial.println(" ");
Serial.println("Webserver-Test");
WiFi.mode(WIFI_STA);
WiFiStart(Receive_ssid, Receive_password);
Serial1.begin(115200);
Serial.setDebugOutput(true);
}
///////////////////
// (re-)start WiFi
///////////////////
void WiFiStart(char* ssid, char* password)
{
unsigned int uiTimeOut = 0;
ulReconncount++;
// Connect to WiFi network
Serial.println();
Serial.print("Connecting to ");
Serial.print(ssid);
Serial.print(" with password ");
Serial.println(password);
WiFi.begin((const char*)ssid, (const char*)password);
while (WiFiStatus != WL_CONNECTED)
{
WiFiStatus = WiFi.status();
delay(500);
Serial.print(".");
uiTimeOut++;
if(uiTimeOut == 20)
{
Serial.println("retry");
WiFi.begin((const char*)ssid, (const char*)password);
}
if(uiTimeOut == 40)
{
break;
}
}
if(uiTimeOut >= 40)
{
Serial.println("Could not establish connection!");
switch (WiFiStatus)
{
case WL_IDLE_STATUS:
{
Serial.println("WL_IDLE_STATUS");
break;
}
case WL_CONNECTED:
{
Serial.println("WL_CONNECTED");
break;
}
case WL_NO_SHIELD:
{
Serial.println("WL_NO_SHIELD");
break;
}
case WL_CONNECT_FAILED:
{
Serial.println("WL_CONNECT_FAILED");
break;
}
case WL_NO_SSID_AVAIL:
{
Serial.println("WL_NO_SSID_AVAIL");
break;
}
case WL_SCAN_COMPLETED:
{
Serial.println("WL_SCAN_COMPLETED");
break;
}
case WL_CONNECTION_LOST:
{
Serial.println("WL_CONNECTION_LOST");
break;
}
case WL_DISCONNECTED:
{
Serial.println("WL_DISCONNECTED");
break;
}
default:
{
Serial.println("No idea what went wrong...");
}
}
return;
}
Serial.println();
Serial.println("WiFi connected");
delay(500);
// Start the server
server.begin();
Serial.println("Server started");
// Print the IP address
Serial.print("IP: ");
Serial.println(WiFi.localIP());
}
//////////////////////////
// create HTTP 1.1 header
//////////////////////////
String MakeHTTPHeader(unsigned long ulLength)
{
String sHeader;
sHeader = F("HTTP/1.1 200 OK\r\nContent-Length: ");
sHeader += ulLength;
sHeader += F("\r\nContent-Type: text/html\r\nConnection: close\r\n\r\n");
return (sHeader);
}
////////////////////
// make html footer
////////////////////
String MakeHTTPFooter()
{
String sResponse;
sResponse = F("\r\n<div style=\"font-size:x-small\">");
sResponse += F("\r\n\t<BR>Aufrufzähler = ");
sResponse += ulReqcount;
sResponse += F("\r\n\t<BR>Verbindungszähler = ");
sResponse += ulReconncount;
sResponse += F("\r\n\t<BR>Freies RAM = ");
sResponse += (uint32_t)system_get_free_heap_size();
sResponse += F("\r\n</div>\r\n</body>\r\n</html>");
return (sResponse);
}
/////////////
// main look
/////////////
void loop()
{
delay(50);
//////////////////////////////
// check if WLAN is connected
//////////////////////////////
if(WiFi.status() != WL_CONNECTED)
{
Serial.println("restart server if not connected");
WiFiStart(Receive_ssid, Receive_password);
}
///////////////////////////////////
// Check if a client has connected
///////////////////////////////////
WiFiClient client = server.available();
if (!client)
{
return;
}
// Wait until the client sends some data
Serial.println("new client");
unsigned long ultimeout = millis() + 250;
while (!client.available() && (millis() < ultimeout) )
{
delay(1);
}
if (millis() > ultimeout)
{
Serial.println("client connection time-out!");
return;
}
/////////////////////////////////////
// Read the first line of the request
/////////////////////////////////////
String sRequest = client.readStringUntil('\r');
Serial.println(sRequest);
client.flush();
// stop client, if request is empty
if (sRequest == "")
{
Serial.println("empty request! - stopping client");
client.stop();
return;
}
// get path; end of path is either space or ?
// Syntax is e.g. GET /?show=1234 HTTP/1.1
String sPath = "", sParam = "", sCmd = "";
String sGetstart = "GET ";
int iStart, iEndSpace, iEndQuest;
iStart = sRequest.indexOf(sGetstart);
if (iStart >= 0)
{
iStart += +sGetstart.length();
iEndSpace = sRequest.indexOf(" ", iStart);
iEndQuest = sRequest.indexOf("?", iStart);
// are there parameters?
if (iEndSpace > 0)
{
if (iEndQuest > 0)
{
// there are parameters
sPath = sRequest.substring(iStart, iEndQuest);
sParam = sRequest.substring(iEndQuest, iEndSpace);
}
else
{
// NO parameters
sPath = sRequest.substring(iStart, iEndSpace);
}
}
}
///////////////////////////
// format the html response
///////////////////////////
String sResponse, sResponse2, sHeader;
if (sPath == "/")
////////////////////////////////////
// format the html page for /tabelle
////////////////////////////////////
{
ulReqcount++;
sResponse = F("<!DOCTYPE HTML>");
sResponse += F("\r\n<html>\r\n<head>\r\n<meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\">");
sResponse += F("\r\n\t<meta http-equiv=\"refresh\" content=\"2; url=/\">");
sResponse += F("\r\n\t<style>");
sResponse += F("\r\n\t\tbody {background-color: #dfdfdf;}");
sResponse += F("\r\n\t\tfont {color: #000000;}");
sResponse += F("\r\n\t\ttable {font-size: large; width:100%;}");
sResponse += F("\r\n\t\ttable, th, td {border: 2px solid black; border-collapse: collapse;}");
sResponse += F("\r\n\t\tth, td {padding: 5px;}");
sResponse += F("\r\n\t\tth {text-align: left;}");
sResponse += F("\r\n\t</style>\r\n<title>Test</title>\r\n</head>\r\n<body>");
sResponse += F("\r\n<h1>Testdata</h1>");
sResponse += "\r\n<table>";
sResponse += "\r\n\t<tbody><tr><th>#</th><th>Time</th><th>Calibration used</th><th>Sesnor 1</th><th>Sensor2</th></tr>";
sResponse += "\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>";
sResponse += "\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>";
sResponse += "\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>";
sResponse += "\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>";
sResponse += "\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>";
sResponse += "\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>";
sResponse += "\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>";
sResponse += "\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>";
sResponse += "\r\n</tbody></table>";
sResponse2 = MakeHTTPFooter().c_str();
// Send the response to the client - delete strings after use to keep mem low
client.print(MakeHTTPHeader(sResponse.length() + sResponse2.length()));
client.print(sResponse);
sResponse = "";
client.print(sResponse2);
sResponse2 = "";
}
else
////////////////////////////
// 404 for non-matching path
////////////////////////////
{
sResponse = "<html><head><title>404 Not Found</title></head><body><h1>Not Found</h1><p>The requested URL was not found on this server.</p></body></html>";
sHeader = F("HTTP/1.1 404 Not found\r\nContent-Length: ");
sHeader += sResponse.length();
sHeader += F("\r\nContent-Type: text/html\r\nConnection: close\r\n\r\n");
// Send the response to the client
client.print(sHeader);
client.print(sResponse);
}
// and stop the client
client.stop();
Serial.println("Client disconnected");
delay(50);
}
I tried several things, also modified the code to use ESP8266WebServer and the corresponding server.send() commands but that didn't cure it.
Most notable difference is that I don't get the
:wr !_pcbdebug output any more.
I found out that it has to do with the tcp_output( _pcb ) function in ClientContext.h (regardless which function is used to stream out data) but I have absolutely no idea how I could debug any deeper into the libraries.
My knowledge about Arduino environment and WiFi is very limited.
Any help greatly appreciated