Your new topic does not fit any of the above??? Check first. Then post here. Thanks.

Moderator: igrr

User avatar
By schufti
#64900 best method to reliably check if wifi is active: get host by name
I've seen situations where wifi was reported as connected but no traffic going through or vice-versa
see: https://github.com/esp8266/Arduino/issues/2186

there is a esp.restart() function

but: you are creating a new instance of "client" in every loop without dropping it at the end. I can't say if this might pose a problem but I would try to avoid it.

final: for your application I would consider going into deepsleep for the 5minutes instead of delay().
this will provide for a clean reboot and reconnect on every wakeup and save massive on energy, too.
User avatar
By Marmachine
#64902 Thanks for your response!

schufti wrote:best method to reliably check if wifi is active: get host by name
I've seen situations where wifi was reported as connected but no traffic going through or vice-versa
see: https://github.com/esp8266/Arduino/issues/2186


Basically, on the above link, i see the same method applied as a working solution or am i missing something here?

Testing WiFi.status()
Code: Select allif (WiFi.status() != WL_CONNECTED) {  // FIX FOR USING 2.3.0 CORE (only .begin if not connected)
    WiFi.begin(ssid, password);       // connect to the network
}


schufti wrote:there is a esp.restart() function

but: you are creating a new instance of "client" in every loop without dropping it at the end. I can't say if this might pose a problem but I would try to avoid it.


"you are creating a new instance of "client" in every loop without dropping it at the end", meaning: when applying the esp.restart() function? Would a good example be this?

schufti wrote:final: for your application I would consider going into deepsleep for the 5minutes instead of delay().
this will provide for a clean reboot and reconnect on every wakeup and save massive on energy, too.


Sounds like a plan, i will test this! Will setup be ran after deep sleep automatically?
In other words, best to add this at the end of the loop:

Code: Select allSerial.println("Time to sleep");
system_deep_sleep(10000000); //sleep time in usecs. 10000000 = 10 secs.
delay(1000); // a short delay to keep in loop while Deep Sleep is being implemented.
User avatar
By schufti
#64921 the code from the github thread tackles a different problem: the wifi stack entered a erratic state if one issued a wifi.connect while wifi still was connected. The reference to the git was just to give a start on reading about wifi flakyness of the esp8266 and why it isn't a good idea to keep wifi connected and rely on a stable and working connection.

as your existing code goes through setup once and then keeps "looping" (and creating a wifi client) every 5min, I would suggest to at least move the

// Define a new client
WiFiClient client;

to the setup section (out of the loop).

an esp.restart() will just restart the esp8266 but without a reinitialisation of the hw (cantrary to power up or reset), meaning: will go through setup and then enter loop.

on deepsleep wakeup the esp8266 starts up like hw-reset (with all init of ports, registers etc)