diff --git a/index.html b/index.html deleted file mode 100644 index 77ed309..0000000 --- a/index.html +++ /dev/null @@ -1,54 +0,0 @@ - - - - -Pi-power - socket control - - - - - - - -

Pi power web control

- -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Socket 1OnOff
Socket 2OnOff
Socket 3OnOff
Socket 4OnOff
All socketsOnOff
- - -

Cmd status : ...

- -
- - - - - diff --git a/public/android-icon-144x144.png b/public/android-icon-144x144.png new file mode 100644 index 0000000..28091e9 Binary files /dev/null and b/public/android-icon-144x144.png differ diff --git a/public/android-icon-192x192.png b/public/android-icon-192x192.png new file mode 100644 index 0000000..944b0e4 Binary files /dev/null and b/public/android-icon-192x192.png differ diff --git a/public/android-icon-36x36.png b/public/android-icon-36x36.png new file mode 100644 index 0000000..cbe2f65 Binary files /dev/null and b/public/android-icon-36x36.png differ diff --git a/public/android-icon-48x48.png b/public/android-icon-48x48.png new file mode 100644 index 0000000..8fb6b3c Binary files /dev/null and b/public/android-icon-48x48.png differ diff --git a/public/android-icon-72x72.png b/public/android-icon-72x72.png new file mode 100644 index 0000000..9cdd03c Binary files /dev/null and b/public/android-icon-72x72.png differ diff --git a/public/android-icon-96x96.png b/public/android-icon-96x96.png new file mode 100644 index 0000000..829e89f Binary files /dev/null and b/public/android-icon-96x96.png differ diff --git a/public/apple-icon-114x114.png b/public/apple-icon-114x114.png new file mode 100644 index 0000000..0293108 Binary files /dev/null and b/public/apple-icon-114x114.png differ diff --git a/public/apple-icon-120x120.png b/public/apple-icon-120x120.png new file mode 100644 index 0000000..b4aa84c Binary files /dev/null and b/public/apple-icon-120x120.png differ diff --git a/public/apple-icon-144x144.png b/public/apple-icon-144x144.png new file mode 100644 index 0000000..28091e9 Binary files /dev/null and b/public/apple-icon-144x144.png differ diff --git a/public/apple-icon-152x152.png b/public/apple-icon-152x152.png new file mode 100644 index 0000000..1a25c97 Binary files /dev/null and b/public/apple-icon-152x152.png differ diff --git a/public/apple-icon-180x180.png b/public/apple-icon-180x180.png new file mode 100644 index 0000000..e875b73 Binary files /dev/null and b/public/apple-icon-180x180.png differ diff --git a/public/apple-icon-57x57.png b/public/apple-icon-57x57.png new file mode 100644 index 0000000..4cbb9a6 Binary files /dev/null and b/public/apple-icon-57x57.png differ diff --git a/public/apple-icon-60x60.png b/public/apple-icon-60x60.png new file mode 100644 index 0000000..d7699fb Binary files /dev/null and b/public/apple-icon-60x60.png differ diff --git a/public/apple-icon-72x72.png b/public/apple-icon-72x72.png new file mode 100644 index 0000000..9cdd03c Binary files /dev/null and b/public/apple-icon-72x72.png differ diff --git a/public/apple-icon-76x76.png b/public/apple-icon-76x76.png new file mode 100644 index 0000000..1687bea Binary files /dev/null and b/public/apple-icon-76x76.png differ diff --git a/public/apple-icon-precomposed.png b/public/apple-icon-precomposed.png new file mode 100644 index 0000000..6e9dab9 Binary files /dev/null and b/public/apple-icon-precomposed.png differ diff --git a/public/apple-icon.png b/public/apple-icon.png new file mode 100644 index 0000000..6e9dab9 Binary files /dev/null and b/public/apple-icon.png differ diff --git a/public/browserconfig.xml b/public/browserconfig.xml new file mode 100644 index 0000000..c554148 --- /dev/null +++ b/public/browserconfig.xml @@ -0,0 +1,2 @@ + +#ffffff \ No newline at end of file diff --git a/public/css/pipower.css b/public/css/pipower.css new file mode 100644 index 0000000..9176136 --- /dev/null +++ b/public/css/pipower.css @@ -0,0 +1,29 @@ +#centre { + position:relative; + margin: 20px auto; + width: 90vw; + padding: 20px; + border-radius: 5px; +} + +.buttons { + display: flex; + justify-content: space-around; + flex-wrap: wrap; + margin-top: 20px; + align-items: center; + background-color: aliceblue; + padding: 10px; + border-radius: 10px; + box-shadow: 2px 2px 1px grey; +} + +button { + min-width: 100px; + cursor: pointer; + padding: 10px 20px; +} + +.buttonname { + min-width: 100px; +} diff --git a/public/favicon-16x16.png b/public/favicon-16x16.png new file mode 100644 index 0000000..1c94096 Binary files /dev/null and b/public/favicon-16x16.png differ diff --git a/public/favicon-32x32.png b/public/favicon-32x32.png new file mode 100644 index 0000000..25810ac Binary files /dev/null and b/public/favicon-32x32.png differ diff --git a/public/favicon-96x96.png b/public/favicon-96x96.png new file mode 100644 index 0000000..829e89f Binary files /dev/null and b/public/favicon-96x96.png differ diff --git a/public/favicon.ico b/public/favicon.ico new file mode 100644 index 0000000..f507737 Binary files /dev/null and b/public/favicon.ico differ diff --git a/public/index.html b/public/index.html new file mode 100644 index 0000000..d13bb73 --- /dev/null +++ b/public/index.html @@ -0,0 +1,74 @@ + + + + +Pi-power - socket control + + + + + + + + + + + + + + + + + + + + + + + + + +

Pi power web control

+ +
+ +
+
+ Socket 1 + + +
+
+ Socket 2 + + +
+
+ Socket 3 + + +
+
+ Socket 4 + + +
+
+ All sockets + + +
+
+ + +

Cmd status : ...

+ +
+ + + + + + + + diff --git a/public/jquery.min.js b/public/js/jquery.min.js similarity index 100% rename from public/jquery.min.js rename to public/js/jquery.min.js diff --git a/public/js/pipower.js b/public/js/pipower.js new file mode 100644 index 0000000..c437b3d --- /dev/null +++ b/public/js/pipower.js @@ -0,0 +1,18 @@ +$(document).ready(function() { + // define handlers + $('span[data-cmd]').click(function(){ + var commands = $(this).data().cmd; + console.log(commands, typeof commands); + for (var i = 0; i < commands.length; i++) { + buttonClicked(commands[i][0], commands[i][1]); + } + }); +}); // end ready + +function buttonClicked (type, button) { + $.get ('/switch'+type, 'socket='+button, displayResponse); +} + +function displayResponse (data) { + $('#status').html(data); +} diff --git a/public/manifest.json b/public/manifest.json new file mode 100644 index 0000000..013d4a6 --- /dev/null +++ b/public/manifest.json @@ -0,0 +1,41 @@ +{ + "name": "App", + "icons": [ + { + "src": "\/android-icon-36x36.png", + "sizes": "36x36", + "type": "image\/png", + "density": "0.75" + }, + { + "src": "\/android-icon-48x48.png", + "sizes": "48x48", + "type": "image\/png", + "density": "1.0" + }, + { + "src": "\/android-icon-72x72.png", + "sizes": "72x72", + "type": "image\/png", + "density": "1.5" + }, + { + "src": "\/android-icon-96x96.png", + "sizes": "96x96", + "type": "image\/png", + "density": "2.0" + }, + { + "src": "\/android-icon-144x144.png", + "sizes": "144x144", + "type": "image\/png", + "density": "3.0" + }, + { + "src": "\/android-icon-192x192.png", + "sizes": "192x192", + "type": "image\/png", + "density": "4.0" + } + ] +} \ No newline at end of file diff --git a/public/ms-icon-144x144.png b/public/ms-icon-144x144.png new file mode 100644 index 0000000..28091e9 Binary files /dev/null and b/public/ms-icon-144x144.png differ diff --git a/public/ms-icon-150x150.png b/public/ms-icon-150x150.png new file mode 100644 index 0000000..61bf673 Binary files /dev/null and b/public/ms-icon-150x150.png differ diff --git a/public/ms-icon-310x310.png b/public/ms-icon-310x310.png new file mode 100644 index 0000000..ef5461b Binary files /dev/null and b/public/ms-icon-310x310.png differ diff --git a/public/ms-icon-70x70.png b/public/ms-icon-70x70.png new file mode 100644 index 0000000..d086415 Binary files /dev/null and b/public/ms-icon-70x70.png differ diff --git a/public/offbutton.png b/public/offbutton.png deleted file mode 100644 index 0162298..0000000 Binary files a/public/offbutton.png and /dev/null differ diff --git a/public/onbutton.png b/public/onbutton.png deleted file mode 100644 index 1ff348c..0000000 Binary files a/public/onbutton.png and /dev/null differ diff --git a/public/pipower.css b/public/pipower.css deleted file mode 100644 index 5ce39c5..0000000 --- a/public/pipower.css +++ /dev/null @@ -1,15 +0,0 @@ - - - -div#centre { - position:relative; - margin-left:auto; - margin-right:auto; - top: 20px; - width: 400px; - background-color: #CCCCCC; -} - -.imgonbutton, .imgoffbutton { - cursor: pointer; -} diff --git a/public/pipower.js b/public/pipower.js deleted file mode 100644 index ed6581a..0000000 --- a/public/pipower.js +++ /dev/null @@ -1,39 +0,0 @@ - - -// Use global variable for status so we know if we need to send ajax if change -var button_pressed = ''; - -$(document).ready(function() { -// define handlers -$('#sw_on_1').click(function(){onButtonClicked('1')}); -$('#sw_on_2').click(function(){onButtonClicked('2')}); -$('#sw_on_3').click(function(){onButtonClicked('3')}); -$('#sw_on_4').click(function(){onButtonClicked('4')}); -$('#sw_on_all').click(function(){onButtonClicked('0')}); - -$('#sw_off_1').click(function(){offButtonClicked('1')}); -$('#sw_off_2').click(function(){offButtonClicked('2')}); -$('#sw_off_3').click(function(){offButtonClicked('3')}); -$('#sw_off_4').click(function(){offButtonClicked('4')}); -$('#sw_off_all').click(function(){offButtonClicked('0')}); - - -}); // end ready - - - -// handle on button -function onButtonClicked (button) { - $.get ('/switchon', 'socket='+button, displayResponse); -} - - -// handle off button -function offButtonClicked (button) { - $.get ('/switchoff', 'socket='+button, displayResponse); -} - - -function displayResponse (data) { - $('#status').html(data); -} diff --git a/web-power.py b/web-power.py index bb5ff1d..66c7e49 100755 --- a/web-power.py +++ b/web-power.py @@ -20,6 +20,7 @@ from gpiozero import Energenie import bottle from bottle import route, request, response, template, static_file +import os sockets = [None] sockets.append(Energenie(1)) @@ -35,18 +36,11 @@ # Folder where this is installed and the index.html file is located # The index.html file is exposed to the webserver as well as any files in a subdirectory called public (ie. /home/pi/pi-power/public) -DOCUMENT_ROOT = '/home/pi/pi-power' +DOCUMENT_ROOT = os.path.dirname(os.path.realpath(__file__)) # Create the bottle web server app = bottle.Bottle() - -# public files -# *** WARNING ANYTHING STORED IN THE PUBLIC FOLDER WILL BE AVAILABLE TO DOWNLOAD BY ANYONE CONNECTED TO THE SAME NETWORK *** -@app.route ('/public/') -def server_public (filename): - return static_file (filename, root=DOCUMENT_ROOT+"/public") - # Handle switch on request @app.route ('/switchon') def switchon(): @@ -63,8 +57,7 @@ def switchon(): return 'Requested switch on ALL' else : return 'Invalid request' - - + @app.route ('/switchoff') def switchoff(): socket = int(request.query.socket) @@ -80,11 +73,22 @@ def switchoff(): return 'Requested switch off ALL' else: return 'Invalid request' - + +# public files +# *** WARNING ANYTHING STORED IN THE PUBLIC FOLDER WILL BE AVAILABLE TO DOWNLOAD BY ANYONE CONNECTED TO THE SAME NETWORK *** +@app.route ('/') +def server_public (filename): + return static_file (filename, root=DOCUMENT_ROOT+"/public") +@app.route ('/css/') +def server_public (filename): + return static_file (filename, root=DOCUMENT_ROOT+"/public/css") +@app.route ('/js/') +def server_public (filename): + return static_file (filename, root=DOCUMENT_ROOT+"/public/js") # Serve up the default index.html page @app.route ('/') def server_home (): - return static_file ('index.html', root=DOCUMENT_ROOT) + return static_file ('index.html', root=DOCUMENT_ROOT+"/public") -app.run(host=HOST, port=PORT) \ No newline at end of file +bottle.run(app, host=HOST, port=PORT)