Fix MDNS after the user turns off wifi
We need to reset our MDNS state instead of just the IDF's.
This commit is contained in:
parent
40a5313589
commit
8f3c6422ee
@ -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;
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
@ -1 +1 @@
|
||||
Subproject commit 630c2724fc8c69eeaaa1bb025de52b99c5cb11aa
|
||||
Subproject commit b6b7a7aad56ede8f2d4e213c3dd3621dacc34122
|
Loading…
Reference in New Issue
Block a user