Closed J-Arnold closed 8 years ago
I don't see anywhere in your sketch where you're explicitly closing the client with client.stop();
Most likely you're hitting the ESP max connection limit (Which is 5, IIRC), since neither the ESP nor the application you made seem to close the connection. Could you try explicitly closing it, as well as instructing the application to close with the HTTP header Connection: close
?
Please try using ESP8266WebServer library instead. There are several examples which will get you started. This library avoids many of the errors you are making in managing incoming connections, and it also provides facilities to parse request arguments, headers, and so on.
Basic Infos
Hardware
Hardware: ESP-12e Core Version: 2.1.0-rc2
Description
I developed a Sketch to readout 5 Sensors and other data from the ESP. When multiple requests are coming from my FHEM application at the same time the ESP stops to response and needs to be resetted.
Settings in IDE
Module: NodeMCU 1.0 (ESP12-E) Flash Size: 4MB CPU Frequency: 80Mhz Upload Using: 115200
Sketch (witout sensors)
include
include
const char* ssid = "xxxx"; const char* password = "xxxxx"; IPAddress ip(192,168,100,201); IPAddress dns(192,168,100,254);
IPAddress gateway(192,168,100,254); IPAddress subnet(255,255,255,0);
define GPIO_02_LED 2
Ticker Reset; int NoOutput = 0;
void Reset_System () {
Serial.println("Reset");
ESP.restart(); }
String milli2time(unsigned long mSekunden) {
String TIME = ""; String help = "";
int Tage = mSekunden/86400000; int Stunden = (mSekunden-((Tage_86400000)))/3600000; int Minuten = (mSekunden-((Tage_86400000)+(Stunden_3600000)))/60000; int Sekunden = (mSekunden-((Tage_86400000)+(Stunden_3600000)+(Minuten_60000)))/1000; int MilliSekunden = mSekunden-((Tage_86400000)+(Stunden_3600000)+(Minuten_60000)+(Sekunden_1000)); help = String(Tage); TIME = help + "Tage "; help = String(Stunden); help = "000" + help; help = help.substring(help.length()-2); TIME = TIME + help + ":"; help = String(Minuten); help = "000" + help; help = help.substring(help.length()-2); TIME = TIME + help + ":"; help = String(Sekunden); help = "000" + help; help = help.substring(help.length()-2); TIME = TIME + help + " "; help = String(MilliSekunden); help = "0000" + help; help = help.substring(help.length()-3); TIME = TIME + help; return TIME; }
WiFiServer server(80);
extern "C" {
include "user_interface.h"
uint16 readvdd33(void); }
void setup() { pinMode(GPIO_02_LED, OUTPUT); digitalWrite(GPIO_02_LED, LOW); Serial.begin(115200); delay(10);
Serial.println(); Serial.println("Starting"); Serial.print("Flash Chip Size = "); Serial.println(ESP.getFlashChipSize());
// Connect to WiFi network
Serial.println(); Serial.print("Connecting to ");
WiFi.mode(WIFI_STA); WiFi.config(ip, dns, gateway, subnet); WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) { delay(500);
}
Serial.println(""); Serial.println("WiFi connected"); Serial.println(ssid); Serial.print("WiFi RSSI="); Serial.println(WiFi.RSSI());
// Start the server server.begin();
Serial.println("Server started");
// Print the IP address Serial.print("Use this URL to connect: "); Serial.print("http://"); Serial.print(WiFi.localIP()); Serial.println("/");
digitalWrite(GPIO_02_LED, HIGH);
Reset.once(300, Reset_System); //reset ESP after 5 Minutes no action from Web }
void loop() { String Text = ""; // Check if a client has connected WiFiClient client = server.available(); if (!client) { return; }
Reset.detach(); Reset.once(300, Reset_System); //reset ESP after 5 Minutes no action from Web
// Wait until the client sends some data
Serial.println("new client");
while(!client.available()){ delay(1); }
// Read the first line of the request String request = client.readStringUntil('\r');
Serial.println(request);
client.flush();
// Return the response client.println("HTTP/1.1 200 OK"); client.println("Content-Type: text/html"); client.println(""); // do not forget this one client.println("<!DOCTYPE HTML>"); client.println(""); // Match the request
NoOutput = 0;
if (request.indexOf("/?read=RSSI") != -1) { client.print("RSSI="); client.println(WiFi.RSSI());
}
if (request.indexOf("/?read=UPTIME") != -1) {
}
if (request.indexOf("/?info") != -1) { //ESP.getResetReason() returns String containing the last reset resaon in human readable format.
}
if (request.indexOf("/?read=vdd33") != -1) { client.print("vdd33="); client.println(readvdd33());
}
if (NoOutput != 1) { client.print("Wifi has = "); client.print(WiFi.RSSI()); client.println("DB
");
} client.println(""); delay(1);
Serial.println("Client disonnected"); Serial.println("");
}