ESP8266 WiFi.scanNetworks() error codes

I am using Arduino with an ESP8266 module (ESP12F) and occasionally, the module gets into a mode where it loses connectivity with the access point. When that happens, calling WiFi.scanNetworks() immediately returns with a -2 error code and any attempt to re-connect to the access point will fail until I reset the module (e.g. via Soft WDT reset) at which point it will immediately reconnect to the access point.

So:

  • Is there a list of error return codes from methods like scanNetworks?
  • Has anyone else seen this problem?
  • Is there a known solution or workaround?

Any ideas would be appreciated. Thanks!

It's unfortunate those return codes are not documented. The esp8266 Arduino core developers seem to really not like writing documentation. This situation has gotten a bit better recently due to Espressif providing some funds to pay people to write documentation but there's just no substitute for the person who actually wrote the code doing the documentation. I did some digging through the source code and found the following at https://github.com/esp8266/Arduino/blob/2.3.0/libraries/ESP8266WiFi/src/ESP8266WiFiType.h#L28-L29:

#define WIFI_SCAN_RUNNINGĀ   (-1)
#define WIFI_SCAN_FAILED (-2)

Other than the number of networks discovered during the scan, those are the two possible return values of that function.

As for a solution, I can't say. Hopefully someone else can comment on that.