- Fri Jul 24, 2020 2:51 am
#88031
We have a few things to talk about here.
1) you dont need that pin mapping: the ArduinoIDE has already done it for you
so you could (should) say {D0,D1,D2....};
2) The connection code is cumbersome and mostly redundant AND will confuse you:
The likelihood of the first begin connection is next to zero - it takes time, often more thn your arbitrary 200mS so you will probably always get get "unable..." message, even though all is fine and it is still trying.
The "while (WiFi.status() != WL_CONNECTED) // Wait until connection completed" is all you need
3) The truth is the code is not behaving differently after a reset - all that is changing is the time that WiFi takes to connect. I guarantee that if you did this long enough, at some point you will get sevearl successful connects in a row and also several (erroneous) "fails" in a row.
4) While the code is typical of what you see in sample sketches...it is probably the worst possible way to do it. Examples are [i]examples[/i], not solid reliable production code! Look at "WiFi events" a good example is here. Using these, you don't need the constant check in the loop, nor do you need the WiFi.begin (at least after you have made one successful connection) See
https://8266iot.blogspot.com/2019/02/st ... artup.htmland
https://arduino-esp8266.readthedocs.io/ ... mples.html