[Swlug] Python Hotspot
Rhys Sage
rhys_sage at yahoo.com
Mon Sep 5 17:51:39 UTC 2022
I'm digging around and not coming up with much. I'm trying to find working sample code that I can use on my Pi Pico W to turn it into a hotspot. Currently I can connect it to my home network but I need to be able to set it as a hotspot so my phone can see what's being displayed on a custom webpage.
I'd been planning on putting an LCD on the ordinary non-W Pico but the first LCD that arrived and took forever to get here was faulty. The second came with a JST connector but no JST cable. It's really not worth throwing more time and money down that hole at the moment. I did get a Pico W at the same time so I'm figuring I'll just try using the W to display what's going on, on a webpage rather than waste more time waiting for stuff that might or might not work to arrive. There are no places locally selling components. There are quite a lot of dropshippers though.
I want to set up so that it's an open hotspot. I connect with a phone or other gizmo and up comes a webpage displaying current settings, readings etc. Where I'm stuck is on the MicroPython to open the webpage. Eventually I'll do away with the password and have it as a public hotspot which will be fine for development. I've got this far:
import machine
import time
import network
import socket
ssid = 'Wot u lookin at, boy?'
password = 'bollocks'
ap = network.WLAN(network.AP_IF)
ap.config(essid=ssid, password=password)
ap.active(True)
while ap.active()==False:
pass
print('comnnection successful')
print (ap.ifconfig)
def web_page():
html = "<html><head><meta name='viewpoint' content='width=device width, initial-scale=1'></head><body><h1>Hello Plonker</h1></body></html>"
return html
It displays in the shell:
MicroPython v1.19.1 on 2022-08-31; Raspberry Pi Pico W with RP2040
Type "help()" for more information.
>>> %Run -c $EDITOR_CONTENT
comnnection successful
<bound_method>
>>>
My phones accept the hotspot then the password is rejected on one phone while on the other I can connect but that's all. Clearly I'm missing something but what?
Rhys Sage
More information about the Swlug
mailing list