Skip to content

Commit 8371ea6

Browse files
committed
Fix ESP32 network:stop/0
Removes all of the registered event handlers when the driver is stopped. No longer deletes default_event_loop when the driver is stopped. Deleting this loop was a mistake since other processes may use the default loop and it is normally created at boot up, not as part of the network initialization. Adds a network:stop/0 and a second start to the test_wifi_example esp32-simtest to help catch future problems with stopping and restarting the network. Closes #1449 Signed-off-by: Winford <winford@object.stream>
1 parent dfc3bf1 commit 8371ea6

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
@@ -27,6 +27,7 @@ certain VM instructions are used.
2727
- Fixed an issue where a timeout would occur immediately in a race condition
2828
- Fixed SPI close command
2929
- Added missing lock on socket structure
30+
- Fix `network:stop/0` on ESP32 so the network can be started again
3031

3132
## [0.6.5] - 2024-10-15
3233

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)