Commit 0f61f1e5 authored by Kyle Watson's avatar Kyle Watson

added skeleton of microPython software

parent 8ba529ed
import socket
import wifimgr
from machine import Pin
led = Pin(2, Pin.OUT)
wlan = wifimgr.get_connection()
if wlan is None:
print("Could not initialize the network connection.")
while True:
pass # you shall not pass :D
# Main Code goes here, wlan is a working network.WLAN(STA_IF) instance.
def web_page():
if led.value() == 1:
last_rotated = "7 minutes ago"
html = """
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" href="data:,">
<style>html{font-family: Helvetica; display:inline-block; margin: 0px auto; text-align: center;}
h1{color: #0F3376; padding: 2vh;}p{font-size: 1.5rem;}
.button{display: inline-block; background-color: #e7bd3b; border: none;
border-radius: 4px; color: white; padding: 16px 40px; text-decoration: none; font-size: 30px; margin: 2px; cursor: pointer;}
.button2{background-color: #4286f4;}</style>
<p>Night Light: <strong>""" + gpio_state + """</strong></p>
<p><a href="/?led=on"><button class="button button2">Rotate</button></a></p>
<p><a href="/?led=off"><button class="button button">Cancel</button></a></p>
<p>Last Rotated: <strong>""" + last_rotated + """</strong></p>
return html
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(('', 80))
while True:
conn, addr = s.accept()
print('Got a connection from %s' % str(addr))
request = conn.recv(1024)
request = str(request)
print('Content = %s' % request)
led_on = request.find('/?led=on')
led_off = request.find('/?led=off')
if led_on == 6:
print('LED ON')
if led_off == 6:
print('LED OFF')
response = web_page()
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment