commit a08243f366689ffc2e980f4af0647944c212fd28 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..2d88b0d --- /dev/null +++ b/README.md @@ -0,0 +1,36 @@ +# Weblight + +Tool to switch on/off the yard light with web page. + +## Installation + +```shell +python setup.py install +``` + +## Usage + +### Manual + +Create wrapper script (e.g. wrapper.py): + +```python +from weblight import app + +if __name__ == "__main__": + app.run() + +``` + +Execute the wrapper script: + +```shell +python3 wrapper.py +``` + +### gunicorn + +```shell +gunicorn --bind 0.0.0.0:80 weblight:app +``` + diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..c0cbd08 --- /dev/null +++ b/setup.py @@ -0,0 +1,17 @@ +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'] +REQUIRES = ['Flask', 'RPi.GPIO'] + + +setup(name=NAME, version=VERSION, long_description=__doc__, author=AUTHOR, author_email=EMAIL, + packages=PACKAGES, include_package_data=True, zip_safe=False, install_requires=REQUIRES) + diff --git a/weblight/__init__.py b/weblight/__init__.py new file mode 100644 index 0000000..0ccc333 --- /dev/null +++ b/weblight/__init__.py @@ -0,0 +1,2 @@ +from .app import app + diff --git a/weblight/app.py b/weblight/app.py new file mode 100644 index 0000000..9ff3fa4 --- /dev/null +++ b/weblight/app.py @@ -0,0 +1,32 @@ +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.setwarnings(False) +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=True, 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

+

+

+

+
+
+

+
+

+ +