Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 0 additions & 54 deletions index.html

This file was deleted.

Binary file added public/android-icon-144x144.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/android-icon-192x192.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/android-icon-36x36.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/android-icon-48x48.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/android-icon-72x72.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/android-icon-96x96.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/apple-icon-114x114.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/apple-icon-120x120.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/apple-icon-144x144.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/apple-icon-152x152.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/apple-icon-180x180.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/apple-icon-57x57.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/apple-icon-60x60.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/apple-icon-72x72.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/apple-icon-76x76.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/apple-icon-precomposed.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/apple-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions public/browserconfig.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="utf-8"?>
<browserconfig><msapplication><tile><square70x70logo src="/ms-icon-70x70.png"/><square150x150logo src="/ms-icon-150x150.png"/><square310x310logo src="/ms-icon-310x310.png"/><TileColor>#ffffff</TileColor></tile></msapplication></browserconfig>
29 changes: 29 additions & 0 deletions public/css/pipower.css
Original file line number Diff line number Diff line change
@@ -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;
}
Binary file added public/favicon-16x16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/favicon-32x32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/favicon-96x96.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/favicon.ico
Binary file not shown.
74 changes: 74 additions & 0 deletions public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Pi-power - socket control</title>
<link href="css/pipower.css" rel="stylesheet" type="text/css">

<meta name="viewport" content="width=device-width, initial-scale=1">

<link rel="apple-touch-icon" sizes="57x57" href="/apple-icon-57x57.png">
<link rel="apple-touch-icon" sizes="60x60" href="/apple-icon-60x60.png">
<link rel="apple-touch-icon" sizes="72x72" href="/apple-icon-72x72.png">
<link rel="apple-touch-icon" sizes="76x76" href="/apple-icon-76x76.png">
<link rel="apple-touch-icon" sizes="114x114" href="/apple-icon-114x114.png">
<link rel="apple-touch-icon" sizes="120x120" href="/apple-icon-120x120.png">
<link rel="apple-touch-icon" sizes="144x144" href="/apple-icon-144x144.png">
<link rel="apple-touch-icon" sizes="152x152" href="/apple-icon-152x152.png">
<link rel="apple-touch-icon" sizes="180x180" href="/apple-icon-180x180.png">
<link rel="icon" type="image/png" sizes="192x192" href="/android-icon-192x192.png">
<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="96x96" href="/favicon-96x96.png">
<link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png">
<link rel="manifest" href="/manifest.json">
<meta name="msapplication-TileColor" content="#ffffff">
<meta name="msapplication-TileImage" content="/ms-icon-144x144.png">
<meta name="theme-color" content="#ffffff">

</head>
<body>

<h1>Pi power web control</h1>

<div id="centre">

<div>
<div class="buttons">
<span class="buttonname">Socket 1</span>
<span class="onbutton" data-cmd='[["on", 1]]'><button>On</button></span>
<span class="offbutton" data-cmd='[["off", 1]]'><button>Off</button></span>
</div>
<div class="buttons">
<span class="buttonname">Socket 2</span>
<span class="onbutton" data-cmd='[["on", 2]]'><button>On</button></span>
<span class="offbutton" data-cmd='[["off", 2]]'><button>Off</button></span>
</div>
<div class="buttons">
<span class="buttonname">Socket 3</span>
<span class="onbutton" data-cmd='[["on", 3]]'><button>On</button></span>
<span class="offbutton" data-cmd='[["off", 3]]'><button>Off</button></span>
</div>
<div class="buttons">
<span class="buttonname">Socket 4</span>
<span class="onbutton" data-cmd='[["on", 4]]'><button>On</button></span>
<span class="offbutton" data-cmd='[["off", 4]]'><button>Off</button></span>
</div>
<div class="buttons">
<span class="buttonname">All sockets</span>
<span class="onbutton" data-cmd='[["on", 0]]'><button>On</button></span>
<span class="offbutton" data-cmd='[["off", 0]]'><button>Off</button></span>
</div>
</div>


<p>Cmd status : <span id="status">...</span></p>

</div>


<!-- Add Jquery -->
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/pipower.js"></script>

</body>
</html>
File renamed without changes.
18 changes: 18 additions & 0 deletions public/js/pipower.js
Original file line number Diff line number Diff line change
@@ -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);
}
41 changes: 41 additions & 0 deletions public/manifest.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
}
Binary file added public/ms-icon-144x144.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/ms-icon-150x150.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/ms-icon-310x310.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/ms-icon-70x70.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed public/offbutton.png
Binary file not shown.
Binary file removed public/onbutton.png
Diff not rendered.
15 changes: 0 additions & 15 deletions public/pipower.css

This file was deleted.

39 changes: 0 additions & 39 deletions public/pipower.js

This file was deleted.

30 changes: 17 additions & 13 deletions web-power.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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/<filename>')
def server_public (filename):
return static_file (filename, root=DOCUMENT_ROOT+"/public")

# Handle switch on request
@app.route ('/switchon')
def switchon():
Expand All @@ -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)
Expand All @@ -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 ('/<filename>')
def server_public (filename):
return static_file (filename, root=DOCUMENT_ROOT+"/public")
@app.route ('/css/<filename>')
def server_public (filename):
return static_file (filename, root=DOCUMENT_ROOT+"/public/css")
@app.route ('/js/<filename>')
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)
bottle.run(app, host=HOST, port=PORT)