Skip to content

Commit 078ead2

Browse files
greezybacondpgeorge
authored andcommitted
extmod/network_wiznet5k: Reset mDNS when interface is brought up.
The LwIP interface is removed in wiznet5k_deinit() which is called as part of the init sequence. Therefore, if using mDNS, then the interface will need to be re-added when bringing the interface up. Additionally, this allows to set the hostname from MicroPython code prior to bringing the interface up and mDNS responding to the (new) hostname. This allows the hostname to be configured and saved on the flash or be based on dynamic information such as the MAC or unique_id(). Signed-off-by: Jared Hancock <[email protected]>
1 parent 3f54e5d commit 078ead2

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

extmod/network_wiznet5k.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
#include "shared/netutils/netutils.h"
5959
#include "lib/wiznet5k/Ethernet/wizchip_conf.h"
6060
#include "lib/wiznet5k/Ethernet/socket.h"
61+
#include "lwip/apps/mdns.h"
6162
#include "lwip/err.h"
6263
#include "lwip/dns.h"
6364
#include "lwip/dhcp.h"
@@ -201,6 +202,9 @@ static void wiznet5k_config_interrupt(bool enabled) {
201202
void wiznet5k_deinit(void) {
202203
for (struct netif *netif = netif_list; netif != NULL; netif = netif->next) {
203204
if (netif == &wiznet5k_obj.netif) {
205+
#if LWIP_MDNS_RESPONDER
206+
mdns_resp_remove_netif(&wiznet5k_obj.netif);
207+
#endif
204208
netif_remove(netif);
205209
netif->flags = 0;
206210
break;
@@ -334,6 +338,12 @@ static void wiznet5k_lwip_init(wiznet5k_obj_t *self) {
334338
self->netif.flags |= NETIF_FLAG_UP;
335339
dhcp_start(&self->netif);
336340
self->netif.flags &= ~NETIF_FLAG_UP;
341+
342+
#if LWIP_MDNS_RESPONDER
343+
// NOTE: interface is removed in ::wiznet5k_deinit(), which is called as
344+
// part of the init sequence.
345+
mdns_resp_add_netif(&self->netif, mod_network_hostname_data);
346+
#endif
337347
}
338348

339349
void wiznet5k_poll(void) {

0 commit comments

Comments
 (0)