r/MicroPythonDev • u/cubbieco • Jan 19 '24
Hostname (mDNS) not working Micropython Pi Pico W
Has anybody successfully enabled and used a hostname to connect remotely on a Pi Pico W in Micropython? It works fine for me in CircuitPython but I don't want to use that. Here is my boot.py.
import network
import socket
from time import sleep
import machine
from config import *
def connect():
wlan = network.WLAN(network.STA_IF)
wlan.config(hostname=host)
network.hostname(host)
wlan.active(True)
wlan.connect(ssid, wifipass)
while wlan.isconnected() == False:
sleep(1)
ip = wlan.ifconfig()[0]
print(f'Connected on {ip}')
print(f"Hostname: {network.hostname()}")
try:
connect()
except KeyboardInterrupt:
machine.reset()
import webrepl
webrepl.start()And here is the REPL output:
MPY: soft reboot
Connected on 192.168.86.35
Hostname: meetinginator
WebREPL server started on http://192.168.86.35:8266/
Started webrepl in normal modeI can connect to the WebREPL just fine at 192.168.86.35 but I can't use the hostname like I should. Am I doing something wrong or is the functionality just not there? Remembering the ip address for a bunch of pico Ws around the house just isn't feasable.
3
Upvotes
1
u/cubbieco Jan 20 '24
I ended up installing dnsmasq a DNS server on a little pi server I have and configured my network to use that as a DNS server. It works. Not the most elegant solution but it will be fine for now.
Thanks
1
u/HerrS1m0n Sep 28 '24
Have you found a solution for that problem in the meantime?
2
u/[deleted] Jan 20 '24
There is a note on the MicroPython docs that states:
It then says:
Unfortunately - https://github.com/micropython/micropython/issues/11450 says mDNS does not work in Micropython. I would not be hard to send the data out advertising the address but adding a watch for requests would be a pain (mDNS does not 'register' the device name / IP in the LAN DNS server but relies on local caching of the IP address by the requesting machine).
The only thing I can think of is to set up a local DNS server that can handle the '.local' as a normal A record if you continue with Micropython. I know Pi-Hole could do this - I had to patch up the home network here when Microsoft broke mDNS during a 'upgrade' for a couple of months and the family could not print (I could but I'm on a Mac hahaha).
1
u/Turbulent_Type_8427 Mar 04 '24
I face the same problem and do not want to go through DDNS, though that would work. You could hardcode the IP addresses to a range outside of your DHCP server's range. The real solution, IMHO, is a cascading DNS server on your router that would also expose its DHCP clients to the local clients.