-
I'm trying to setup a Pico W as a captive-portal access point, so that when users connect, they're automatically redirected to the page it's hosting. I actually managed to do this before using Phew, but since that was rather buggy, I've recently converted to Microdot. I figured I'd just use the same DNS catchall server from Phew, tho I'm not sure if it's compatible with Microdot, since there's no catchall() function? This code is usually what's required to enable a captive-portal (already converted most of it to microdot): # microsoft windows redirects
@server.get("/ncsi.txt")
def hotspot(request):
print("AP ncsi.txt request received")
return "", 200
@server.get("/connecttest.txt")
def hotspot(request):
print("AP connecttest.txt request received")
return "", 200
@server.get("/redirect")
def hotspot(request):
print("AP redirect request received")
return redirect(f"http://{DOMAIN}/", 302)
# android redirects
@server.get("/generate_204")
def hotspot(request):
print("AP generate_204 request received")
return redirect(f"http://{DOMAIN}/", 302)
# apple redir
@server.get("/hotspot-detect.html")
def hotspot(request):
print("AP hotspot-detect.html request received")
return render_template('guestbook.html')
@server.catchall() # This is how other webservers do it, is there an equivalent way with Microdot?
def catch_all(request):
print("***CATCHALL***\n" + str(request))
return redirect("http://" + DOMAIN + "/") At the moment, I'm able to connect to my Pico W, but I have to manually enter 192.168.4.1 to go to it's page, and I should be able to enter anything into the URL and be redirected to the hosted page, or click a notification and be taken to it. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Have you tried: @server.get('/<path:path>')
def catch_all(request, path):
print("***CATCHALL***\n" + str(request))
return redirect("http://" + DOMAIN + "/") |
Beta Was this translation helpful? Give feedback.
-
Okay, sorry.. Now I feel a little silly, but I found a solution to my problem. Anywho, I guess maybe I should just close this now that I got it working? |
Beta Was this translation helpful? Give feedback.
Okay, sorry.. Now I feel a little silly, but I found a solution to my problem.
Turns out I needed to use the Asyncio version of microdot. Which earlier I had figured I might need to use, but then I totally forgot about it until now. ^^;
So ya, essentially the catchall function you suggested does seem to work fine. Thanks!
And actually it turns out, I don't even need the catchall! Just an errorhandler(404) redirecting back to the domain.
Anywho, I guess maybe I should just close this now that I got it working?