commit c1f433090f19f512ad96568d6e0e3310eace4560 Author: Thomas Klaehn Date: Mon Jan 18 09:56:52 2021 +0100 Initial commit Signed-off-by: Thomas Klaehn diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5c80531 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +__pycache__ + +dist/ diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 0000000..84dae5c --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1 @@ +recursive-include weblight/templates * diff --git a/README.md b/README.md new file mode 100644 index 0000000..d6fb6bb --- /dev/null +++ b/README.md @@ -0,0 +1,24 @@ +# Weblight + +Tool to switch on/off the yard light with web page. + +## Installation + +```shell +python setup.py install +``` + +## Usage + +### Manual + +```shell +start-weblight +``` + +### systemd + +```shell +$ systemctl enable weblight +$ systemctl start weblight +``` diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..0499cfd --- /dev/null +++ b/setup.py @@ -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) diff --git a/start-weblight b/start-weblight new file mode 100644 index 0000000..d4874f3 --- /dev/null +++ b/start-weblight @@ -0,0 +1,3 @@ +#!/bin/bash + +python -m weblight $@ diff --git a/weblight.service b/weblight.service new file mode 100644 index 0000000..746c947 --- /dev/null +++ b/weblight.service @@ -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 diff --git a/weblight/__init__.py b/weblight/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/weblight/__main__.py b/weblight/__main__.py new file mode 100644 index 0000000..2dc4dde --- /dev/null +++ b/weblight/__main__.py @@ -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('/', 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) diff --git a/weblight/templates/index.html b/weblight/templates/index.html new file mode 100644 index 0000000..c2a2be7 --- /dev/null +++ b/weblight/templates/index.html @@ -0,0 +1,52 @@ + + + + Yard Light + + + + + +

Yard Light

+

+

+

+
+
+

+
+

+ +