Just for fun. What is the shortest micropython server for ON/OFF-type socket? Have not tested this yet:
import network,socket,time
sta_if = network.WLAN(network.STA_IF)
if not sta_if.isconnected():
sta_if.active(True)
sta_if.connect('wifi', 'password')
while not sta_if.isconnected(): pass
from machine import Pin
relayON =Pin(5, Pin.OUT)
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(('', 80))
s.listen(5)
while True:
s.settimeout(0.5)
try:
conn, addr = s.accept()
request = conn.recv(1024)
request = str(request)
if request.find('/ON') == 6:
relayON.value(1)
if request.find('/OFF') == 6:
relayON.value(0)
conn.close()
except: pass