diff --git a/flexible_web_server/main.py b/flexible_web_server/main.py index d1855c1..d3a72af 100644 --- a/flexible_web_server/main.py +++ b/flexible_web_server/main.py @@ -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 = """ @@ -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():