[TASK] Init
This commit is contained in:
commit
8ce8543caa
218
.gitignore
vendored
Normal file
218
.gitignore
vendored
Normal file
@ -0,0 +1,218 @@
|
||||
# Byte-compiled / optimized / DLL files
|
||||
__pycache__/
|
||||
*.py[codz]
|
||||
*$py.class
|
||||
|
||||
# C extensions
|
||||
*.so
|
||||
|
||||
# Distribution / packaging
|
||||
.Python
|
||||
build/
|
||||
develop-eggs/
|
||||
dist/
|
||||
downloads/
|
||||
eggs/
|
||||
.eggs/
|
||||
lib/
|
||||
lib64/
|
||||
parts/
|
||||
sdist/
|
||||
var/
|
||||
wheels/
|
||||
share/python-wheels/
|
||||
*.egg-info/
|
||||
.installed.cfg
|
||||
*.egg
|
||||
MANIFEST
|
||||
|
||||
# PyInstaller
|
||||
# Usually these files are written by a python script from a template
|
||||
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
||||
*.manifest
|
||||
*.spec
|
||||
|
||||
# Installer logs
|
||||
pip-log.txt
|
||||
pip-delete-this-directory.txt
|
||||
|
||||
# Unit test / coverage reports
|
||||
htmlcov/
|
||||
.tox/
|
||||
.nox/
|
||||
.coverage
|
||||
.coverage.*
|
||||
.cache
|
||||
nosetests.xml
|
||||
coverage.xml
|
||||
*.cover
|
||||
*.py.cover
|
||||
.hypothesis/
|
||||
.pytest_cache/
|
||||
cover/
|
||||
|
||||
# Translations
|
||||
*.mo
|
||||
*.pot
|
||||
|
||||
# Django stuff:
|
||||
*.log
|
||||
local_settings.py
|
||||
db.sqlite3
|
||||
db.sqlite3-journal
|
||||
|
||||
# Flask stuff:
|
||||
instance/
|
||||
.webassets-cache
|
||||
|
||||
# Scrapy stuff:
|
||||
.scrapy
|
||||
|
||||
# Sphinx documentation
|
||||
docs/_build/
|
||||
|
||||
# PyBuilder
|
||||
.pybuilder/
|
||||
target/
|
||||
|
||||
# Jupyter Notebook
|
||||
.ipynb_checkpoints
|
||||
|
||||
# IPython
|
||||
profile_default/
|
||||
ipython_config.py
|
||||
|
||||
# pyenv
|
||||
# For a library or package, you might want to ignore these files since the code is
|
||||
# intended to run in multiple environments; otherwise, check them in:
|
||||
# .python-version
|
||||
|
||||
# pipenv
|
||||
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
||||
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
||||
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
||||
# install all needed dependencies.
|
||||
#Pipfile.lock
|
||||
|
||||
# UV
|
||||
# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
|
||||
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
||||
# commonly ignored for libraries.
|
||||
#uv.lock
|
||||
|
||||
# poetry
|
||||
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
||||
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
||||
# commonly ignored for libraries.
|
||||
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
||||
#poetry.lock
|
||||
#poetry.toml
|
||||
|
||||
# pdm
|
||||
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
||||
# pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
|
||||
# https://pdm-project.org/en/latest/usage/project/#working-with-version-control
|
||||
#pdm.lock
|
||||
#pdm.toml
|
||||
.pdm-python
|
||||
.pdm-build/
|
||||
|
||||
# pixi
|
||||
# Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
|
||||
#pixi.lock
|
||||
# Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
|
||||
# in the .venv directory. It is recommended not to include this directory in version control.
|
||||
.pixi
|
||||
|
||||
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
||||
__pypackages__/
|
||||
|
||||
# Celery stuff
|
||||
celerybeat-schedule
|
||||
celerybeat.pid
|
||||
|
||||
# Redis
|
||||
*.rdb
|
||||
*.aof
|
||||
*.pid
|
||||
|
||||
# RabbitMQ
|
||||
mnesia/
|
||||
rabbitmq/
|
||||
rabbitmq-data/
|
||||
|
||||
# ActiveMQ
|
||||
activemq-data/
|
||||
|
||||
# SageMath parsed files
|
||||
*.sage.py
|
||||
|
||||
# Environments
|
||||
.env
|
||||
.envrc
|
||||
.venv
|
||||
env/
|
||||
venv/
|
||||
ENV/
|
||||
env.bak/
|
||||
venv.bak/
|
||||
|
||||
# Spyder project settings
|
||||
.spyderproject
|
||||
.spyproject
|
||||
|
||||
# Rope project settings
|
||||
.ropeproject
|
||||
|
||||
# mkdocs documentation
|
||||
/site
|
||||
|
||||
# mypy
|
||||
.mypy_cache/
|
||||
.dmypy.json
|
||||
dmypy.json
|
||||
|
||||
# Pyre type checker
|
||||
.pyre/
|
||||
|
||||
# pytype static type analyzer
|
||||
.pytype/
|
||||
|
||||
# Cython debug symbols
|
||||
cython_debug/
|
||||
|
||||
# PyCharm
|
||||
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
||||
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
||||
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
||||
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
||||
#.idea/
|
||||
|
||||
# Abstra
|
||||
# Abstra is an AI-powered process automation framework.
|
||||
# Ignore directories containing user credentials, local state, and settings.
|
||||
# Learn more at https://abstra.io/docs
|
||||
.abstra/
|
||||
|
||||
# Visual Studio Code
|
||||
# Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
|
||||
# that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
|
||||
# and can be added to the global gitignore or merged into this file. However, if you prefer,
|
||||
# you could uncomment the following to ignore the entire vscode folder
|
||||
# .vscode/
|
||||
|
||||
# Ruff stuff:
|
||||
.ruff_cache/
|
||||
|
||||
# PyPI configuration file
|
||||
.pypirc
|
||||
|
||||
# Marimo
|
||||
marimo/_static/
|
||||
marimo/_lsp/
|
||||
__marimo__/
|
||||
|
||||
# Streamlit
|
||||
.streamlit/secrets.toml
|
||||
|
||||
/db.json
|
123
app.py
Normal file
123
app.py
Normal file
@ -0,0 +1,123 @@
|
||||
from time import sleep
|
||||
from flask import Flask, render_template, request
|
||||
from blinker import Namespace
|
||||
import threading
|
||||
import RPi.GPIO as GPIO
|
||||
import copy
|
||||
import os
|
||||
from pprint import pprint
|
||||
from datetime import datetime
|
||||
from tinydb import TinyDB, Query
|
||||
|
||||
#RPI_LGPIO_REVISION="800032" entr python app.p
|
||||
#ledpin = 4 # set output LED pin
|
||||
#pushpin = 17 # set input push button pin
|
||||
pushpins = [17, 27, 22, 10, 9, 11, 0, 5]
|
||||
|
||||
app = Flask(__name__)
|
||||
app.jinja_options['variable_start_string'] = '[['
|
||||
app.jinja_options['variable_end_string'] = ']]'
|
||||
|
||||
my_signals = Namespace()
|
||||
value_toggled = my_signals.signal('value-toggled')
|
||||
|
||||
|
||||
db = TinyDB(os.path.dirname(__file__) + '/db.json')
|
||||
DbState = Query()
|
||||
|
||||
class DoorState:
|
||||
door1 = True
|
||||
states = {}
|
||||
heartbeat = 0
|
||||
|
||||
def __init__(self):
|
||||
for i in range(0, 8):
|
||||
self.states[i] = {
|
||||
'closed': False,
|
||||
'date': False,
|
||||
'index': i,
|
||||
}
|
||||
db_item = db.get(DbState.index == i)
|
||||
if db_item:
|
||||
self.states[i] = db_item
|
||||
else:
|
||||
db.insert(self.states[i])
|
||||
|
||||
door_state = DoorState()
|
||||
|
||||
|
||||
@value_toggled.connect
|
||||
def on_value_toggled(sender, pin_states):
|
||||
#door_state.door1 = not door_state.door1
|
||||
#door_state.door1 = pin_state
|
||||
#pprint(pin_states)
|
||||
for i in pin_states:
|
||||
#print(i)
|
||||
#print(pin_states[i])
|
||||
if door_state.states[i]['closed'] == pin_states[i]:
|
||||
door_state.states[i]['closed'] = not pin_states[i]
|
||||
door_state.states[i]['date'] = datetime.now().isoformat()
|
||||
db.update(door_state.states[i], DbState.index == i)
|
||||
|
||||
#pprint(door_state.states)
|
||||
|
||||
thread_event = threading.Event()
|
||||
|
||||
def backgroundTask(signal):
|
||||
while thread_event.is_set():
|
||||
#pin_state = GPIO.input(pushpin)
|
||||
pin_states = {}
|
||||
for i, val in enumerate(pushpins):
|
||||
pin_states[i] = GPIO.input(val)
|
||||
signal.send(app, pin_states=pin_states)
|
||||
sleep(1)
|
||||
|
||||
@app.route('/')
|
||||
def index():
|
||||
return render_template('index.html')
|
||||
|
||||
@app.route('/details')
|
||||
def details():
|
||||
return render_template('details.html')
|
||||
|
||||
@app.route('/status', methods=['GET', 'POST'])
|
||||
def status():
|
||||
data = request.get_json()
|
||||
heartbeat = not data['heartbeat']
|
||||
states = copy.deepcopy(door_state.states)
|
||||
for i in states:
|
||||
if not states[i]['date']:
|
||||
continue
|
||||
date = datetime.fromisoformat(
|
||||
states[i]['date']
|
||||
)
|
||||
date = date.strftime('%d.%m.%Y %H:%M:%S')
|
||||
states[i]['date'] = date
|
||||
return {
|
||||
'states': states,
|
||||
'heartbeat': heartbeat,
|
||||
}
|
||||
|
||||
@app.route('/toggle')
|
||||
def toggle():
|
||||
value_toggled.send(app)
|
||||
return 'OK'
|
||||
|
||||
if __name__ == '__main__':
|
||||
GPIO.setmode(GPIO.BCM)
|
||||
#GPIO.setup(ledpin, GPIO.OUT) # set ledpin as an output
|
||||
#GPIO.setup(pushpin, GPIO.IN, pull_up_down=GPIO.PUD_UP) # with pull up resistor
|
||||
#GPIO.setup(pushpin, GPIO.IN) # with pull up resistor
|
||||
for i, val in enumerate(pushpins):
|
||||
GPIO.setup(val, GPIO.IN, pull_up_down=GPIO.PUD_UP)
|
||||
thread_event.set()
|
||||
thread = threading.Thread(target=backgroundTask, args =(value_toggled, ))
|
||||
thread.daemon = True
|
||||
thread.start()
|
||||
app.run(use_reloader=False, debug=True, host='0.0.0.0')
|
||||
thread_event.clear()
|
||||
|
||||
#while True:
|
||||
# #GPIO.output(ledpin, GPIO.input(pushpin))
|
||||
# print(GPIO.input(pushpin))
|
||||
# sleep(1)
|
3
gunicorn.conf.py
Normal file
3
gunicorn.conf.py
Normal file
@ -0,0 +1,3 @@
|
||||
import app
|
||||
|
||||
on_starting = app.on_starting
|
88
static/app.css
Normal file
88
static/app.css
Normal file
@ -0,0 +1,88 @@
|
||||
/*https://www.color-hex.com/color-palette/23357*/
|
||||
body {
|
||||
margin: 0;
|
||||
background-color: #555;
|
||||
}
|
||||
#app {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
height: 100vh;
|
||||
}
|
||||
.heartbeats {
|
||||
display: flex;
|
||||
flex: 10px 0 0;
|
||||
}
|
||||
.heartbeat {
|
||||
/*background-color: #4f5d75;*/
|
||||
background-color: #2d3142;
|
||||
height: 10px;
|
||||
flex: 50% 0 0;
|
||||
/*outline: 1px solid #4f5d75;*/
|
||||
outline: 1px solid #2d3142;
|
||||
z-index: 10;
|
||||
}
|
||||
.heartbeat.active {
|
||||
background-color: #bfc0c0;
|
||||
outline: 1px solid #bfc0c0;
|
||||
}
|
||||
.statusblocks {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
flex: 1;
|
||||
}
|
||||
.statusblock {
|
||||
flex: 25% 0 0;
|
||||
background-color: #BE452F;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
color: #fff;
|
||||
font-size: 15vw;
|
||||
outline: 1px solid rgba(181, 165, 150, 0.40);
|
||||
font-weight: bold;
|
||||
}
|
||||
.statusblock.closed {
|
||||
background-color: #1B4D3E;
|
||||
}
|
||||
.statusblock div {
|
||||
|
||||
}
|
||||
.statusrows {
|
||||
width: 100%;
|
||||
display: grid;
|
||||
grid-template-columns: repeat(3, 1fr);
|
||||
grid-template-rows: repeat(8, 1fr);
|
||||
grid-column-gap: 0px;
|
||||
grid-row-gap: 0px;
|
||||
position: absolute;
|
||||
top: 10px;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
}
|
||||
.statusrow {
|
||||
/*display: flex;*/
|
||||
background-color: #BE452F;
|
||||
color: #fff;
|
||||
font-weight: bold;
|
||||
position: relative;
|
||||
}
|
||||
.statusrow.closed {
|
||||
background-color: #1B4D3E;
|
||||
}
|
||||
.statusrow > div {
|
||||
/*flex: 33%;*/
|
||||
border-bottom: 1px solid #555;
|
||||
text-align: center;
|
||||
padding: 10px 20px;
|
||||
position: absolute;
|
||||
top: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
.statusrow > div > div {
|
||||
}
|
3
static/axios.min.js
vendored
Normal file
3
static/axios.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
60
static/index.js
Normal file
60
static/index.js
Normal file
@ -0,0 +1,60 @@
|
||||
const { createApp } = Vue
|
||||
createApp({
|
||||
data() {
|
||||
return {
|
||||
message: 'Hello Vue!',
|
||||
//state: 'undefined',
|
||||
heartbeat: false,
|
||||
states: {},
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
heartbeatActive: function (index) {
|
||||
if (index == this.heartbeat) {
|
||||
return 'active';
|
||||
}
|
||||
return '';
|
||||
},
|
||||
statusblockClosed: function (index) {
|
||||
if (this.states[index].closed == true) {
|
||||
return 'closed';
|
||||
}
|
||||
return '';
|
||||
},
|
||||
update: function () {
|
||||
axios.post('/status', {
|
||||
heartbeat: this.heartbeat,
|
||||
})
|
||||
.then((response) => {
|
||||
// handle success
|
||||
//this.state = response.data.state;
|
||||
this.heartbeat = response.data.heartbeat;
|
||||
let states = response.data.states
|
||||
//for (var key in states) {
|
||||
// if (!states[key]['date']) {
|
||||
// continue;
|
||||
// }
|
||||
// let date = new Date(states[key]['date']);
|
||||
// states[key]['date'] = date;
|
||||
//}
|
||||
this.states = states;
|
||||
|
||||
console.debug(response.data.states);
|
||||
//console.log(response.data);
|
||||
})
|
||||
.catch(function (error) {
|
||||
// handle error
|
||||
console.log(error);
|
||||
})
|
||||
.finally(function () {
|
||||
// always executed
|
||||
});
|
||||
},
|
||||
},
|
||||
mounted: function() {
|
||||
this.update();
|
||||
setInterval(() => {
|
||||
this.update();
|
||||
}, 2000);
|
||||
}
|
||||
}).mount('#app')
|
18193
static/vue.global.js
Normal file
18193
static/vue.global.js
Normal file
File diff suppressed because it is too large
Load Diff
66
templates/details.html
Normal file
66
templates/details.html
Normal file
@ -0,0 +1,66 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title></title>
|
||||
<meta name="author" content="">
|
||||
<meta name="description" content="">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<link
|
||||
rel="stylesheet"
|
||||
type="text/css"
|
||||
href="[[ url_for('static', filename='app.css') ]]"
|
||||
>
|
||||
<style>
|
||||
html {
|
||||
font-family: 'DejaVu Sans', sans-serif;
|
||||
}
|
||||
svg {
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div id="app" class="details">
|
||||
<div class="heartbeats">
|
||||
<div :class="['heartbeat', 'heartbeat-0', heartbeatActive(0)]">
|
||||
</div>
|
||||
<div :class="['heartbeat', 'heartbeat-1', heartbeatActive(1)]">
|
||||
</div>
|
||||
</div>
|
||||
<div class="statusrows">
|
||||
<template
|
||||
v-for="(state, index) in states"
|
||||
:class="['statusrow', statusblockClosed(index)]"
|
||||
>
|
||||
<div :class="['statusrow', statusblockClosed(index)]">
|
||||
<div>
|
||||
Tor {{ parseInt(index) + 1 }}
|
||||
</div>
|
||||
</div>
|
||||
<div :class="['statusrow', statusblockClosed(index)]">
|
||||
<div v-if="state.closed">
|
||||
geschlossen
|
||||
</div>
|
||||
<div v-else>
|
||||
offen
|
||||
</div>
|
||||
</div>
|
||||
<div :class="['statusrow', statusblockClosed(index)]">
|
||||
<div v-if="state.date">
|
||||
{{ state.date }}
|
||||
</div>
|
||||
<div v-else>
|
||||
-
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
<!--<div>-->
|
||||
<!-- security.mixed_content.block_active_content-->
|
||||
<!--</div>-->
|
||||
</div>
|
||||
<script src="[[ url_for('static', filename='vue.global.js') ]]"></script>
|
||||
<script src="[[ url_for('static', filename='axios.min.js') ]]"></script>
|
||||
<script src="[[ url_for('static', filename='index.js') ]]"></script>
|
||||
</body>
|
||||
</html>
|
48
templates/index.html
Normal file
48
templates/index.html
Normal file
@ -0,0 +1,48 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title></title>
|
||||
<meta name="author" content="">
|
||||
<meta name="description" content="">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<link
|
||||
rel="stylesheet"
|
||||
type="text/css"
|
||||
href="[[ url_for('static', filename='app.css') ]]"
|
||||
>
|
||||
<style>
|
||||
html {
|
||||
font-family: 'DejaVu Sans', sans-serif;
|
||||
}
|
||||
svg {
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div id="app" class="index">
|
||||
<div class="heartbeats">
|
||||
<div :class="['heartbeat', 'heartbeat-0', heartbeatActive(0)]">
|
||||
</div>
|
||||
<div :class="['heartbeat', 'heartbeat-1', heartbeatActive(1)]">
|
||||
</div>
|
||||
</div>
|
||||
<div class="statusblocks">
|
||||
<div
|
||||
v-for="(state, index) in states"
|
||||
:class="['statusblock', statusblockClosed(index)]"
|
||||
>
|
||||
<div>
|
||||
{{ parseInt(index) + 1 }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!--<div>-->
|
||||
<!-- security.mixed_content.block_active_content-->
|
||||
<!--</div>-->
|
||||
</div>
|
||||
<script src="[[ url_for('static', filename='vue.global.js') ]]"></script>
|
||||
<script src="[[ url_for('static', filename='axios.min.js') ]]"></script>
|
||||
<script src="[[ url_for('static', filename='index.js') ]]"></script>
|
||||
</body>
|
||||
</html>
|
Loading…
x
Reference in New Issue
Block a user