Skip to content
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
passwords.txt
33 changes: 32 additions & 1 deletion flexible_web_server/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,15 @@

import machine
import ntptime, utime
from machine import RTC
from machine import RTC, Pin
from time import sleep

rtc = RTC()
led = Pin(9, Pin.OUT)
switch_pin = Pin(10, Pin.IN)
temp_pin = machine.ADC(0)
print(temp_pin.read())

try:
seconds = ntptime.time()
except:
Expand All @@ -46,9 +51,35 @@ def dummy():

return response_template % body

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

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

def switch():
"""returns switch state"""
switch_state = switch_pin.value()
body = "The swtich is {}".format(switch_state)
return response_template % body

def temperature():
"""measures the value of temp from our sensor"""
body = "{value: " + str(temp_pin.read()) + "}"
return response_template % body


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

def main():
Expand Down
1 change: 1 addition & 0 deletions main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import machine