From e7cbbb8226d2d0f74d1f0b4cfa82f767f9c61785 Mon Sep 17 00:00:00 2001
From: Thomas Klaehn
Date: Mon, 18 Jan 2021 09:56:52 +0100
Subject: [PATCH] Initial commit
Signed-off-by: Thomas Klaehn
---
.gitignore | 3 ++
MANIFEST.in | 1 +
build/lib/weblight/__init__.py | 0
build/lib/weblight/__main__.py | 31 +++++++++++++++
build/lib/weblight/templates/index.html | 52 +++++++++++++++++++++++++
build/scripts-3.7/start-weblight | 3 ++
setup.py | 24 ++++++++++++
start-weblight | 3 ++
weblight.service | 10 +++++
weblight/__init__.py | 0
weblight/__main__.py | 31 +++++++++++++++
weblight/templates/index.html | 52 +++++++++++++++++++++++++
12 files changed, 210 insertions(+)
create mode 100644 .gitignore
create mode 100644 MANIFEST.in
create mode 100644 build/lib/weblight/__init__.py
create mode 100644 build/lib/weblight/__main__.py
create mode 100644 build/lib/weblight/templates/index.html
create mode 100755 build/scripts-3.7/start-weblight
create mode 100644 setup.py
create mode 100644 start-weblight
create mode 100644 weblight.service
create mode 100644 weblight/__init__.py
create mode 100644 weblight/__main__.py
create mode 100644 weblight/templates/index.html
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/build/lib/weblight/__init__.py b/build/lib/weblight/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/build/lib/weblight/__main__.py b/build/lib/weblight/__main__.py
new file mode 100644
index 0000000..2dc4dde
--- /dev/null
+++ b/build/lib/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/build/lib/weblight/templates/index.html b/build/lib/weblight/templates/index.html
new file mode 100644
index 0000000..c2a2be7
--- /dev/null
+++ b/build/lib/weblight/templates/index.html
@@ -0,0 +1,52 @@
+
+
+
+ Yard Light
+
+
+
+
+
+ Yard Light
+
+
+
+
+
+
diff --git a/build/scripts-3.7/start-weblight b/build/scripts-3.7/start-weblight
new file mode 100755
index 0000000..d4874f3
--- /dev/null
+++ b/build/scripts-3.7/start-weblight
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+python -m 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
+
+
+
+
+
+