Disabling wifi: reconnect

User avatar
kolban
Posts: 1683
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

Disabling wifi: reconnect

Postby kolban » Wed Dec 21, 2016 10:57 pm

I am finding that after I issue an esp_wifi_connect() to connect my ESP32 as a station to an access point, if I provide the wrong SSID or password, I get a SYSTEM_EVENT_STA_DISCONNECTED event. That's fine. However I then see a "wifi: reconnect" message followed by another SYSTEM_EVENT_STA_DISCONNECTED event. This seems to continue on-wards approximately every two seconds. Is there a way to disable what appears to be the ESP32 attempting to continually attempt to reconnect to the access point? For example, following an esp_wifi_connect(), I only want one STA_DISCONNECTED event if we fail to connect.
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

WiFive
Posts: 3529
Joined: Tue Dec 01, 2015 7:35 am

Re: Disabling wifi: reconnect

Postby WiFive » Thu Dec 22, 2016 8:48 am

Are you handling the SYSTEM_EVENT_STA_DISCONNECTED in your event handler? If so I think you can filter based on reason code and only call esp_wifi_connect for reasons that make sense and/or limit retries.

User avatar
kolban
Posts: 1683
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

Re: Disabling wifi: reconnect

Postby kolban » Thu Dec 22, 2016 4:53 pm

Thank you sir. The problem partially stems from the fact that I am handling the SYSTEM_EVENT_STA_DISCONNECTED in my event handler. The way I am thinking of ESP32 WiFi is that of a "state machine". Using the "esp_wifi_*" APIs, I am sending "requests" (events in state machine speak) to the WIFI subsystem. Those requests cause the WiFi state machine to change state. When it changes state, then the WiFi subsystem informs me of a change of state by publishing a SYSTEM_EVENT_* event that I catch and handle.

What I would like to write is a diagram (or ideally find one already written) that is a representation of the state machine that is WiFi in ESP32. With that said, what I expected to happen is that when I send in a request "esp_wifi_connect" then the state diagram would transition either to a "STA_CONNECTED" or "STA_DISCONNECTED" state. However, the "side effect" I am "sensing" is that there is an "implicit" "esp_wifi_connect()" request being "re-made" on my behalf when the original "esp_wifi_connect()" happens.

In my current design, I was expecting a "STA_DISCONNECTED" to occur when EITHER ... I make an explicit "esp_wifi_connect" and it fails OR I have previously made an "esp_wifi_connect()" and I am in "connected" state and I am disconnected by the external access point. In either of those cases, my logic knows what to do ... I have a registered "callback" that calls into my app code to tell me that it has happened. To add an "extra layer" of logic means that I have to add my "own" state machine on top of the existing WiFi state machine to remember where I was previously. I can and will do that. The primary purpose of this question was to determine if I "had" to do that ... or is there an alternate technique that might be present and, merely in my ignorance, I am unware of it and could have employed it.
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

mephistod2
Posts: 6
Joined: Mon Dec 26, 2016 8:43 am

Re: Disabling wifi: reconnect

Postby mephistod2 » Thu Dec 29, 2016 3:23 am

I try to use "esp_wifi_set_auto_connect(false)" but ESP32 still continually attempt to reconnect AP. when ESP32 running for a while, "SYSTEM_EVENT_STA_DISCONNECTED" always block other my task.

WiFive
Posts: 3529
Joined: Tue Dec 01, 2015 7:35 am

Re: Disabling wifi: reconnect

Postby WiFive » Thu Dec 29, 2016 6:11 am

I don't think esp_wifi_set_auto_connect is implemented at this time.

Do you have this in your code

Code: Select all

case SYSTEM_EVENT_STA_DISCONNECTED:
        /* This is a workaround as ESP32 WiFi libs don't currently
           auto-reassociate. */
        esp_wifi_connect();

mephistod2
Posts: 6
Joined: Mon Dec 26, 2016 8:43 am

Re: Disabling wifi: reconnect

Postby mephistod2 » Thu Dec 29, 2016 6:53 am

Code: Select all

	case SYSTEM_EVENT_STA_DISCONNECTED:
		LOG_INFO("SYSTEM_EVENT_STA_DISCONNECTED\r\n");
//		esp_wifi_connect();
		xEventGroupClearBits(wifi_event_group, CONNECTED_BIT);
I comment out “esp_wifi_connect();” but ESP32 still attempt to reconnect AP.and get "wifi: reconnect" message .

so I use "esp_wifi_set_auto_connect(false)", but it's not working.

Who is online

Users browsing this forum: Baidu [Spider], Baldhead, Bing [Bot], brushlow18, NoTan2 and 61 guests