Skip to content

esp32: don't fully reset the wifi device #6600

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

Merged
merged 2 commits into from
Jul 14, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion ports/espressif/common-hal/wifi/__init__.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,12 @@ static bool wifi_ever_inited;
static bool wifi_user_initiated;

void common_hal_wifi_init(bool user_initiated) {
wifi_radio_obj_t *self = &common_hal_wifi_radio_obj;

if (wifi_inited) {
if (user_initiated && !wifi_user_initiated) {
common_hal_wifi_radio_set_enabled(self, true);
}
return;
}
wifi_inited = true;
Expand All @@ -154,7 +159,6 @@ void common_hal_wifi_init(bool user_initiated) {
}
wifi_ever_inited = true;

wifi_radio_obj_t *self = &common_hal_wifi_radio_obj;
self->netif = esp_netif_create_default_wifi_sta();
self->ap_netif = esp_netif_create_default_wifi_ap();
self->started = false;
Expand Down Expand Up @@ -204,6 +208,7 @@ void common_hal_wifi_init(bool user_initiated) {
void wifi_user_reset(void) {
if (wifi_user_initiated) {
wifi_reset();
wifi_user_initiated = false;
}
}

Expand All @@ -214,6 +219,7 @@ void wifi_reset(void) {
common_hal_wifi_monitor_deinit(MP_STATE_VM(wifi_monitor_singleton));
wifi_radio_obj_t *radio = &common_hal_wifi_radio_obj;
common_hal_wifi_radio_set_enabled(radio, false);
#ifndef CONFIG_IDF_TARGET_ESP32
ESP_ERROR_CHECK(esp_event_handler_instance_unregister(WIFI_EVENT,
ESP_EVENT_ANY_ID,
radio->handler_instance_all_wifi));
Expand All @@ -226,6 +232,7 @@ void wifi_reset(void) {
esp_netif_destroy(radio->ap_netif);
radio->ap_netif = NULL;
wifi_inited = false;
#endif
supervisor_workflow_request_background();
}

Expand Down