gmag11 / FSBrowserNG

Full autocontained (on SPIFFS) async web server on ESP8266. Written as a Library.
Other
158 stars 70 forks source link

Async Webserver becomes unresponsive #36

Open bill-orange opened 6 years ago

bill-orange commented 6 years ago

edit - I revised this post substantially. I initially thought this was a Safari problem..

I have encountered several situations where the browser stops responding. LOOP() continues to run fine but the browser is not reachable..

I just about have my Wunderground sketch running properly. It plots actual temp from a sensor along with forecasts. Here's a version that does not use FSBrowser: http://orangecaweather.duckdns.org:8021

In the FSB version I am exposed so I am not giving the link to it!

Right now I am running my sketch after recompiling with ESP8266 RC2 to see if that maters. It looks to my uneducated eyes like there have been a lot of changes that could affect web service. edit - no change :(

If I still have Webserver problems with RC2 my next attempt to fix the problem will be to have the device ping its own IP within LOOP() and restart if it fails.

if ((millis() - currentLoop) > pingTest) { currentLoop = millis(); if (Ping.ping(WiFi.localIP()), 1) { //if (Ping.ping(remote_host)) { Serial.print("ping Success!! Ping Time (mS) = "); Serial.println(Ping.averageTime()); } else { Serial.println("ping Error :("); ESP.restart();

}

}

Thoughts?

Bill

bill-orange commented 6 years ago

Well that almost worked. I had about 15 hours of operation without a problem. That's a record.

I should note that the symptoms changed a bit. When the Webserver became unresponsive, Ping continued to work . After an hour or so it recovered on its own for no clear reason.

So: I depreciated the PING solution and added in this proposed solution.

https://github.com/me-no-dev/ESPAsyncWebServer/issues/54#issuecomment-234742606

Presently testing. We will see. It is doing something the Webserver is not very snappy as before.

EDIT overnight it became unresponsive again:(**

bill-orange commented 6 years ago

This is clearly a work-around, but it seems to resolve 'unresponsive' behavior. Then code it not meant to run alone. Merge it into your existing sketch that has 'unresponsive' issues.

include

include

include

define FPM_SLEEP_MAX_TIME 0xFFFFFFF

unsigned long pingTest = 1000UL 60UL 30UL; // Test connection every 30 minuites unsigned long prevMillis = 0; // used for temp timing counter

extern "C" {

include "user_interface.h" // Required for wifi_station_connect() to work

}

extern "C" { extern char netif_list; uint8_t etharp_request(char , char *); // required for forceArp to work }

void forceARP() { char *netif = netif_list;

while (netif) { etharp_request((netif), (netif + 4)); netif = *((char **) netif); } }

void setup() { wifi_set_sleep_type(NONE_SLEEP_T); // May help stability // add your code to connect to the internet and so forth

}

void loop() { // ----------------------Connectivity testing within Loop() ----------- HTTPClient http_1; // used in ping test unsigned long currentMillis = millis(); // timer for data unsigned long pingMillis = millis(); // timer for data

if ((pingMillis - prevMillis) > pingTest) { prevMillis = pingMillis; WiFiOff(); Serial.print("WiFi - OFF "); delay (20); WiFiOn(); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println("WiFi - ON"); if (Ping.ping(WiFi.gatewayIP())) { Serial.print("ping gateway Success!! Ping Time (mS) = "); Serial.println(Ping.averageTime()); forceARP(); } else { Serial.println("Failed ping to gateway!"); ESP.restart(); } if (Ping.ping(WiFi.localIP()), 1) { Serial.print("ping localIP Success!! Ping Time (mS) = "); Serial.println(Ping.averageTime()); forceARP(); } else { Serial.println("ping Error :("); ESP.restart();

} http_1.begin("http://api.wunderground.com"); // or some other web site you like int httpCode = http_1.GET(); if (httpCode > 0) { Serial.println ("connection test okay!"); } else { Serial.print("connection test failed! code: "); Serial.println(httpCode); ESP.restart(); } http_1.end(); } // -------------------- end testing --------------------------- // rest of your loop goes here }

//----------------------------------- WiFi On OFF ----------------------------------

void WiFiOn() {

wifi_fpm_do_wakeup(); wifi_fpm_close();

//Serial.println("Reconnecting"); wifi_set_opmode(STATION_MODE); wifi_station_connect(); }

void WiFiOff() {

//Serial.println("diconnecting client and wifi"); //client.disconnect(); wifi_station_disconnect(); wifi_set_opmode(NULL_MODE); wifi_set_sleep_type(MODEM_SLEEP_T); wifi_fpm_open(); wifi_fpm_do_sleep(FPM_SLEEP_MAX_TIME);

}

species5618 commented 6 years ago

Sorry short in time at the moment May be able to support you in this over the holidays

My temp sensor based on this seems to reboot every few days And stops responding to are requests But web server still works. May be related

bill-orange commented 6 years ago

Thanks. Possibly related. Also try, accessing the. server from an iPhone using Safari. After a couple of refreshes it begins to ignore the Safari browser. Here'a a link to my sketch. It plots actual temperature vs Wunderground forecast..