Disabling wifi: reconnect
Disabling wifi: reconnect
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
Re: Disabling wifi: reconnect
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.
Re: Disabling wifi: reconnect
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.
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
-
- Posts: 6
- Joined: Mon Dec 26, 2016 8:43 am
Re: Disabling wifi: reconnect
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.
Re: Disabling wifi: reconnect
I don't think esp_wifi_set_auto_connect is implemented at this time.
Do you have this in your code
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();
-
- Posts: 6
- Joined: Mon Dec 26, 2016 8:43 am
Re: Disabling wifi: reconnect
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);
so I use "esp_wifi_set_auto_connect(false)", but it's not working.
Who is online
Users browsing this forum: Gaston1980 and 197 guests