[Swlug] Well that was awkward!
Rhys Sage
rhys_sage at yahoo.com
Mon Sep 5 17:54:55 UTC 2022
It seemed the newly pasted code didn't make it!
Simple HTTP Server Example
# Control an LED and read a Button using a web browser
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
addr = socket.getaddrinfo('0.0.0.0', 80)[0][-1]
s = socket.socket()
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.bind(addr)
s.listen(1)
while True:
cl, addr = s.accept()
cl_file = cl.makefile('rwb', 0)
while True:
line = cl_file.readline()
if not line or line == b'\r\n':
break
response = html
cl.send(web_page())
cl.send(response)
cl.close()
Rhys Sage
More information about the Swlug
mailing list