Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions flexible_web_server/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@
seconds = 0
rtc.datetime(utime.localtime(seconds))

pin = machine.Pin(16, machine.Pin.OUT)
switch_pin = machine.Pin(10, machine.Pin.IN)
adc = machine.ADC(0)

def time():
body = """<html>
<body>
Expand All @@ -41,14 +45,37 @@ def time():

return response_template % body


def dummy():
body = "This is a dummy endpoint"

return response_template % body

def light_on():
pin.value(1)
body = 'You turned a light on!'
return response_template % body

def light_off():
pin.value(0)
body = 'You turned a light off!'
return response_template % body

def switch():
body = '{state: ' + switch_pin.value() + '}'
return response_template % body

def light():
body = '{valve: ' + adc.read() + '}'
return response_template % body

handlers = {
'time': time,
'dummy': dummy,
'light_on': light_on,
'light_off': light_off,
'switch': switch,
'light' : light,
}

def main():
Expand Down