-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathserverLEDtime.py
More file actions
63 lines (55 loc) · 1.75 KB
/
Copy pathserverLEDtime.py
File metadata and controls
63 lines (55 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
"""
Web interface for a presentation timer.
Copyright 2019 Wes Lauer
This code is released under the MIT license
Requires timer.py
Creates a simple website that allows user to enter the time
required for a presentation over a web page served by an
ESP32 or ESP8266. The program calls a separate script that
controls uses this time to control a presentation timer.
Can be used over a typical cell phone if the user joins the
ESP32/8266 network (using SSID/Password set up in boot.py),
then navigates using a browser app to 192.168.4.1.
"""
#HTML to send to browsers
html = """<!DOCTYPE html>
<html>
<head> <title>WS2812 LED Presentation Timer</title> </head>
<h2>LEDs Turn Yellow One Minute Before Time, Red at Time</h2></center>
<h3>(ESP32)</h3></center>
<form action="/test" method="get">
Enter Minutes: <input type="text" name="minutes"><br />
<input type="submit" value="Submit">
</form>
</html>
"""
#Setup PINS
import machine
import socket
import re
import utime
import timer
LED_BLUE = machine.Pin(2, machine.Pin.OUT)
#Setup Socket WebServer
#addr = socket.getaddrinfo('192.168.4.1', 80)[0][-1]
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(('', 80))
#s.bind(addr)
s.listen(5)
while True:
conn, addr = s.accept()
print("Got a connection from %s" % str(addr))
request = conn.recv(1024)
print("Content = %s" % str(request))
request = str(request)
output = re.search("minutes=(.+?) HTTP", request)
if output:
out_min = output.group(1)
print(out_min)
LED_BLUE.value(0)
utime.sleep(float(out_min))
LED_BLUE.value(1)
timer.t(float(out_min))
response = html
conn.send(response)
conn.close()