commit 799de0c306e5a9c524d746e81a1a340c1ce8dc75 Author: Adrian A. Baumann Date: Tue Aug 25 20:25:20 2020 +0300 Initial commit diff --git a/boot.py b/boot.py new file mode 100644 index 0000000..4d4e8da --- /dev/null +++ b/boot.py @@ -0,0 +1,9 @@ +# This file is executed on every boot (including wake-boot from deepsleep) +#import esp +#esp.osdebug(None) +import uos, machine +#uos.dupterm(None, 1) # disable REPL on UART(0) +import gc +#import webrepl +#webrepl.start() +gc.collect() diff --git a/firmware_esp8266-v1.3.5.bin b/firmware_esp8266-v1.3.5.bin new file mode 100644 index 0000000..fd114f1 Binary files /dev/null and b/firmware_esp8266-v1.3.5.bin differ diff --git a/garage.py b/garage.py new file mode 100644 index 0000000..fd6f6af --- /dev/null +++ b/garage.py @@ -0,0 +1,32 @@ +import tinyweb +from machine import Pin +from time import sleep + +# Create web server application +app = tinyweb.webserver() +Button=Pin(2,Pin.OUT) +Button.on() + +# Index page +@app.route('/') +async def index(request, response): + # Start HTTP response with content-type text/html + await response.start_html() + # Send actual HTML page + await response.send('

Hi George!

Push the garage door button\n') + + +# Another one, more complicated page +@app.route('/button/') +async def table(request, response,nr): + # Start HTTP response with content-type text/html + Button.off() + sleep(1) + Button.on() + await response.start_html() + await response.send('

Hi George!

Button number %s pushed. Go back. Or push it again.\n'%nr) + + +def run(): + print ("running app") + app.run(host='0.0.0.0', port=80) diff --git a/main.py b/main.py new file mode 100644 index 0000000..6cea21b --- /dev/null +++ b/main.py @@ -0,0 +1,42 @@ +import network +import json +import time + +settings=json.loads(''.join(open('settings.json').readlines())) + +def netstop(): + n=network.WLAN(network.STA_IF) + n.active(False) + n=network.WLAN(network.AP_IF) + n.active(False) + +def STA(): + sta=network.WLAN(network.STA_IF) + if sta.isconnected(): + return True + sta.active(True) + if ('NetMask') in settings and 'DNS' in settings and 'Gateway' in settings and 'IP' in settings: + print("Static configuration active") + sta.ifconfig((settings["IP"],settings["NetMask"],settings["Gateway"],settings["DNS"])) + else: + print("DHCP active") + sta.connect(settings['ssid'],settings['password']) + timeout=0 + while timeout < 60: + if sta.isconnected(): + return True + else: + time.sleep(1) + timeout += 1 + print("Time waiting: %s sec"%timeout) + sta.active(False) + return False + +def AP(): + ap=network.WLAN(network.AP_IF) + ap.active(True) + ap.config(essid=settings['AP-ssid'],password=settings['AP-password']) + print("AP configured") + +import garage +#garage.run() diff --git a/netstop.py b/netstop.py new file mode 100644 index 0000000..d3a8e33 --- /dev/null +++ b/netstop.py @@ -0,0 +1,5 @@ +import network +n=network.WLAN(network.STA_IF) +n.active(False) +n=network.WLAN(network.AP_IF) +n.active(False) diff --git a/settings.json b/settings.json new file mode 100644 index 0000000..d509101 --- /dev/null +++ b/settings.json @@ -0,0 +1,14 @@ +{"password": "blueground856", + "AP-password": "OpenSesame2020", + "DNS": "8.8.8.8", "IP": + "192.168.1.234", + "AP-ssid": "Georges Garage Door Prototype", + "NetMask": "255.255.255.0", + "buttons": { + "2": {"pin": 3, "delay": 2}, + "1": {"pin": 2, "delay": 2}, + "3": {"pin": 4, "delay": 2}, + }, + "ssid": "BLUEGROUND 856", + "Gateway": "192.168.1.1" + } \ No newline at end of file