Initial commit

This commit is contained in:
2020-08-25 20:25:20 +03:00
commit 799de0c306
6 changed files with 102 additions and 0 deletions

9
boot.py Normal file
View File

@@ -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()

BIN
firmware_esp8266-v1.3.5.bin Normal file

Binary file not shown.

32
garage.py Normal file
View File

@@ -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('<html><body><h1>Hi George!</h1><a href="button/1">Push the garage door button</a></html>\n')
# Another one, more complicated page
@app.route('/button/<nr>')
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('<html><body><h1>Hi George!</h1>Button number %s pushed. <a href="/">Go back.</a> <a href="button">Or push it again.</a></html>\n'%nr)
def run():
print ("running app")
app.run(host='0.0.0.0', port=80)

42
main.py Normal file
View File

@@ -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()

5
netstop.py Normal file
View File

@@ -0,0 +1,5 @@
import network
n=network.WLAN(network.STA_IF)
n.active(False)

14
settings.json Normal file
View File

@@ -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": {