Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mDNS doesn't work on an Access Point on raspberrypi #9813

Open
riancz opened this issue Nov 16, 2024 · 3 comments
Open

mDNS doesn't work on an Access Point on raspberrypi #9813

riancz opened this issue Nov 16, 2024 · 3 comments
Labels
network rp2 Both RP2 microcontrollers
Milestone

Comments

@riancz
Copy link

riancz commented Nov 16, 2024

Device: Raspberry Pi Pico W

mDNS seems to not work when combining the two basic examples from the project: Manual AP & mDNS.

I can reach the page when going directly to my ip address on port 5000, however when trying to reach it on abcd.local:8080 it doesn't do anything.

import wifi
import socketpool
from adafruit_httpserver import Server, Request, Response, FileResponse
import mdns

# Set up access point
print("Creating access point...")
wifi.radio.start_ap(ssid="MyNetwork", password="SomePassword!")
print(f"Created access point {SSID}")

#Set up mDNS
mdns_server = mdns.Server(wifi.radio)
mdns_server.hostname = "abcd"
print("MDNS Hostname: " + mdns_server.hostname)
mdns_server.advertise_service(service_type="_http", protocol="_tcp", port=8080)

# Set up web server
pool = socketpool.SocketPool(wifi.radio)
server = Server(pool, "/static", debug=True)

@server.route("/", methods=['GET'])
def index(request):
    """ Render the Index page"""
    if request.method == 'GET':
        return FileResponse(request, "index.html", "/static")


server.serve_forever(str(wifi.radio.ipv4_address_ap))

settings.toml file is deleted.

Did I do something wrong, or is it some bug?
Thanks

@michalpokusa
Copy link

michalpokusa commented Nov 16, 2024

I cannot test right now, but if this is the exact code you are using, then the http server port does not match the mDNS port, which I believe might be the problem here.

You sould set both http and mdns to the same port.

@riancz
Copy link
Author

riancz commented Nov 16, 2024

It doesn't work even if the mDNS port is set to 5000 as well.
mdns_server.advertise_service(service_type="_http", protocol="_tcp", port=5000)

Also just to be sure I tries to set up both to port 80, with no success.
mdns_server.advertise_service(service_type="_http", protocol="_tcp", port=80)
server.serve_forever(str(wifi.radio.ipv4_address_ap), port=80)

@anecdata
Copy link
Member

anecdata commented Nov 16, 2024

If I'm reading this right, mDNS seems to be hard-coded to station:
https://github.com/adafruit/circuitpython/blob/8cdd96c2055de8a03446d7bc34785d3a32e4a57e/ports/raspberrypi/common-hal/mdns/Server.c#L41C27-L41C35
The code works on Espressif (when using same port for mDNS and HTTP Server).

Transferring this issue to the circuitpython repo.

@anecdata anecdata transferred this issue from adafruit/Adafruit_CircuitPython_HTTPServer Nov 16, 2024
@anecdata anecdata changed the title mDNS not working mDNS doesn't work on an Access Point on raspberrypi Nov 16, 2024
@anecdata anecdata added network rp2 Both RP2 microcontrollers labels Nov 16, 2024
@riancz riancz closed this as completed Nov 18, 2024
@riancz riancz reopened this Nov 18, 2024
@dhalbert dhalbert added this to the 9.x.x milestone Nov 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
network rp2 Both RP2 microcontrollers
Projects
None yet
Development

No branches or pull requests

4 participants