Skip to content

WiFi Strange behavior about connection/reconnection #2769

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
asetyde opened this issue May 12, 2019 · 37 comments
Closed

WiFi Strange behavior about connection/reconnection #2769

asetyde opened this issue May 12, 2019 · 37 comments
Labels
Status: Stale Issue is stale stage (outdated/stuck)

Comments

@asetyde
Copy link

asetyde commented May 12, 2019

Hardware:

Board: ESP32 WROOM 32D
Core Installation version: 1.0.2 stable
IDE name: Arduino IDE/ Visual Micro on Visual Studio
Flash Frequency: 80cpu/80flash
PSRAM enabled: no
Upload Speed: 115200
Computer OS: Windows 10

Description:

In this month we 've fond many issue that weren't on 1.0.0, but we need temperature reduction with low core, therefore we must use 1.0.2.
WiFi fail sometimes to reconnect, also watchdog sometimes fail to reboot board , we not find any issue about our code.
We ve see many issue but no response from espressif coders, we ve also use ESP-IDF base sdk but issue is hide on WiFi core working and we not investigate inside.

We hope a fast resolving bugfix because devices are not stable and not usable.

Debug Messages:

Always verbose logs about fail reconnection says "AUTH_EXP" looping
about watchdog , says not triggered many times continuosly, core 0 seems live but core 1 freezed and try rebooting but nothing do, board freeze.

@asetyde
Copy link
Author

asetyde commented May 12, 2019

If not fast resolution coming we must come back to 1.0.0 but we ve some problems with i2c, millis, core temperature and some big bug

@me-no-dev
Copy link
Member

there is a fix coming for the wifi issues.

@asetyde
Copy link
Author

asetyde commented May 13, 2019

Many Thanks

@me-no-dev
Copy link
Member

I have merged updated IDF lib. It's only available through github. Could you try them and see if your issues are resolved?

@asetyde
Copy link
Author

asetyde commented May 13, 2019

Yes now I'm loading on devices, test require 24/48h max .

@me-no-dev
Copy link
Member

thanks :)

@asetyde
Copy link
Author

asetyde commented May 13, 2019

can I use 1.0.3 rc from board manager ? git give me always strange issue

@me-no-dev
Copy link
Member

yes :) I tagged it so you and other people with wifi issues can test

@asetyde
Copy link
Author

asetyde commented May 13, 2019

not download , give error on board manager

@me-no-dev
Copy link
Member

something went wrong the first time. I have updated the release. Please try again :)

@asetyde
Copy link
Author

asetyde commented May 13, 2019

ok it go !

@asetyde
Copy link
Author

asetyde commented May 13, 2019

Now I test it, first connection not go (always), second go , now I test many situations

@asetyde
Copy link
Author

asetyde commented May 13, 2019

example :

Port open
[wifi_start] Stato WiFi: WL_NO_SSID_AVAIL
[wifi_start] Tentativo di connessione (EEPROM) 2 di 3
Smartcondfig
maggio2014
[D][WiFiGeneric.cpp:336] _eventCallback(): Event: 5 - STA_DISCONNECTED
[W][WiFiGeneric.cpp:351] _eventCallback(): Reason: 201 - NO_AP_FOUND
[wifi_start] Stato WiFi: WL_NO_SSID_AVAIL
[wifi_start] Tentativo di connessione (EEPROM) 3 di 3
Smartcondfig
maggio2014
[D][WiFiGeneric.cpp:336] _eventCallback(): Event: 5 - STA_DISCONNECTED
[W][WiFiGeneric.cpp:351] _eventCallback(): Reason: 201 - NO_AP_FOUND
[wifi_start] Stato WiFi: WL_NO_SSID_AVAIL
[wifi_start] Tentativo di connessione (Recovery) 1 di 3
Smartconfig
maggio2014
[D][WiFiGeneric.cpp:336] _eventCallback(): Event: 5 - STA_DISCONNECTED
[W][WiFiGeneric.cpp:351] _eventCallback(): Reason: 202 - AUTH_FAIL
[wifi_start] Connessione fallita
[wifi_start] Tentativo di connessione (Recovery) 2 di 3
Smartconfig
maggio2014
[D][WiFiGeneric.cpp:336] _eventCallback(): Event: 4 - STA_CONNECTED
[D][WiFiGeneric.cpp:336] _eventCallback(): Event: 7 - STA_GOT_IP
[D][WiFiGeneric.cpp:379] _eventCallback(): STA IP: 192.168.1.163, MASK: 255.255.255.0, GW: 192.168.1.1

@asetyde
Copy link
Author

asetyde commented May 13, 2019

now we test all days , I report as soon as possible

@asetyde
Copy link
Author

asetyde commented May 13, 2019

Note : We new library 1.0.3 i start to use our chip of memory , eeprom is not use anymore

@asetyde
Copy link
Author

asetyde commented May 14, 2019

About some devices : 3 lost connection and 2 of this after 30/40 min re-connected. Our code not use autoconnect and disabile it, also we use olle manual begin with user and password, we disconnect every time we see lost connection and our code begin our code routine to connect again

@asetyde
Copy link
Author

asetyde commented May 14, 2019

We se only auth exp but we see many logs inside esp-idf this library not report it, as you see on our report example , two connection fail (ssid wrong and is ok), but with recovery, first try not go , always

@asetyde
Copy link
Author

asetyde commented May 14, 2019

About SSID we underline with router with wireless access point , seems esp not choose best signal but choose randomlly, also we see on ESP MDF where channel is fixed and esp not capace to change it
Hope advice you, we continue test on it

about watchdog , one device it blocks on loop wifi, watchdog unable to reset it

@asetyde
Copy link
Author

asetyde commented May 14, 2019

a question , your update is not 3.3 beta IDF correct ? I see many improvements to wifi
our I see is : 0acf19a Update IDF to v3.2 977854975 (#2771)

@me-no-dev
Copy link
Member

Yup we are on the latest IDF 3.2 with whatever bugfixes were added to it.
How is WiFi doing?

@asetyde
Copy link
Author

asetyde commented May 15, 2019

WiFi seems has same problems, but now I test it in STATIC mode, it seems work without reconnection, I suppose two reason , Arduino library not manage correctly or not manage a WiFi.status(), or ISSUE of re-connection is a mask for a issue of DHCP , I give to you an example of our routine , but I think we restrict issue to this two ways, DHCP or WiFi.status() (after reconnections. ? )

@asetyde
Copy link
Author

asetyde commented May 15, 2019

wl_status_t wifi_connect(boolean recovery)
{
	static unsigned long conn_timeout = 5000;
	static unsigned long t0, t1 = 0;
	char wssid[30], wpasswd[30];

	if (WiFi.status() == WL_CONNECTED)
	{
		WiFi.disconnect();
	}

	WiFi.mode(WIFI_MODE_STA);
	WiFi.setHostname("Electric Labs Device");

	if (recovery)
	{
		snprintf(wssid, sizeof(wssid), "Test");
		snprintf(wpasswd, sizeof(wpasswd), "prova");
	}
	else
	{
		if (memory.iptype == 100)
		{
			WiFi.config(convertfromStringSTD(memory.ipset), convertfromStringSTD(memory.ipgateway), convertfromStringSTD(memory.ipmask));
		}
		snprintf(wssid, sizeof(wssid), memory.ssid);
		snprintf(wpasswd, sizeof(wpasswd), memory.password);
	}

	WiFi.begin(wssid, wpasswd);

	t0 = t1 = millis();
	while ((WiFi.status() != WL_CONNECTED) && ((t1 - t0) < conn_timeout))
	{
		delay(500);            // internal memory                         // recovery memory
		if (!recovery){ledcommands(false, false, 0, 2);} else { ledcommands(false, false, 0, 2);}
		delay(500);
		if (!recovery){ledcommands(true, false, 0, 2);} else { ledcommands(false, true, 0, 2); }
		t1 = millis();
	}

	return WiFi.status();
}

@asetyde
Copy link
Author

asetyde commented May 15, 2019

boolean wifi_start()
{
	WiFi.setAutoReconnect(false);

	int RETRY_MAX = 3;
	int retry = 0;
	boolean memory_connected = false;

	wdtreset();
	while (retry < RETRY_MAX)
	{
		debug("[wifi_start] Tentativo di connessione (EEPROM) "); debug((retry + 1)); debug(" di "); debugn(RETRY_MAX);
		wl_status_t result = wifi_connect(false);
		int rssi = 0;
		int value2 = 0;

		switch (result)
		{
			case WL_CONNECT_FAILED:
				debugn("[wifi_start] Connessione fallita");
				break;

			case WL_CONNECTED:
				currentIP.fromString(WiFi.localIP().toString());
				server[0] = currentIP[0];
				server[1] = currentIP[1];
				server[2] = currentIP[2];
				server[3] = 89;
				serial[0] = currentIP[0];
				serial[1] = currentIP[1];
				serial[2] = currentIP[2];
				broadcast[0] = currentIP[0];
				broadcast[1] = currentIP[1];
				broadcast[2] = currentIP[2];
				broadcast[3] = 255;
				WiFi.SSID().toCharArray(datassid, 30);

				debugn("[wifi_start] Connesso!");
				debugn(" --------------------------------------- ");
				debug(" - Wifi SSID : ");
				debugn(datassid);
				debug(" - Wifi ip : ");
				debugn(currentIP.toString());
				debug(" - Size of structt : ");
				debugn(sizeof(memory));
				debug(" - Wifi Mac : ");
				debugn(macAddress);
				debug("- WIFI signal : ");
				rssi = WiFi.RSSI();
				debugn(rssi);
				value2 = abs(rssi);
				if (value2 <= 30) { debugn("- Signal level is < -30 Perfect "); }
				if ((value2 > 30) && (value2 <= 67)) { debugn("- Signal level is  < -67 Very Good "); }
				if ((value2 > 67) && (value2 <= 70)) { debugn("- Signal level is < -70 Ok but is low >30mbit "); }
				if ((value2 > 72) && (value2 <= 80)) { debugn("- Signal level is < -80 not so Good  (about 15-5 mbit) "); }
				if (value2 > 80) { Serial.println("- Signal level is > -80 - Warning is UNSTABLE "); }
				debug(" - Firm.Chip :");
				debugn(ESP.getSdkVersion());
				debug(" - EHI SW : ");
				debugn(systemversion);
				debug(" - IP configuration : ");
				if (memory.iptype == 100) { debugn("system uses Ip fixed"); }
				else {
					debugn("system on DHCP");
					debug(" - IP on dhcp : ");
					debugn(WiFi.localIP());
					debug(" - IPGateway on dhcp : ");
					debugn(WiFi.gatewayIP());
					debug(" - IPmask on dhcp : ");
					debugn(WiFi.subnetMask());
				}
				if (memory.iptype == 100) {
					debug(" - IP fixed : ");
					debugn(memory.ipset);
					debug(" - IPmask fixed : ");
					debugn(memory.ipmask);
					debug(" - IPGateway fixed : ");
					debugn(memory.ipgateway);
				}
				debug(" - Server : ");
				debugn(server);
				debug(" - Serial : ");
				debugn(serial);
				debug(" - Broadcast : ");
				debugn(broadcast);
				debugn(" --------------------------------------- ");
				memory_connected = true;
				connessioneScelta = 1;
				retry = RETRY_MAX;
				iamaliveSQLforecast();
				break;

			default:
				debug("[wifi_start] Stato WiFi: "); printWiFiStatus(WiFi.status());
				break;
		}
		retry++;
	}

	if (!memory_connected)
	{
		wdtreset();
		retry = 0;
		while (retry < RETRY_MAX)
		{
			debug("[wifi_start] Tentativo di connessione (Recovery) "); debug((retry + 1)); debug(" di "); debugn(RETRY_MAX);
			wl_status_t result = wifi_connect(true);
			int rssi = 0;
			int value2 = 0;

			switch (result)
			{
				case WL_CONNECT_FAILED:
					debugn("[wifi_start] Connessione fallita");
					break;

				case WL_CONNECTED:
					currentIP.fromString(WiFi.localIP().toString());
					WiFi.SSID().toCharArray(datassid, 30);
					server[0] = currentIP[0];
					server[1] = currentIP[1];
					server[2] = currentIP[2];
					server[3] = 89;
					serial[0] = currentIP[0];
					serial[1] = currentIP[1];
					serial[2] = currentIP[2];
					broadcast[0] = currentIP[0];
					broadcast[1] = currentIP[1];
					broadcast[2] = currentIP[2];
					broadcast[3] = 255;
					WiFi.SSID().toCharArray(datassid, 30);

					debugn("[wifi_start] Connesso!");
					debug("\tModalità: Recovery");
					debugn(" --------------------------------------- ");
					debug(" - Wifi SSID : ");
					debugn(datassid);
					debug(" - Wifi ip : ");
					debugn(currentIP.toString());
					debug(" - Size of structt : ");
					debugn(sizeof(memory));
					debug(" - Wifi Mac : ");
					debugn(macAddress);
					debug("- WIFI signal : ");
					rssi = WiFi.RSSI();
					debugn(rssi);
					value2 = abs(rssi);
					if (value2 <= 30) { debugn("- Signal level is < -30 Perfect "); }
					if ((value2 > 30) && (value2 <= 67)) { debugn("- Signal level is  < -67 Very Good "); }
					if ((value2 > 67) && (value2 <= 70)) { debugn("- Signal level is < -70 Ok but is low >30mbit "); }
					if ((value2 > 72) && (value2 <= 80)) { debugn("- Signal level is < -80 not so Good  (about 15-5 mbit) "); }
					if (value2 > 80) { Serial.println("- Signal level is > -80 - Warning is UNSTABLE "); }
					debug(" - Firm.Chip :");
					debugn(ESP.getSdkVersion());
					debug(" - EHI SW : ");
					debugn(systemversion);
					debug(" - IP configuration : ");
					if (memory.iptype == 100) { debugn("system uses Ip fixed"); }
					else {
						debugn("system on DHCP");
						debug(" - IP on dhcp : ");
						debugn(WiFi.localIP());
						debug(" - IPGateway on dhcp : ");
						debugn(WiFi.gatewayIP());
						debug(" - IPmask on dhcp : ");
						debugn(WiFi.subnetMask());
					}
					if (memory.iptype == 100) {
						debug(" - IP fixed : ");
						debugn(memory.ipset);
						debug(" - IPmask fixed : ");
						debugn(memory.ipmask);
						debug(" - IPGateway fixed : ");
						debugn(memory.ipgateway);
					}
					debug(" - Server : ");
					debugn(server);
					debug(" - Serial : ");
					debugn(serial);
					debug(" - Broadcast : ");
					debugn(broadcast);

					debugn(" --------------------------------------- ");
					connessioneScelta = 2;
					retry = RETRY_MAX;
					iamaliveSQLforecast();
					break;

				default:
					debug("[wifi_start] Stato WiFi: "); printWiFiStatus(WiFi.status());
					break;
			}
			retry++;
		}
	}

	return WiFi.status() == WL_CONNECTED;
}

@asetyde
Copy link
Author

asetyde commented May 15, 2019

void printWiFiStatus(wl_status_t state)
{
	switch (state)
	{
		case WL_NO_SHIELD:
			debugn("WL_NO_SHIELD");
			break;
		case WL_CONNECTED:
			debugn("WL_CONNECTED");
			break;
		case WL_IDLE_STATUS:
			debugn("WL_IDLE_STATUS");
			break;
		case WL_NO_SSID_AVAIL:
			debugn("WL_NO_SSID_AVAIL");
			break;
		case WL_SCAN_COMPLETED:
			debugn("WL_SCAN_COMPLETED");
			break;
		case WL_CONNECT_FAILED:
			debugn("WL_CONNECT_FAILED");
			break;
		case WL_CONNECTION_LOST:
			debugn("WL_CONNECTION_LOST");
			break;
		case WL_DISCONNECTED:
			debugn("WL_DISCONNECTED");
			break;
	}
}

@me-no-dev
Copy link
Member

please read how to paste code :)

@asetyde
Copy link
Author

asetyde commented May 15, 2019

sorry I do with cell phone, it's a bit confusing, thanks for reformat

@asetyde
Copy link
Author

asetyde commented May 16, 2019

UPDATE : With static configuration and this library, no issue, therefore I think it would be something with disconnection and DHCP is wrong. We can not investigate inside, we not have other information about AUTH_EXP from verbose logs, do you know something about DHCP issues ?

@asetyde
Copy link
Author

asetyde commented May 17, 2019

Other test and continuos operative test on STATIC IP not has issue, I think we can close circle on DHCP

@asetyde
Copy link
Author

asetyde commented May 22, 2019

Continues test and no issue, uses watchdog with while(1) blocking function it works.
We have find some strange casual issue about data from .RSSI sometimes values is corrupted .. this can say something but I don't know

@asetyde
Copy link
Author

asetyde commented Jun 27, 2019

Now it working so better without freeze, but I see sometimes reconnection and sometimes reboot of ESP32 WROOM D. I hope soon @me-no-dev you will upgrade to new IDF with new bug fix about wifi, I see on logs many correction , we need stable working library. Hope to improve signal performance, it's lower than first firmware.

@GeorgeFlorian
Copy link

I am experiencing something similar: #2999

Any luck with this ?

@asetyde
Copy link
Author

asetyde commented Jul 18, 2019

now I see new IDF loaded .. I'm waiting new RC to test it .. at now go better but signal so so .. sometimes not freeze but reboot .. i wait to test it

@CircuitSetup
Copy link

I'm wondering if this has to do with this issue: #2899

However, in the last IDF update CONFIG_ESP32_WIFI_RX_BA_WIN was changed to 16 from 6

@CircuitSetup
Copy link

CircuitSetup commented Jul 19, 2019

I'm curious if the problems people are having with reconnecting to wifi have anything to do with the power being provided? This seems to only happen to me when running a smaller power supply.

When it tries to reconnect to the AP, it fails and eventually freezes. It seems to not disconnect in the first place with more power, but if it does, it reconnects easier.

Edit: I tried this with the latest IDF and settings, but still got a freeze, and had to reboot. It's very hard to log this behavior since it only happens without a serial connection.

@CircuitSetup
Copy link

now I see new IDF loaded .. I'm waiting new RC to test it .. at now go better but signal so so .. sometimes not freeze but reboot .. i wait to test it

You could just copy the current files in the repository. I did this, but unfortunately it didnt solve my issue.

@stale
Copy link

stale bot commented Sep 18, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. Thank you for your contributions.

@stale stale bot added the Status: Stale Issue is stale stage (outdated/stuck) label Sep 18, 2019
@stale
Copy link

stale bot commented Oct 2, 2019

[STALE_DEL] This stale issue has been automatically closed. Thank you for your contributions.

@stale stale bot closed this as completed Oct 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Stale Issue is stale stage (outdated/stuck)
Projects
None yet
Development

No branches or pull requests

4 participants