-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcode.py
31 lines (31 loc) · 1.29 KB
/
code.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
import socketpool
import wifi
from duck import exe
from adafruit_httpserver import Server, Request, JSONResponse ,POST , Response
"""--------------------------------------------------------------------------------------"""
ssid = "Pico WIFI DUCK"
password = "pico123456"
"""--------------------------------------------------------------------------------------"""
print("Creating access point", ssid)
wifi.radio.stop_station()
wifi.radio.start_ap(ssid, password)
print("Access point created!")
pool = socketpool.SocketPool(wifi.radio)
server = Server(pool, "/static", debug=True)
"""--------------------------------------------------------------------------------------"""
@server.route("/")
def base(request: Request):
with open("index.html", "r") as file:
html_content = file.read()
headers = {"Content-Type": "text/html"}
return Response(request, html_content, headers=headers)
"""--------------------------------------------------------------------------------------"""
@server.route("/api", POST,append_slash=True)
def api(request: Request):
if request.method == POST :
req = request.json()
payload = req["content"]
payload = payload.splitlines()
exe(payload)
return JSONResponse(request, {"message": "Done"})
server.serve_forever('192.168.4.1', 80)