diff --git a/esp8266-20180511-v1.9.4.bin b/micropython/esp8266-20180511-v1.9.4.bin similarity index 100% rename from esp8266-20180511-v1.9.4.bin rename to micropython/esp8266-20180511-v1.9.4.bin diff --git a/passwords.txt b/passwords.txt index 9f2747f..dcdf224 100644 --- a/passwords.txt +++ b/passwords.txt @@ -1,2 +1 @@ -EarlGreyTea HotHotHot -MyHomeAccessPoint aueiUeh73NB +Andromeda diff --git a/photos/Espressif_ESP8266.jpg b/photos/Espressif_ESP8266.jpg new file mode 100644 index 0000000..6b6e7d7 Binary files /dev/null and b/photos/Espressif_ESP8266.jpg differ diff --git a/photos/PWM_1000.JPG b/photos/PWM_1000.JPG new file mode 100644 index 0000000..0d56afb Binary files /dev/null and b/photos/PWM_1000.JPG differ diff --git a/photos/PWM_500.JPG b/photos/PWM_500.JPG new file mode 100644 index 0000000..37f6643 Binary files /dev/null and b/photos/PWM_500.JPG differ diff --git a/photos/photoresistor.JPG b/photos/photoresistor.JPG new file mode 100644 index 0000000..daceb8a Binary files /dev/null and b/photos/photoresistor.JPG differ diff --git a/web_server/main.py b/web_server/main.py index dd66055..156794c 100644 --- a/web_server/main.py +++ b/web_server/main.py @@ -39,20 +39,60 @@ def time(): """ % str(rtc.datetime()) - return response_template % body def dummy(): body = "This is a dummy endpoint" - return response_template % body +# ------------------------------------ + +on_off_pin = machine.Pin(16, machine.Pin.OUT) + +def light_on(): + on_off_pin.value(0) + body = "You turned a light on!" + return response_template % body + +def light_off(): + on_off_pin.value(1) + body = "You turned a light off!" + return response_template % body +# ------------------------------------ + +switch_pin = machine.Pin(5, machine.Pin.IN) +def switch(): + body = "{state: " + str(switch_pin.value()) + "}" + return response_template % body -pin = machine.Pin(10, machine.Pin.IN) +# Port 10 is always in high impedance mode on my microcontroller, +# which prevents wifi connection to router. Instead, I used port 5 (GPI05). +# ------------------------------------ + +adc_pin = machine.ADC(0) +def light(): + body = "{value: " + str(adc_pin.read()) + "}" + return response_template % body +# ------------------------------------ + +pwm_pin = machine.PWM(machine.Pin(13)) +dty=500 + +def pwm(): + pwm_pin.duty(dty) + body = "{pwm duty: " + str(dty) + "}" + return response_template % body +# ------------------------------------ handlers = { 'time': time, 'dummy': dummy, -} + 'light_on': light_on, + 'light_off': light_off, + 'switch': switch, + 'light': light, + 'pwm': pwm, + } +# ------------------------------------- def main(): s = socket.socket() @@ -66,6 +106,7 @@ def main(): print("Listening, connect your browser to http://:8080") while True: + sleep(0.5) res = s.accept() client_s = res[0] client_addr = res[1] @@ -87,5 +128,6 @@ def main(): client_s.close() print() - +# ------------------------------------- main() +