Still no IPv4 Hostname advertisement with stock LwIP and stock mDNS IPv6 does however.
Port, board and/or hardware
Pico 2 on a W6300 NIC,
MicroPython version
WIZnet-ioNIC MicroPython 1.27.0 Wiznet port
Reproduction
Hostname voor mDNS/DHCP zo vroeg mogelijk zetten, vóór we de
# interface opnieuw activeren. Op de WIZnet Pico build wordt
# hostname.local doorgaans door de onderliggende stack afgehandeld.
try:
if hasattr(network, "hostname"):
network.hostname(ETH_HOSTNAME)
log("Hostname set before NIC init:", ETH_HOSTNAME + ".local")
except Exception as e:
log("Failed to set hostname before NIC init:", e)
spi = WIZNET_PIO_SPI(
baudrate=10_000_000,
sck=Pin(17),
cs=Pin(16),
io0=Pin(18),
io1=Pin(19),
io2=Pin(20),
io3=Pin(21),
Expected behaviour
Expected to resolve the hostname.local, able to use it for opening a webpage
Observed behaviour
No A record advertisement
Additional Information
No, I've provided everything above.
Code of Conduct
Yes, I agree
extmod/modnetwork: Add global hostname/LWIP-mDNS.
This PR proposes to globally move hostname definition to the network module, so that it will be defined for all nic boards by using the network.hostname() method. The default host name is set to mp-host and the hostname length is controlled by the MICROPY_PY_HOSTNAME_LENGTH constant which is defaulted to 32 if not defined.
>>> import network
>>> network.hostname("my-host")
>>> network.hostname()
my-host
>>>
Note: This PR would replace some of the modifications done specifically for the cyw43 board only (PR #8918), but keeps the ioctl functions up and running using this global hostname definition.
If the nic board uses the LWIP library, we take advantage of the integrated mDNS server (if the LWIP_MDNS_RESPONDER constant is defined) to a) declare hostname for the nic board; b) append three functions to the nic object to add, rename and remove a service to the mDNS server for that nic.
>>> import network
>>> network.hostname("my-host")
>>> nic = network.WIZNET5K()
>>> nic.active(True)
>>> nic.ifconfig("dhcp")
>>> # nic.ifconfig(("192.168.1.100", "255.255.255.0", "0.0.0.0", "0.0.0.0")) # for fixed IP
>>> svc_token = nic.mdns_add_service("", "_http", network.DNSSD_PROTO_TCP, 80)
>>> nic.mdns_rename_service(svc_token, "my_http_server")
>>> nic.mdns_remove_service(svc_token)
From now on, on the network, you can perform a ping my-host.local to get a response from your micropython board.
I could not test these modifications for all nic boards, I have only WIZNET5K boards available. The pico_w board compiles though.
The actual only limitation is to define the hostname via network.hostname before creating the nic object. Renaming the hostname after the creation of the nic object does not reflect this name change. To make this mDNS hostname change, it requires to global change to the I don't dare to go further for the time being. I need guidance.mod_network_nic_type_t and probably put all the socket oriented functions (that are probably sitting there for older versions before the use of LWIP library) into another struct (like mod_network_custom_fun_type_t for example) pointed by this mod_network_nic_type_t to save ROM space for nic boards that do not use these specific functions, make sure that all nic board objects really derive from this mod_network_nic_type_t and add a void * netif_ptr member to the mod_network_nic_type_t that would point to the netif of the nic board if available, so that the mod_network could access this parameter to use LWIP mDNS functions. This netif_ptr member will be set by the nic board driver so that boards that have multiple netif(s) will set the right one (for the cyw43 for instance). But
Comments and help are more than welcome as I am quite new to micropython firmware and I don't know all the internals as well as you guys.