Skip to content

Commit b6ca308

Browse files
committed
Merge pull request #1450 from UncleGrumpy/fix_esp_wifi_stop
Removes all of the registered event handlers when the driver is stopped. Fixes the incorrect deletion on the default event loop when the driver is stopped. Closes #1449 These changes are made under both the "Apache 2.0" and the "GNU Lesser General Public License 2.1 or later" license terms (dual license). SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later
2 parents 6e9f601 + 8371ea6 commit b6ca308

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ certain VM instructions are used.
3030
- Fixed a race condition affecting multi-core MCUs where a timeout would not be properly cleared
3131
- Fixed a double free when esp32 uart driver was closed, yielding an assert abort
3232
- Fixed compilation with latest debian gcc-arm-none-eabi
33+
- Fix `network:stop/0` on ESP32 so the network can be started again
3334

3435
## [0.6.5] - 2024-10-15
3536

src/platforms/esp32/components/avm_builtins/network_driver.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -811,6 +811,9 @@ static void stop_network(Context *ctx)
811811
{
812812
// Stop unregister event callbacks so they dont trigger during shutdown.
813813
esp_event_handler_unregister(WIFI_EVENT, ESP_EVENT_ANY_ID, &event_handler);
814+
esp_event_handler_unregister(IP_EVENT, IP_EVENT_STA_GOT_IP, &event_handler);
815+
esp_event_handler_unregister(IP_EVENT, IP_EVENT_AP_STAIPASSIGNED, &event_handler);
816+
esp_event_handler_unregister(sntp_event_base, SNTP_EVENT_BASE_SYNC, &event_handler);
814817

815818
esp_netif_t *sta_wifi_interface = esp_netif_get_handle_from_ifkey("WIFI_STA_DEF");
816819
esp_netif_t *ap_wifi_interface = esp_netif_get_handle_from_ifkey("WIFI_AP_DEF");
@@ -830,12 +833,6 @@ static void stop_network(Context *ctx)
830833
// Stop sntp (ignore OK, or not configured error)
831834
esp_sntp_stop();
832835

833-
// Delete network event loop
834-
esp_err_t err = esp_event_loop_delete_default();
835-
if (err != ESP_OK) {
836-
ESP_LOGE(TAG, "Invalid state error while deleting event loop, continuing network shutdown...");
837-
}
838-
839836
// Destroy existing netif interfaces
840837
if (ap_wifi_interface != NULL) {
841838
esp_netif_destroy_default_wifi(ap_wifi_interface);

src/platforms/esp32/test/main/test_erl_sources/test_wifi_example.erl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
start() ->
2626
case verify_platform(atomvm:platform()) of
2727
ok ->
28+
ok = start_network(),
29+
ok = network:stop(),
2830
start_network(),
2931
loop(0);
3032
Error ->

0 commit comments

Comments
 (0)