Initial commit
Signed-off-by: Thomas Klaehn <tkl@blackfinn.de>
This commit is contained in:
commit
78dca5c559
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
__pycache__
|
||||||
|
|
||||||
|
dist/
|
1
MANIFEST.in
Normal file
1
MANIFEST.in
Normal file
@ -0,0 +1 @@
|
|||||||
|
recursive-include weblight/templates *
|
24
setup.py
Normal file
24
setup.py
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
import sys
|
||||||
|
import os
|
||||||
|
import shutil
|
||||||
|
import stat
|
||||||
|
from setuptools import setup
|
||||||
|
|
||||||
|
NAME = 'Web Light'
|
||||||
|
VERSION = '1'
|
||||||
|
AUTHOR = 'Thomas Klaehn'
|
||||||
|
EMAIL = 'tkl@blackfinn.de'
|
||||||
|
PACKAGES = ['weblight']
|
||||||
|
SCRIPTS = ['start-weblight']
|
||||||
|
SERVICEDIR = "/lib/systemd/system"
|
||||||
|
REQUIRES = ['Flask']
|
||||||
|
DAEMON_START_SCRIPT = os.path.join(SERVICEDIR, 'weblight.service')
|
||||||
|
|
||||||
|
if sys.argv[1] == 'install':
|
||||||
|
os.makedirs(SERVICEDIR, exist_ok=True)
|
||||||
|
shutil.copyfile('weblight.service', DAEMON_START_SCRIPT)
|
||||||
|
os.chmod(DAEMON_START_SCRIPT, stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP | stat.S_IROTH)
|
||||||
|
|
||||||
|
setup(name=NAME, version=VERSION, long_description=__doc__, author=AUTHOR, author_email=EMAIL,
|
||||||
|
packages=PACKAGES, scripts=SCRIPTS, include_package_data=True, zip_safe=False,
|
||||||
|
install_requires=REQUIRES)
|
3
start-weblight
Normal file
3
start-weblight
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
python -m weblight $@
|
10
weblight.service
Normal file
10
weblight.service
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=Weblight
|
||||||
|
After=multi-user.target
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=idle
|
||||||
|
ExecStart=/usr/local/bin/start-weblight
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
0
weblight/__init__.py
Normal file
0
weblight/__init__.py
Normal file
31
weblight/__main__.py
Normal file
31
weblight/__main__.py
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
from flask import Flask
|
||||||
|
from flask import render_template
|
||||||
|
from flask import redirect
|
||||||
|
from flask import url_for
|
||||||
|
from flask import make_response
|
||||||
|
|
||||||
|
import RPi.GPIO as GPIO
|
||||||
|
|
||||||
|
RELAY_1 = 26
|
||||||
|
|
||||||
|
GPIO.setmode(GPIO.BCM)
|
||||||
|
GPIO.setup(RELAY_1,GPIO.OUT)
|
||||||
|
|
||||||
|
app = Flask(__name__)
|
||||||
|
|
||||||
|
@app.route('/')
|
||||||
|
def index():
|
||||||
|
return render_template('index.html')
|
||||||
|
|
||||||
|
@app.route('/<state>', methods=['POST'])
|
||||||
|
def reroute(state):
|
||||||
|
if state == 'on':
|
||||||
|
GPIO.output(RELAY_1, 0)
|
||||||
|
else:
|
||||||
|
GPIO.output(RELAY_1, 1)
|
||||||
|
|
||||||
|
response = make_response(redirect(url_for('index')))
|
||||||
|
return response
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
app.run(debug=False, host='0.0.0.0', port=8000)
|
52
weblight/templates/index.html
Normal file
52
weblight/templates/index.html
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Yard Light</title>
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
|
<style>
|
||||||
|
html, body {
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
font-size: 18px !important;
|
||||||
|
font-family: 'Muli', arial, verdana, helvetica, sans-serif;
|
||||||
|
font-weight: 300;
|
||||||
|
font-style: normal;
|
||||||
|
height: 100%;
|
||||||
|
color: #b6b6b6;
|
||||||
|
background: #282929;
|
||||||
|
}
|
||||||
|
|
||||||
|
body {
|
||||||
|
display:flex;
|
||||||
|
flex-direction:column;
|
||||||
|
}
|
||||||
|
|
||||||
|
h1 {text-align: center;}
|
||||||
|
p {text-align: center;}
|
||||||
|
div {text-align: center;}
|
||||||
|
|
||||||
|
.button {
|
||||||
|
color: #b6b6b6;
|
||||||
|
background-color: #3d5f69;
|
||||||
|
padding: 10px;
|
||||||
|
margin: 10px 0;
|
||||||
|
border: none;
|
||||||
|
border-radius: 8px;
|
||||||
|
font-size: 1.2rem;
|
||||||
|
width: 12rem;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<h1>Yard Light</h1>
|
||||||
|
<p>
|
||||||
|
<form action="/on" method="POST">
|
||||||
|
<div><button class="button">On</button></div><br>
|
||||||
|
</form>
|
||||||
|
<form action="/off" method="POST">
|
||||||
|
<div><button class="button">Off</button></div><br>
|
||||||
|
</form>
|
||||||
|
</p>
|
||||||
|
</body>
|
||||||
|
</html>
|
Loading…
Reference in New Issue
Block a user