diff --git a/garage.py b/IOTdevice.py similarity index 81% rename from garage.py rename to IOTdevice.py index b6aac84..80bd9b0 100644 --- a/garage.py +++ b/IOTdevice.py @@ -8,6 +8,8 @@ settings=json.loads(''.join(open('settings.json').readlines())) # Create web server application app = tinyweb.webserver() + +# Hardware Setup, e.g. Garage Door Remote Button={} for name in settings["buttons"].keys(): Button[name]=Pin(settings["buttons"][name]["pin"],Pin.OUT) @@ -18,10 +20,10 @@ for name in settings["buttons"].keys(): async def index(request, response): # Start HTTP response with content-type text/html await response.start_html() - # Send actual HTML page + # Send actual HTML page, in this example with three buttons await response.send(''' -

George\'s Garage

+

Garage Door Remote

@@ -29,22 +31,23 @@ async def index(request, response): @app.route('/reset') async def index(request, response): - # Start HTTP response with content-type text/html await response.start_html() - # Send actual HTML page await response.send(''' -

|RESETTING...

+

RESETTING...

\n''') reset() @app.route('/button/') async def button(request, response,nr): # Start HTTP response with content-type text/html + # Machine control Button[nr].on() sleep(settings['buttons'][nr]['delay']) Button[str(nr)].off() + # Debug string print ('button %s (Pin %s) pressed for %s seconds'%(nr,Button[nr],settings['buttons'][nr]['delay'])) + #Send response await response.start_html() await response.send('

Hi George!

Button number %s pushed for %s seconds. Go back.\n'%(nr,settings['buttons'][str(nr)]['delay'])) @@ -76,21 +79,8 @@ class config(): Write_Settings() return data -#await response.start_html() -# print (request.query_string) -# a=tinyweb.server.parse_query_string(request.query_string) -# print (a) -# configs=str(a) -# await response.send(configs) - def run(): print ("running app") app.add_resource(config,"/config") app.run(host='0.0.0.0', port=80) - -# -# form='''

Settings

''' -# form += ""%settings['AP-ssid'] -# form +="
AP-ssid%s
" -# return form \ No newline at end of file diff --git a/main.py b/main.py index 6c4df38..f4d9647 100644 --- a/main.py +++ b/main.py @@ -3,7 +3,7 @@ import json import time from machine import Pin import LED -import garage +import IOTdevice #import settings settings=json.loads(''.join(open('settings.json').readlines())) @@ -50,4 +50,4 @@ def AP(): netstop() if STA() != True: AP() -garage.run() +IOTdevice.run()