Initial commit
Signed-off-by: Thomas Klaehn <tkl@blackfinn.de>
This commit is contained in:
commit
a08243f366
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 *
|
36
README.md
Normal file
36
README.md
Normal file
@ -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
|
||||
```
|
||||
|
17
setup.py
Normal file
17
setup.py
Normal file
@ -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)
|
||||
|
2
weblight/__init__.py
Normal file
2
weblight/__init__.py
Normal file
@ -0,0 +1,2 @@
|
||||
from .app import app
|
||||
|
32
weblight/app.py
Normal file
32
weblight/app.py
Normal file
@ -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('/<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=True, 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