diff --git a/boot.py b/boot.py index 91135a5..183246f 100644 --- a/boot.py +++ b/boot.py @@ -18,7 +18,7 @@ for connection in connections: - station, password = connection.split() + station, password = connection.split("_") print("Connecting to {}.".format(station)) @@ -30,7 +30,7 @@ if sta_if.isconnected(): break - time.sleep(1) + time.sleep(1) if sta_if.isconnected(): break diff --git a/boot_test.py b/boot_test.py new file mode 100644 index 0000000..fd45beb --- /dev/null +++ b/boot_test.py @@ -0,0 +1,20 @@ +import time + +try: + with open("passwords.txt") as f: + connections = f.readlines() +except OSError: + print("No passwords.txt file!") + connections = [] + + +for connection in connections: + station, password = connection.split("_") + + print("Connecting to {}.".format(station)) + print("password to {}.".format(password)) + + for i in range(15): + print(".") + + time.sleep(1) diff --git a/passwords.txt b/passwords.txt index 9f2747f..4569f3f 100644 --- a/passwords.txt +++ b/passwords.txt @@ -1,2 +1 @@ -EarlGreyTea HotHotHot -MyHomeAccessPoint aueiUeh73NB +wifiname_password \ No newline at end of file diff --git a/web_server/main.py b/web_server/main.py index dd66055..78cd076 100644 --- a/web_server/main.py +++ b/web_server/main.py @@ -23,6 +23,7 @@ from machine import RTC from time import sleep + try: seconds = ntptime.time() except: @@ -47,11 +48,38 @@ def dummy(): return response_template % body -pin = machine.Pin(10, machine.Pin.IN) +def light_on(): + pin_out.value(1) + body = "You turned a light on!" + return response_template % body + +def light_off(): + pin_out.value(0) + body = "You turned a light off!" + return response_template % body + + +def switch(): + body = "{state: %s}" % str(switch_pin.value()) + return response_template % body + + +def light(): + body = "{value: %s}" % str(adc.read()) + return response_template % body + + +switch_pin = machine.Pin(10, machine.Pin.IN) +pin_out = machine.Pin(9, machine.Pin.OUT) +adc = machine.ADC(0) handlers = { 'time': time, 'dummy': dummy, + 'light_on': light_on, + 'light_off': light_off, + 'switch': switch, + 'light': light, } def main():