Merge 6951ef525c
into 712964b1d9
commit
850d5e95f4
|
@ -50,31 +50,34 @@ while True:
|
||||||
try:
|
try:
|
||||||
cl, addr = s.accept()
|
cl, addr = s.accept()
|
||||||
print('client connected from', addr)
|
print('client connected from', addr)
|
||||||
request = cl.recv(1024)
|
request = cl.recv(1024).decode()
|
||||||
print(request)
|
print(request)
|
||||||
|
|
||||||
request = str(request)
|
led_on = '/light/on' in request
|
||||||
led_on = request.find('/light/on')
|
led_off = '/light/off' in request
|
||||||
led_off = request.find('/light/off')
|
|
||||||
print( 'led on = ' + str(led_on))
|
print( 'led on = ' + str(led_on))
|
||||||
print( 'led off = ' + str(led_off))
|
print( 'led off = ' + str(led_off))
|
||||||
|
|
||||||
if led_on == 6:
|
if led_on:
|
||||||
print("led on")
|
print("led on")
|
||||||
led.value(1)
|
led.on()
|
||||||
stateis = "LED is ON"
|
text = "LED is ON"
|
||||||
|
|
||||||
if led_off == 6:
|
elif led_off:
|
||||||
print("led off")
|
print("led off")
|
||||||
led.value(0)
|
led.off()
|
||||||
stateis = "LED is OFF"
|
text = "LED is OFF"
|
||||||
|
|
||||||
response = html % stateis
|
else:
|
||||||
|
print("no LED command")
|
||||||
|
text = "Access the /light/on and /light/off pages to control the LED!"
|
||||||
|
|
||||||
|
response = html % text
|
||||||
|
|
||||||
cl.send('HTTP/1.0 200 OK\r\nContent-type: text/html\r\n\r\n')
|
cl.send('HTTP/1.0 200 OK\r\nContent-type: text/html\r\n\r\n')
|
||||||
cl.send(response)
|
cl.send(response)
|
||||||
cl.close()
|
cl.close()
|
||||||
|
|
||||||
except OSError as e:
|
except OSError:
|
||||||
cl.close()
|
cl.close()
|
||||||
print('connection closed')
|
print('connection closed')
|
Ładowanie…
Reference in New Issue