代码: 全选
import ampule, socketpool, wifi
@ampule.route("/hello/world")
def light_set(request):
return (200, {}, 'Hi There!'})
try:
from secrets import secrets
except ImportError:
print("WiFi secrets not found in secrets.py")
raise
try:
print("Connecting to %s..." % secrets["ssid"])
print("MAC: ", [hex(i) for i in wifi.radio.mac_address])
wifi.radio.connect(secrets["ssid"], secrets["password"])
except:
print("Error connecting to WiFi")
raise
pool = socketpool.SocketPool(wifi.radio)
socket = pool.socket()
socket.bind(['0.0.0.0', 80])
socket.listen(1)
print("Connected to %s, IPv4 Addr: " % secrets["ssid"], wifi.radio.ipv4_address)
while True:
ampule.listen(socket)