- Thu Nov 25, 2021 5:48 am
I forgot to add, I've found that the ESP8266 in some situations will disconnect and reconnect quite regularly. In others, it is solid as a rock. Haven't figured why, but it doesn't seem to be based on strength of the WiFi connection.
I also didn't really answer your question. Whether you continue to poll for WiFi status depends on if you need to know that you're connected. You don't need to, to re-initiate the connecting process, but you obviously can't sends stuff if you're disconnected. So it depends on how important the information you have is to be successfully sent.
If you prefer, instead of polling to see if your WiFi status is "currently" connected, there is a low level method to supply a callback for WiFi events.wifi_set_event_handler_cb(statusHandler);
And here is a sample statusHandler
Code: Select all
ICACHE_FLASH_ATTR void statusHandler(System_Event_t *evt)
dbg("connect to ssid %s, channel %d\n",
dbg("disconnect from ssid %s, reason %d\n",
// * When router powers off, we get reason REASON_ASSOC_EXPIRE (4) once, then
// REASON_NO_AP_FOUND (201) repeatedly trying to reconnect. Might be
// better to respond to 4. Keep evaluating.
// * Got 201 once on first connection, then proceeded to connect properly.
if ((evt->event_info.disconnected.reason == REASON_ASSOC_EXPIRE) &&
(_Hdr.start == aStrongest))
InqInterval::SetInterval(scanner, 1, NULL, AUTO_LBL);
dbg("mode: %d -> %d\n",
dbg("ip:" IPSTR " mask: " IPSTR " gw: " IPSTR "\n",
dbg("station: " MACSTR " join, AID = %d\n",
dbg("station: " MACSTR " leave, AID = %d\n",
dbg("station: " MACSTR " leave, rssi = %d\n",
dbg("OpMode old=%u, new=%u\n",
case EVENT_OPMODE_CHANGED + 1:// EVENT_SOFTAPMODE_DISTRIBUTE_STA_IP:
u8* p = (u8*)&evt->event_info;
dbg("station: " MACSTR " ip: " IPSTR " ex: %u, %u\n",
MAC2STR(evt->event_info.sta_disconnected.mac), // 0-5
IP2STR(&evt->event_info.got_ip.gw), // 8-11
*(p+6), *(p+7)); // 6,7