Unable to Get 8266s to Reconnect, Without Resetting Them...

This is really getting annoying.... I'm STILL having trouble getting 8266s to re-connect reliably. I have several 8266s operating in AP+STA mode. One 8266 (AP0) connects to my TP-Link router, two others (AP1 & AP2) connect to AP0. All 8266s ALWAYS connect immediately following a reset or power-up and work perfectly. But, once connected, if I reset the AP0 8266, AP1 and AP2 will NOT re-connect, unless and until I reset them! My initialization code sets both autoConnect and autoReconnect, but they WILL NOT re-connect once AP0 is reset. But, reset AP1 and/or AP2, and the re-connect instantly (typically under 1/2 second).

All SSIDs, Passwords, IP addresses, etc. are verified 100% correct, and EVERYTHING works perfectly unless I reset AP0 AFTER AP1 and AP2 have connected to it. WTH is going on here?? This should be simple...

Here is my init code. The only other code that even touches the 8266s is simply sending and receiving UDP packets, so the problem HAS to be here.

boolean TimerWiFiDeviceAPI::InitializeAP(TimerModes mode,
	char *apssid, char *appassword, IPAddress apip, IPAddress gatewayip, uint8_t apchannel,
	char *stassid, char *stapassword, IPAddress staip,
	uint16_t port)
{
#if (TARGET == TARGET_CONTROL_PANEL) || (TARGET == TARGET_TIMER_DEVICE_ONLY) || (TARGET == TARGET_TIMER_ALL_IN_ONE)
	boolean success = false;

	ConsolePort->printf("Initializing %s AP for Network %s on Channel %d...\n", DeviceName, TimerAPSSID, TimerAPChannel);

        WiFi.begin();

	while (!success)
	{
		// Set Mode
		if (!(success = WiFi.mode(WiFiMode_t::WIFI_AP_STA)))
			continue;

		// Configure STA
		if (!(success = WiFi.config(staip, gatewayip, Netmask, gatewayip)))
			continue;

		// Configure AP
		if (!(success = WiFi.softAPConfig(apip, GatewayIP, Netmask)))
			continue;

		// Start/Connect AP + STA
		if (!(success = WiFi.setAutoConnect(true)))
			continue;

		if (!(success = WiFi.begin(stassid, stapassword)))
			continue;

		if (!(success = WiFi.setAutoReconnect(true)))
			continue;

		if (!(success = WiFi.softAP(apssid, appassword, apchannel)))
			continue;
	}
#endif
}

Regards,
Ray L.

The problem is the v2.3.0 ESP8266WiFi library is cr@p. I backed up to 2.2.0, and it now works exactly as it should.

Regards,
Ray L.

The only other code that even touches the 8266s is simply sending and receiving UDP packets, so the problem HAS to be here.

Not exactly ....

As far as I can tell if the ESP8266 is not in Access Point mode then as soon as power is applied it will automatically attempt to connect to the access point whose credentials are stored in flash. This will be the last access point that it previously attempted to access even if that attempt was in a different program and even if that attempt was unsuccessful.

I have found that if the ESP8266 is already connected to an access point (such as by the automatic mechanism described above) then the WiFi.begin() function will fail, the connection will be broken, and subsequent connection attempts will frequently fail.

To get around this problem I check the WiFi status to make sure that the device is not already connected before using the WiFi.begin() function.

 if (WiFi.status() != WL_CONNECTED)
    WiFi.begin(ssid, password);

Don