diff --git a/ports/espressif/common-hal/mdns/Server.c b/ports/espressif/common-hal/mdns/Server.c index 18c0f0f5e4..f26597a5bf 100644 --- a/ports/espressif/common-hal/mdns/Server.c +++ b/ports/espressif/common-hal/mdns/Server.c @@ -36,16 +36,22 @@ // Track whether the underlying IDF mdns has been started so that we only // create a single inited MDNS object to CircuitPython. (After deinit, another // could be created.) -STATIC bool mdns_started = false; +STATIC mdns_server_obj_t *_active_object = NULL; void mdns_server_construct(mdns_server_obj_t *self, bool workflow) { - if (mdns_started) { + if (_active_object != NULL) { + if (self == _active_object) { + return; + } // Mark this object as deinited because another is already using MDNS. self->inited = false; return; } - mdns_init(); - mdns_started = true; + esp_err_t ret = mdns_init(); + if (ret != ESP_OK) { + return; + } + _active_object = self; uint8_t mac[6]; esp_netif_get_mac(common_hal_wifi_radio_obj.netif, mac); @@ -86,10 +92,16 @@ void common_hal_mdns_server_deinit(mdns_server_obj_t *self) { return; } self->inited = false; - mdns_started = false; + _active_object = NULL; mdns_free(); } +void mdns_server_deinit_singleton(void) { + if (_active_object != NULL) { + common_hal_mdns_server_deinit(_active_object); + } +} + bool common_hal_mdns_server_deinited(mdns_server_obj_t *self) { return !self->inited; } diff --git a/ports/espressif/common-hal/mdns/Server.h b/ports/espressif/common-hal/mdns/Server.h index ee463657f1..cbdde02929 100644 --- a/ports/espressif/common-hal/mdns/Server.h +++ b/ports/espressif/common-hal/mdns/Server.h @@ -36,3 +36,5 @@ typedef struct { // Track if this object owns access to the underlying MDNS service. bool inited; } mdns_server_obj_t; + +void mdns_server_deinit_singleton(void); diff --git a/ports/espressif/common-hal/wifi/Radio.c b/ports/espressif/common-hal/wifi/Radio.c index 0dcb02a327..b64abd8fb8 100644 --- a/ports/espressif/common-hal/wifi/Radio.c +++ b/ports/espressif/common-hal/wifi/Radio.c @@ -44,7 +44,7 @@ #include "components/lwip/include/apps/ping/ping_sock.h" #if CIRCUITPY_MDNS -#include "components/mdns/include/mdns.h" +#include "common-hal/mdns/Server.h" #endif #define MAC_ADDRESS_LENGTH 6 @@ -97,7 +97,7 @@ void common_hal_wifi_radio_set_enabled(wifi_radio_obj_t *self, bool enabled) { common_hal_wifi_radio_stop_scanning_networks(self); } #if CIRCUITPY_MDNS - mdns_free(); + mdns_server_deinit_singleton(); #endif ESP_ERROR_CHECK(esp_wifi_stop()); self->started = false; diff --git a/ports/espressif/esp-idf b/ports/espressif/esp-idf index 630c2724fc..b6b7a7aad5 160000 --- a/ports/espressif/esp-idf +++ b/ports/espressif/esp-idf @@ -1 +1 @@ -Subproject commit 630c2724fc8c69eeaaa1bb025de52b99c5cb11aa +Subproject commit b6b7a7aad56ede8f2d4e213c3dd3621dacc34122