-
Notifications
You must be signed in to change notification settings - Fork 3
/
webserver.py
33 lines (30 loc) · 1.04 KB
/
webserver.py
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
from tinyweb import webserver
import uasyncio
class website:
"""
Creates a pico webserver ready for modules
"""
def __init__(self) -> None:
self.app = webserver()
# Index page
@self.app.route('/')
async def index(request, response):
# Start HTTP response with content-type text/html
await response.start_html()
# Send actual HTML page
html = """<!DOCTYPE html>
<html>
<head> <title>Pico-Power</title> </head>
<body> <h1>Pico-Power: Relay control of 4 circuits up to 240v AC or 30v DC</h1>
<p>
Use the following URL suffixes to drive functions on this Pico:
<ul>
<li>Relay control - <a href="relay">/relay</a></li>
</p>
</body>
</html>\n
"""
await response.send(html)
def run(self) -> uasyncio.Loop:
loop = self.app.run(host='0.0.0.0', port=80, loop_forever=False)
return loop