Initial commit
This commit is contained in:
commit
a5b5637cfe
27
.vscode/launch.json
vendored
Normal file
27
.vscode/launch.json
vendored
Normal file
@ -0,0 +1,27 @@
|
||||
{
|
||||
// Use IntelliSense to learn about possible attributes.
|
||||
// Hover to view descriptions of existing attributes.
|
||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "Python: Flask",
|
||||
"type": "python",
|
||||
"request": "launch",
|
||||
"module": "flask",
|
||||
"env": {
|
||||
"FLASK_APP": "gardenui/app.py",
|
||||
"FLASK_ENV": "development",
|
||||
"FLASK_DEBUG": "0"
|
||||
},
|
||||
"args": [
|
||||
"run",
|
||||
"--no-debugger",
|
||||
"--no-reload",
|
||||
"--host=0.0.0.0",
|
||||
"--port=8000"
|
||||
],
|
||||
"jinja": true
|
||||
}
|
||||
]
|
||||
}
|
10
gardenui.service
Normal file
10
gardenui.service
Normal file
@ -0,0 +1,10 @@
|
||||
[Unit]
|
||||
Description=Garden UI service
|
||||
After=multi-user.target gardencontrol.service
|
||||
|
||||
[Service]
|
||||
Type=idle
|
||||
ExecStart=gunicorn --bind 0.0.0.0:80 gardenui:app
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
2
gardenui/__init__.py
Normal file
2
gardenui/__init__.py
Normal file
@ -0,0 +1,2 @@
|
||||
from .app import app
|
||||
|
BIN
gardenui/__pycache__/app.cpython-37.pyc
Normal file
BIN
gardenui/__pycache__/app.cpython-37.pyc
Normal file
Binary file not shown.
161
gardenui/app.py
Normal file
161
gardenui/app.py
Normal file
@ -0,0 +1,161 @@
|
||||
|
||||
import json
|
||||
import logging
|
||||
import xmlrpc.client
|
||||
|
||||
from flask import Flask
|
||||
from flask import render_template
|
||||
from flask import make_response
|
||||
from flask import request
|
||||
from flask import jsonify
|
||||
|
||||
LOG_LEVEL = logging.INFO
|
||||
LOG_FILE = "/var/log/sauna.log"
|
||||
LOG_FORMAT = "%(asctime)s %(levelname)s %(message)s"
|
||||
|
||||
URL = 'http://{}:{}'.format('localhost', 64001)
|
||||
|
||||
# logging.basicConfig(format=LOG_FORMAT, level=LOG_LEVEL, filename=LOG_FILE)
|
||||
logging.basicConfig(format=LOG_FORMAT, level=LOG_LEVEL)
|
||||
log = logging.getLogger()
|
||||
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
@app.route('/')
|
||||
def index():
|
||||
return render_template('index.html')
|
||||
|
||||
@app.route('/garden')
|
||||
def garden():
|
||||
return render_template('garden.html')
|
||||
|
||||
@app.route('/greenhouse_1')
|
||||
def greenhouse_1():
|
||||
return render_template('greenhouse_1.html')
|
||||
|
||||
@app.route('/greenhouse_2')
|
||||
def greenhouse_2():
|
||||
return render_template('greenhouse_2.html')
|
||||
|
||||
@app.route('/sample/<idx>', methods=['GET'])
|
||||
def get_sample(idx='0'):
|
||||
idx = int(idx)
|
||||
res = {}
|
||||
client = xmlrpc.client.ServerProxy(URL)
|
||||
|
||||
if idx == 1:
|
||||
heat = {}
|
||||
heat['id'] = str(idx)
|
||||
heat['state'] = client.get_current_heat_state(idx)
|
||||
temp = client.get_current_temperature(idx)
|
||||
if temp:
|
||||
temperature = {}
|
||||
temperature['id'] = str(idx)
|
||||
temperature['value'] = temp
|
||||
res['heat'] = heat
|
||||
res['temperature'] = temperature
|
||||
|
||||
water = {}
|
||||
water['id'] = str(idx)
|
||||
water['state'] = client.get_current_water_state(idx)
|
||||
res['water'] = water
|
||||
|
||||
return make_response(jsonify(res), 200)
|
||||
|
||||
@app.route('/config/<idx>', methods=['GET'])
|
||||
def get_config(idx='0'):
|
||||
idx = int(idx)
|
||||
res = {}
|
||||
client = xmlrpc.client.ServerProxy(URL)
|
||||
|
||||
if idx == 1:
|
||||
heat = {}
|
||||
heat['id'] = str(idx)
|
||||
heat['autostate'] = client.get_heat_autostate(idx)
|
||||
heat['on_temperature'] = client.get_on_temperature(idx)
|
||||
heat['off_temperature'] = client.get_off_temperature(idx)
|
||||
res['heat'] = heat
|
||||
|
||||
water = {}
|
||||
water['id'] = str(idx)
|
||||
water['autostate'] = client.get_water_autostate(idx)
|
||||
water['times'] = client.get_water_times(idx)
|
||||
res['water'] = water
|
||||
|
||||
return make_response(jsonify(res), 200)
|
||||
|
||||
|
||||
@app.route('/sample', methods=['PATCH'])
|
||||
def patch_sample():
|
||||
client = xmlrpc.client.ServerProxy(URL)
|
||||
record = json.loads(request.data)
|
||||
if 'id' in record and record['id'] == '1':
|
||||
if 'heatstate' in record:
|
||||
if record['heatstate']:
|
||||
client.set_heat_state(record['id'])
|
||||
else:
|
||||
client.clear_heat_state(record['id'])
|
||||
if 'id' in record and 'waterstate' in record:
|
||||
if record['waterstate']:
|
||||
client.set_water_state(record['id'])
|
||||
else:
|
||||
client.clear_water_state(record['id'])
|
||||
return make_response("", 204)
|
||||
|
||||
|
||||
@app.route('/config', methods=['PATCH'])
|
||||
def patch_config():
|
||||
client = xmlrpc.client.ServerProxy(URL)
|
||||
record = json.loads(request.data)
|
||||
if 'water' in record:
|
||||
water = record['water']
|
||||
if 'autostate' in water:
|
||||
if water['autostate']:
|
||||
client.set_water_autostate(water['id'])
|
||||
else:
|
||||
client.clear_water_autostate(water['id'])
|
||||
if 'times' in water:
|
||||
client.set_water_times(water['id'], water['times'])
|
||||
if 'heat' in record:
|
||||
if 'id' in record['heat'] and record['heat']['id'] == '1':
|
||||
if 'autostate' in record['heat']:
|
||||
if record['heat']['autostate']:
|
||||
client.set_heat_autostate('1')
|
||||
else:
|
||||
client.clear_heat_autostate('1')
|
||||
if 'increase_on_temperature' in record['heat']:
|
||||
if record['heat']['increase_on_temperature']:
|
||||
client.increase_on_temperature('1')
|
||||
if 'decrease_on_temperature' in record['heat']:
|
||||
if record['heat']['decrease_on_temperature']:
|
||||
client.decrease_on_temperature('1')
|
||||
if 'increase_off_temperature' in record['heat']:
|
||||
if record['heat']['increase_off_temperature']:
|
||||
client.increase_off_temperature('1')
|
||||
if 'decrease_off_temperature' in record['heat']:
|
||||
if record['heat']['decrease_off_temperature']:
|
||||
client.decrease_off_temperature('1')
|
||||
|
||||
# prepare answer
|
||||
res = {}
|
||||
if 'heat' in record and record['heat']['id'] == '1':
|
||||
heat = {}
|
||||
heat['id'] = '1'
|
||||
heat['autostate'] = client.get_heat_autostate(1)
|
||||
heat['on_temperature'] = client.get_on_temperature(1)
|
||||
heat['off_temperature'] = client.get_off_temperature(1)
|
||||
res['heat'] = heat
|
||||
if 'water' in record:
|
||||
water = {}
|
||||
water['id'] = record['water']['id']
|
||||
water['autostate'] = client.get_water_autostate(int(record['water']['id']))
|
||||
water['times'] = client.get_water_times(int(record['water']['id']))
|
||||
res['water'] = water
|
||||
|
||||
|
||||
return make_response(jsonify(res), 200)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run(debug=True, host='0.0.0.0', port=8000)
|
73
gardenui/static/css/style.css
Normal file
73
gardenui/static/css/style.css
Normal file
@ -0,0 +1,73 @@
|
||||
html, body {
|
||||
font-size: 22px !important;
|
||||
font-family: arial, verdana, helvetica, sans-serif;
|
||||
color: #b6b6b6;
|
||||
background: #282929;
|
||||
}
|
||||
|
||||
h1, h2, h3 {text-align: center;}
|
||||
p {text-align: center;}
|
||||
div {text-align: center;}
|
||||
|
||||
.center {
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
input {
|
||||
border: 1px #999999 solid;
|
||||
background-color: #f6f6f6;
|
||||
padding: 2px 4px 2px 4px;
|
||||
margin: 0 0 0.5rem 0;
|
||||
font-size: 1.0rem;
|
||||
border-radius: 8px;
|
||||
}
|
||||
|
||||
input[type="submit" i] {
|
||||
color: #b6b6b6;
|
||||
background-color: #282929;
|
||||
padding: 10px;
|
||||
margin: 10px 0;
|
||||
border-color: #b6b6b6;
|
||||
border-width: 3px;
|
||||
border-radius: 18px;
|
||||
font-size: 20px;
|
||||
}
|
||||
|
||||
input[type="text"] {
|
||||
border-radius: 8px;
|
||||
}
|
||||
|
||||
td {
|
||||
padding: 8px;
|
||||
}
|
||||
|
||||
.table_left {
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
footer {
|
||||
position: fixed;
|
||||
/* left: 50%; */
|
||||
bottom: 20px;
|
||||
/* transform: translate(-50%, -50%); */
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
a {
|
||||
outline: none;
|
||||
color: #b6b6b6;
|
||||
text-decoration-line: none;
|
||||
}
|
||||
|
||||
select {
|
||||
color: #b6b6b6;
|
||||
background-color: #282929;
|
||||
padding: 10px;
|
||||
margin: 10px 0;
|
||||
border-color: #b6b6b6;
|
||||
border-width: 3px;
|
||||
border-radius: 16px;
|
||||
font-size: 20px;
|
||||
}
|
116
gardenui/static/scripts/garden.js
Normal file
116
gardenui/static/scripts/garden.js
Normal file
@ -0,0 +1,116 @@
|
||||
var on_switch_water = function() {
|
||||
var state = true;
|
||||
if(document.getElementById("water_switch").value == "ausschalten") {
|
||||
state = false;
|
||||
}
|
||||
var json_str = JSON.stringify({"id": "3", "waterstate": state});
|
||||
patch_sample(json_str);
|
||||
}
|
||||
|
||||
var on_switch_auto_state = function() {
|
||||
var state = true;
|
||||
if(document.getElementById("auto_switch").value == "ausschalten") {
|
||||
state = false;
|
||||
}
|
||||
var json_str = JSON.stringify({"water": {"id": "3", "autostate": state}});
|
||||
patch_config(json_str);
|
||||
}
|
||||
|
||||
var on_change_config = function() {
|
||||
var on_time_one = document.getElementById("water_on_one").value;
|
||||
var off_time_one = document.getElementById("water_off_one").value;
|
||||
var on_time_two = document.getElementById("water_on_two").value;
|
||||
var off_time_two = document.getElementById("water_off_two").value;
|
||||
var json_str = JSON.stringify({"water": {"id": "3", "times": [{"on_time": on_time_one, "off_time": off_time_one}, {"on_time": on_time_two, "off_time": off_time_two}]}});
|
||||
patch_config(json_str);
|
||||
}
|
||||
|
||||
var http_patch_config = new XMLHttpRequest();
|
||||
http_patch_config.onreadystatechange = function () {
|
||||
if (http_patch_config.readyState === 4) {
|
||||
var status = http_patch_config.status;
|
||||
if (status === 0 || (status >= 200 && status < 400)) {
|
||||
// The request has been completed successfully
|
||||
parse_config(http_patch_config.responseText);
|
||||
}
|
||||
} else {
|
||||
// request error
|
||||
}
|
||||
}
|
||||
var patch_config = function(config) {
|
||||
http_patch_config.abort();
|
||||
http_patch_config.open("PATCH", "/config");
|
||||
http_patch_config.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
|
||||
http_patch_config.send(config);
|
||||
}
|
||||
|
||||
var patch_http = new XMLHttpRequest();
|
||||
var patch_sample = function(sample) {
|
||||
patch_http.abort();
|
||||
patch_http.open("PATCH", "/sample");
|
||||
patch_http.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
|
||||
patch_http.send(sample);
|
||||
}
|
||||
|
||||
var parse_config = function (event) {
|
||||
var config = JSON.parse(event)
|
||||
var output = "einschalten"
|
||||
var visibility = 'hidden'
|
||||
if(config.water && config.water.id == '3') {
|
||||
if(config.water.autostate) {
|
||||
output = "ausschalten"
|
||||
visibility = "visible"
|
||||
document.getElementById("water_on_one").value = config.water.times[0].on_time;
|
||||
document.getElementById("water_off_one").value = config.water.times[0].off_time;
|
||||
document.getElementById("water_on_two").value = config.water.times[1].on_time;
|
||||
document.getElementById("water_off_two").value = config.water.times[1].off_time;
|
||||
}
|
||||
document.getElementById("auto_switch").value = output;
|
||||
document.getElementById("water_times").style.visibility = visibility
|
||||
}
|
||||
}
|
||||
|
||||
var parse_sample = function (event) {
|
||||
var sample = JSON.parse(event)
|
||||
if(sample.water && sample.water.id == '3') {
|
||||
var switch_caption = "einschalten";
|
||||
if(sample.water.state) {
|
||||
switch_caption = "ausschalten";
|
||||
}
|
||||
document.getElementById("water_switch").value = switch_caption;
|
||||
}
|
||||
}
|
||||
|
||||
var http = new XMLHttpRequest();
|
||||
http.onreadystatechange = function () {
|
||||
if (http.readyState === 4) {
|
||||
var status = http.status;
|
||||
if (status === 0 || (status >= 200 && status < 400)) {
|
||||
// The request has been completed successfully
|
||||
parse_sample(http.responseText);
|
||||
setTimeout(function () {
|
||||
http.open("GET", 'sample/3');
|
||||
http.send();
|
||||
}, 500);
|
||||
}
|
||||
} else {
|
||||
// request error
|
||||
}
|
||||
}
|
||||
http.open("GET", "sample/3");
|
||||
http.send();
|
||||
|
||||
var http_get_config = new XMLHttpRequest();
|
||||
http_get_config.onreadystatechange = function () {
|
||||
if (http_get_config.readyState === 4) {
|
||||
var status = http_get_config.status;
|
||||
if (status === 0 || (status >= 200 && status < 400)) {
|
||||
// The request has been completed successfully
|
||||
parse_config(http_get_config.responseText);
|
||||
}
|
||||
} else {
|
||||
// request error
|
||||
}
|
||||
}
|
||||
http_get_config.open("GET", "config/3");
|
||||
http_get_config.send();
|
176
gardenui/static/scripts/greenhouse_1.js
Normal file
176
gardenui/static/scripts/greenhouse_1.js
Normal file
@ -0,0 +1,176 @@
|
||||
var on_switch_heat = function() {
|
||||
var state = true;
|
||||
if(document.getElementById("heat_switch").value == "ausschalten") {
|
||||
state = false;
|
||||
}
|
||||
var json_str = JSON.stringify({"id": "1", "heatstate": state});
|
||||
patch_sample(json_str);
|
||||
}
|
||||
|
||||
var on_switch_heat_autostate = function() {
|
||||
var state = true;
|
||||
if(document.getElementById("heat_auto_switch").value == "ausschalten") {
|
||||
state = false;
|
||||
}
|
||||
var json_str = JSON.stringify({"heat": {"id": "1", "autostate": state}});
|
||||
patch_config(json_str);
|
||||
}
|
||||
|
||||
var on_increase_on_temperature = function() {
|
||||
var json_str = JSON.stringify({"heat": {"id": "1", "increase_on_temperature": true}});
|
||||
patch_config(json_str);
|
||||
}
|
||||
|
||||
var on_increase_off_temperature = function() {
|
||||
var json_str = JSON.stringify({"heat": {"id": "1", "increase_off_temperature": true}});
|
||||
patch_config(json_str);
|
||||
}
|
||||
|
||||
var on_decrease_on_temperature = function() {
|
||||
var json_str = JSON.stringify({"heat": {"id": "1", "decrease_on_temperature": true}});
|
||||
patch_config(json_str);
|
||||
}
|
||||
|
||||
var on_decrease_off_temperature = function() {
|
||||
var json_str = JSON.stringify({"heat": {"id": "1", "decrease_off_temperature": true}});
|
||||
patch_config(json_str);
|
||||
}
|
||||
|
||||
var on_switch_water = function() {
|
||||
var state = true;
|
||||
if(document.getElementById("water_switch").value == "ausschalten") {
|
||||
state = false;
|
||||
}
|
||||
var json_str = JSON.stringify({"id": "1", "waterstate": state});
|
||||
patch_sample(json_str);
|
||||
}
|
||||
|
||||
var on_switch_water_auto_state = function() {
|
||||
var state = true;
|
||||
if(document.getElementById("water_auto_switch").value == "ausschalten") {
|
||||
state = false;
|
||||
}
|
||||
var json_str = JSON.stringify({"water": {"id": "1", "autostate": state}});
|
||||
patch_config(json_str);
|
||||
}
|
||||
|
||||
var on_change_config = function() {
|
||||
var on_time_one = document.getElementById("water_on_one").value;
|
||||
var off_time_one = document.getElementById("water_off_one").value;
|
||||
var on_time_two = document.getElementById("water_on_two").value;
|
||||
var off_time_two = document.getElementById("water_off_two").value;
|
||||
var json_str = JSON.stringify({"water": {"id": "1", "times": [{"on_time": on_time_one, "off_time": off_time_one}, {"on_time": on_time_two, "off_time": off_time_two}]}});
|
||||
patch_config(json_str);
|
||||
}
|
||||
|
||||
var http_patch_config = new XMLHttpRequest();
|
||||
http_patch_config.onreadystatechange = function () {
|
||||
if (http_patch_config.readyState === 4) {
|
||||
var status = http_patch_config.status;
|
||||
if (status === 0 || (status >= 200 && status < 400)) {
|
||||
// The request has been completed successfully
|
||||
parse_config(http_patch_config.responseText);
|
||||
}
|
||||
} else {
|
||||
// request error
|
||||
}
|
||||
}
|
||||
var patch_config = function(config) {
|
||||
http_patch_config.abort();
|
||||
http_patch_config.open("PATCH", "/config");
|
||||
http_patch_config.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
|
||||
http_patch_config.send(config);
|
||||
}
|
||||
|
||||
var patch_http = new XMLHttpRequest();
|
||||
var patch_sample = function(sample) {
|
||||
patch_http.abort();
|
||||
patch_http.open("PATCH", "/sample");
|
||||
patch_http.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
|
||||
patch_http.send(sample);
|
||||
}
|
||||
|
||||
var parse_config = function (event) {
|
||||
var config = JSON.parse(event)
|
||||
var output = "einschalten"
|
||||
var visibility = 'hidden'
|
||||
if(config.heat && config.heat.id == '1') {
|
||||
if(config.heat.autostate) {
|
||||
output = "ausschalten"
|
||||
visibility = "visible"
|
||||
document.getElementById("on_temperature").innerHTML = config.heat.on_temperature;
|
||||
document.getElementById("off_temperature").innerHTML = config.heat.off_temperature;
|
||||
}
|
||||
document.getElementById("heat_auto_switch").value = output;
|
||||
document.getElementById("config_temperatures").style.visibility = visibility
|
||||
}
|
||||
output = "einschalten"
|
||||
visibility = 'hidden'
|
||||
if(config.water && config.water.id == '1') {
|
||||
if(config.water.autostate) {
|
||||
output = "ausschalten"
|
||||
visibility = "visible"
|
||||
document.getElementById("water_on_one").value = config.water.times[0].on_time;
|
||||
document.getElementById("water_off_one").value = config.water.times[0].off_time;
|
||||
document.getElementById("water_on_two").value = config.water.times[1].on_time;
|
||||
document.getElementById("water_off_two").value = config.water.times[1].off_time;
|
||||
}
|
||||
document.getElementById("water_auto_switch").value = output;
|
||||
document.getElementById("water_times").style.visibility = visibility
|
||||
}
|
||||
}
|
||||
|
||||
var parse_sample = function (event) {
|
||||
var sample = JSON.parse(event)
|
||||
if(sample.heat && sample.heat.id == '1') {
|
||||
var switch_caption = "einschalten";
|
||||
if(sample.heat.state) {
|
||||
switch_caption = "ausschalten";
|
||||
}
|
||||
document.getElementById("heat_switch").value = switch_caption;
|
||||
}
|
||||
if(sample.temperature && sample.temperature.id == '1') {
|
||||
document.getElementById("temperature_value").innerHTML = sample.temperature.value;
|
||||
}
|
||||
if(sample.water && sample.water.id == '1') {
|
||||
var switch_caption = "einschalten";
|
||||
if(sample.water.state) {
|
||||
switch_caption = "ausschalten";
|
||||
}
|
||||
document.getElementById("water_switch").value = switch_caption;
|
||||
}
|
||||
}
|
||||
|
||||
var http = new XMLHttpRequest();
|
||||
http.onreadystatechange = function () {
|
||||
if (http.readyState === 4) {
|
||||
var status = http.status;
|
||||
if (status === 0 || (status >= 200 && status < 400)) {
|
||||
// The request has been completed successfully
|
||||
parse_sample(http.responseText);
|
||||
setTimeout(function () {
|
||||
http.open("GET", 'sample/1');
|
||||
http.send();
|
||||
}, 500);
|
||||
}
|
||||
} else {
|
||||
// request error
|
||||
}
|
||||
}
|
||||
http.open("GET", "sample/1");
|
||||
http.send();
|
||||
|
||||
var http_get_config = new XMLHttpRequest();
|
||||
http_get_config.onreadystatechange = function () {
|
||||
if (http_get_config.readyState === 4) {
|
||||
var status = http_get_config.status;
|
||||
if (status === 0 || (status >= 200 && status < 400)) {
|
||||
// The request has been completed successfully
|
||||
parse_config(http_get_config.responseText);
|
||||
}
|
||||
} else {
|
||||
// request error
|
||||
}
|
||||
}
|
||||
http_get_config.open("GET", "config/1");
|
||||
http_get_config.send();
|
116
gardenui/static/scripts/greenhouse_2.js
Normal file
116
gardenui/static/scripts/greenhouse_2.js
Normal file
@ -0,0 +1,116 @@
|
||||
var on_switch_water = function() {
|
||||
var state = true;
|
||||
if(document.getElementById("water_switch").value == "ausschalten") {
|
||||
state = false;
|
||||
}
|
||||
var json_str = JSON.stringify({"id": "2", "waterstate": state});
|
||||
patch_sample(json_str);
|
||||
}
|
||||
|
||||
var on_switch_auto_state = function() {
|
||||
var state = true;
|
||||
if(document.getElementById("auto_switch").value == "ausschalten") {
|
||||
state = false;
|
||||
}
|
||||
var json_str = JSON.stringify({"water": {"id": "2", "autostate": state}});
|
||||
patch_config(json_str);
|
||||
}
|
||||
|
||||
var on_change_config = function() {
|
||||
var on_time_one = document.getElementById("water_on_one").value;
|
||||
var off_time_one = document.getElementById("water_off_one").value;
|
||||
var on_time_two = document.getElementById("water_on_two").value;
|
||||
var off_time_two = document.getElementById("water_off_two").value;
|
||||
var json_str = JSON.stringify({"water": {"id": "2", "times": [{"on_time": on_time_one, "off_time": off_time_one}, {"on_time": on_time_two, "off_time": off_time_two}]}});
|
||||
patch_config(json_str);
|
||||
}
|
||||
|
||||
var http_patch_config = new XMLHttpRequest();
|
||||
http_patch_config.onreadystatechange = function () {
|
||||
if (http_patch_config.readyState === 4) {
|
||||
var status = http_patch_config.status;
|
||||
if (status === 0 || (status >= 200 && status < 400)) {
|
||||
// The request has been completed successfully
|
||||
parse_config(http_patch_config.responseText);
|
||||
}
|
||||
} else {
|
||||
// request error
|
||||
}
|
||||
}
|
||||
var patch_config = function(config) {
|
||||
http_patch_config.abort();
|
||||
http_patch_config.open("PATCH", "/config");
|
||||
http_patch_config.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
|
||||
http_patch_config.send(config);
|
||||
}
|
||||
|
||||
var patch_http = new XMLHttpRequest();
|
||||
var patch_sample = function(sample) {
|
||||
patch_http.abort();
|
||||
patch_http.open("PATCH", "/sample");
|
||||
patch_http.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
|
||||
patch_http.send(sample);
|
||||
}
|
||||
|
||||
var parse_config = function (event) {
|
||||
var config = JSON.parse(event)
|
||||
var output = "einschalten"
|
||||
var visibility = 'hidden'
|
||||
if(config.water && config.water.id == '2') {
|
||||
if(config.water.autostate) {
|
||||
output = "ausschalten"
|
||||
visibility = "visible"
|
||||
document.getElementById("water_on_one").value = config.water.times[0].on_time;
|
||||
document.getElementById("water_off_one").value = config.water.times[0].off_time;
|
||||
document.getElementById("water_on_two").value = config.water.times[1].on_time;
|
||||
document.getElementById("water_off_two").value = config.water.times[1].off_time;
|
||||
}
|
||||
document.getElementById("auto_switch").value = output;
|
||||
document.getElementById("water_times").style.visibility = visibility
|
||||
}
|
||||
}
|
||||
|
||||
var parse_sample = function (event) {
|
||||
var sample = JSON.parse(event)
|
||||
if(sample.water && sample.water.id == '2') {
|
||||
var switch_caption = "einschalten";
|
||||
if(sample.water.state) {
|
||||
switch_caption = "ausschalten";
|
||||
}
|
||||
document.getElementById("water_switch").value = switch_caption;
|
||||
}
|
||||
}
|
||||
|
||||
var http = new XMLHttpRequest();
|
||||
http.onreadystatechange = function () {
|
||||
if (http.readyState === 4) {
|
||||
var status = http.status;
|
||||
if (status === 0 || (status >= 200 && status < 400)) {
|
||||
// The request has been completed successfully
|
||||
parse_sample(http.responseText);
|
||||
setTimeout(function () {
|
||||
http.open("GET", 'sample/2');
|
||||
http.send();
|
||||
}, 500);
|
||||
}
|
||||
} else {
|
||||
// request error
|
||||
}
|
||||
}
|
||||
http.open("GET", "sample/2");
|
||||
http.send();
|
||||
|
||||
var http_get_config = new XMLHttpRequest();
|
||||
http_get_config.onreadystatechange = function () {
|
||||
if (http_get_config.readyState === 4) {
|
||||
var status = http_get_config.status;
|
||||
if (status === 0 || (status >= 200 && status < 400)) {
|
||||
// The request has been completed successfully
|
||||
parse_config(http_get_config.responseText);
|
||||
}
|
||||
} else {
|
||||
// request error
|
||||
}
|
||||
}
|
||||
http_get_config.open("GET", "config/2");
|
||||
http_get_config.send();
|
77
gardenui/templates/garden.html
Normal file
77
gardenui/templates/garden.html
Normal file
@ -0,0 +1,77 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Garten</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<link href="/static/css/style.css" rel="stylesheet">
|
||||
<script src="/static/scripts/garden.js"></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>Garten</h1>
|
||||
<table class="center">
|
||||
<tr>
|
||||
<td class="left">Bewässerung</td>
|
||||
<td class="input">
|
||||
<input id="water_switch" type="submit" value="" onclick="on_switch_water()"></input>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="left">Zeigesteuerte Bewässerung </td>
|
||||
<td class="input">
|
||||
<input id="auto_switch" type="submit" value="einschalten" onclick="on_switch_auto_state()"></input>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<div id="water_times" style="visibility:hidden;">
|
||||
<table class="center">
|
||||
<tr>
|
||||
<td>Vormittag</td>
|
||||
<td>
|
||||
<table>
|
||||
<tr>
|
||||
<td>Einschaltzeit</td>
|
||||
<td class="input">
|
||||
<input type="text" id="water_on_one" style="width: 70px;" onchange="on_change_config()"></input>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Ausschaltzeit</td>
|
||||
<td class="input">
|
||||
<input type="text" id="water_off_one" style="width: 70px;" onchange="on_change_config()"></input>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Nachmittag</td>
|
||||
<td>
|
||||
<table>
|
||||
<tr>
|
||||
<td>Einschaltzeit</td>
|
||||
<td class="input">
|
||||
<input type="text" id="water_on_two" style="width: 70px;" onchange="on_change_config()"></input>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Ausschaltzeit</td>
|
||||
<td class="input">
|
||||
<input type="text" id="water_off_two" style="width: 70px;" onchange="on_change_config()"></input>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
</body>
|
||||
<footer>
|
||||
<nav>
|
||||
<a href="/">Home</a> | 
|
||||
<a href="/greenhouse_1" class="center">Gewächshaus 1</a> | 
|
||||
<a href="/greenhouse_2" class="center">Gewächshaus 2</a> | 
|
||||
<a href="/garden" class="center">Gemüsegarten</a>
|
||||
</nav>
|
||||
</footer>
|
||||
</html>
|
123
gardenui/templates/greenhouse_1.html
Normal file
123
gardenui/templates/greenhouse_1.html
Normal file
@ -0,0 +1,123 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Gewächshaus 1</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<link href="/static/css/style.css" rel="stylesheet">
|
||||
<script src="/static/scripts/greenhouse_1.js"></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>Gewächshaus 1</h1>
|
||||
<hr>
|
||||
<table class="center">
|
||||
<tr>
|
||||
<td><h3>Temperatur </h3></td>
|
||||
<td><h3 id="temperature_value"></h3></td>
|
||||
</tr>
|
||||
</table>
|
||||
<table class="center">
|
||||
<tr>
|
||||
<td class="table_left">Heizung</td>
|
||||
<td class="input">
|
||||
<input id="heat_switch" type="submit" value="" onclick="on_switch_heat()"></input>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="table_left">Frostwächter</td>
|
||||
<td class="input">
|
||||
<input id="heat_auto_switch" type="submit" value="" onclick="on_switch_heat_autostate()"></input>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<div id="config_temperatures" style="visibility:hidden;">
|
||||
<table class="center">
|
||||
<tr>
|
||||
<td>Einschalttemperatur</td>
|
||||
<td class="input">
|
||||
<input id="decrease_on_temperature" type="submit" value="-" onclick="on_decrease_on_temperature()"></input>
|
||||
</td>
|
||||
<td id="on_temperature"></td>
|
||||
<td class="input">
|
||||
<input id="increase_on_temperature" type="submit" value="+" onclick="on_increase_on_temperature()"></input>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Ausschalttemperatur</td>
|
||||
<td class="input">
|
||||
<input id="decrease_off_temperature" type="submit" value="-" onclick="on_decrease_off_temperature()"></input>
|
||||
</td>
|
||||
<td id="off_temperature"></td>
|
||||
<td class="input">
|
||||
<input id="increase_off_temperature" type="submit" value="+" onclick="on_increase_off_temperature()"></input>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
<hr>
|
||||
<table class="center">
|
||||
<tr>
|
||||
<td class="table_left">Bewässerung</td>
|
||||
<td class="input">
|
||||
<input id="water_switch" type="submit" value="" onclick="on_switch_water()"></input>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="table_left">Zeigesteuerte Bewässerung </td>
|
||||
<td class="input">
|
||||
<input id="water_auto_switch" type="submit" value="" onclick="on_switch_water_auto_state()"></input>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<div id="water_times" style="visibility:hidden;">
|
||||
<table class="center">
|
||||
<tr>
|
||||
<td>Vormittag</td>
|
||||
<td>
|
||||
<table>
|
||||
<tr>
|
||||
<td>Einschaltzeit</td>
|
||||
<td class="input">
|
||||
<input type="text" id="water_on_one" style="width: 70px;" onchange="on_change_config()"></input>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Ausschaltzeit</td>
|
||||
<td class="input">
|
||||
<input type="text" id="water_off_one" style="width: 70px;" onchange="on_change_config()"></input>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Nachmittag</td>
|
||||
<td>
|
||||
<table>
|
||||
<tr>
|
||||
<td>Einschaltzeit</td>
|
||||
<td class="input">
|
||||
<input type="text" id="water_on_two" style="width: 70px;" onchange="on_change_config()"></input>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Ausschaltzeit</td>
|
||||
<td class="input">
|
||||
<input type="text" id="water_off_two" style="width: 70px;" onchange="on_change_config()"></input>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
</body>
|
||||
<footer>
|
||||
<nav>
|
||||
<a href="/">Home</a> | 
|
||||
<a href="/greenhouse_1" class="center">Gewächshaus 1</a> | 
|
||||
<a href="/greenhouse_2" class="center">Gewächshaus 2</a> | 
|
||||
<a href="/garden" class="center">Gemüsegarten</a>
|
||||
</nav>
|
||||
</footer>
|
||||
</html>
|
77
gardenui/templates/greenhouse_2.html
Normal file
77
gardenui/templates/greenhouse_2.html
Normal file
@ -0,0 +1,77 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Gewächshaus 2</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<link href="/static/css/style.css" rel="stylesheet">
|
||||
<script src="/static/scripts/greenhouse_2.js"></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>Gewächshaus 2</h1>
|
||||
<table class="center">
|
||||
<tr>
|
||||
<td class="left">Bewässerung</td>
|
||||
<td class="input">
|
||||
<input id="water_switch" type="submit" value="" onclick="on_switch_water()"></input>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="left">Zeigesteuerte Bewässerung </td>
|
||||
<td class="input">
|
||||
<input id="auto_switch" type="submit" value="einschalten" onclick="on_switch_auto_state()"></input>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<div id="water_times" style="visibility:hidden;">
|
||||
<table class="center">
|
||||
<tr>
|
||||
<td>Vormittag</td>
|
||||
<td>
|
||||
<table>
|
||||
<tr>
|
||||
<td>Einschaltzeit</td>
|
||||
<td class="input">
|
||||
<input type="text" id="water_on_one" style="width: 70px;" onchange="on_change_config()"></input>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Ausschaltzeit</td>
|
||||
<td class="input">
|
||||
<input type="text" id="water_off_one" style="width: 70px;" onchange="on_change_config()"></input>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Nachmittag</td>
|
||||
<td>
|
||||
<table>
|
||||
<tr>
|
||||
<td>Einschaltzeit</td>
|
||||
<td class="input">
|
||||
<input type="text" id="water_on_two" style="width: 70px;" onchange="on_change_config()"></input>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Ausschaltzeit</td>
|
||||
<td class="input">
|
||||
<input type="text" id="water_off_two" style="width: 70px;" onchange="on_change_config()"></input>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
</body>
|
||||
<footer>
|
||||
<nav>
|
||||
<a href="/">Home</a> | 
|
||||
<a href="/greenhouse_1" class="center">Gewächshaus 1</a> | 
|
||||
<a href="/greenhouse_2" class="center">Gewächshaus 2</a> | 
|
||||
<a href="/garden" class="center">Gemüsegarten</a>
|
||||
</nav>
|
||||
</footer>
|
||||
</html>
|
26
gardenui/templates/index.html
Normal file
26
gardenui/templates/index.html
Normal file
@ -0,0 +1,26 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Garten</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<link href="/static/css/style.css" rel="stylesheet">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>Garten</h1>
|
||||
<div class="center">
|
||||
<a href="/greenhouse_1">Gewächshaus 1</a><br>
|
||||
<a href="/greenhouse_2">Gewächshaus 2</a><br>
|
||||
<a href="/garden">Gemüsegarten</a>
|
||||
</div>
|
||||
</body>
|
||||
|
||||
<footer>
|
||||
<nav>
|
||||
<a href="/">Home</a> | 
|
||||
<a href="/greenhouse_1" class="center">Gewächshaus 1</a> | 
|
||||
<a href="/greenhouse_2" class="center">Gewächshaus 2</a> | 
|
||||
<a href="/garden" class="center">Gemüsegarten</a>
|
||||
</nav>
|
||||
</footer>
|
||||
</html>
|
40
setup.py
Normal file
40
setup.py
Normal file
@ -0,0 +1,40 @@
|
||||
|
||||
import os
|
||||
import shutil
|
||||
import stat
|
||||
from setuptools import setup
|
||||
from setuptools.command.install import install
|
||||
|
||||
NAME = 'Gardenui'
|
||||
VERSION = '1'
|
||||
AUTHOR = 'Thomas Klaehn'
|
||||
EMAIL = 'tkl@blackfinn.de'
|
||||
PACKAGES = ['gardenui']
|
||||
REQUIRES = ['Flask', 'gunicorn']
|
||||
PACKAGE_DATA = {'gardenui': ['templates/*', 'static/css/*', 'static/scripts/*']}
|
||||
|
||||
SERVICEDIR = "/lib/systemd/system"
|
||||
DAEMON_START_SCRIPT = os.path.join(SERVICEDIR, 'gardenui.service')
|
||||
|
||||
LOGFILE = "/var/log/gardenui.log"
|
||||
|
||||
class Install(install):
|
||||
def run(self):
|
||||
install.run(self)
|
||||
os.makedirs(SERVICEDIR, exist_ok=True)
|
||||
shutil.copyfile('gardenui.service', os.path.join(SERVICEDIR, DAEMON_START_SCRIPT))
|
||||
os.chmod(DAEMON_START_SCRIPT, stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP | stat.S_IROTH)
|
||||
|
||||
try:
|
||||
open(LOGFILE, 'r')
|
||||
except FileNotFoundError:
|
||||
os.makedirs(os.path.dirname(LOGFILE), exist_ok=True)
|
||||
open(LOGFILE, 'x')
|
||||
os.chmod(LOGFILE, stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP |
|
||||
stat.S_IWGRP | stat.S_IROTH | stat.S_IWOTH)
|
||||
|
||||
|
||||
setup(name=NAME, version=VERSION, long_description=__doc__, author=AUTHOR,
|
||||
author_email=EMAIL, packages=PACKAGES, include_package_data=True,
|
||||
package_data=PACKAGE_DATA, zip_safe=False, install_requires=REQUIRES,
|
||||
cmdclass={'install': Install})
|
Loading…
Reference in New Issue
Block a user