Switch to relay_rpc hadling

This commit is contained in:
Thomas Klaehn 2022-06-07 14:12:38 +02:00
parent 64157b00e0
commit f39cde1d1c
19 changed files with 1187 additions and 121 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
__pycache__

8
.vscode/launch.json vendored
View File

@ -4,6 +4,14 @@
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0", "version": "0.2.0",
"configurations": [ "configurations": [
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"justMyCode": true
},
{ {
"name": "Python: Flask", "name": "Python: Flask",
"type": "python", "type": "python",

View File

@ -22,7 +22,6 @@ class Control(threading.Thread):
self.run_condition = True self.run_condition = True
self.config = None self.config = None
self.config_file = config_file_name self.config_file = config_file_name
self.water_state = []
def reload_config(self): def reload_config(self):
@ -36,8 +35,6 @@ class Control(threading.Thread):
shutil.copyfile("config.json", self.config_file) shutil.copyfile("config.json", self.config_file)
with open(self.config_file, "r", encoding="UTF-8") as handle: with open(self.config_file, "r", encoding="UTF-8") as handle:
self.config = json.load(handle) self.config = json.load(handle)
for _ in range(len(self.config['configs'])):
self.water_state.append(False)
def run(self): def run(self):
@ -49,37 +46,41 @@ class Control(threading.Thread):
autostate = water["autostate"] autostate = water["autostate"]
if autostate: if autostate:
times = water["times"] times = water["times"]
idx = 0
now = datetime.datetime.now() now = datetime.datetime.now()
if int(now.hour) >= 12: switch_on = False
idx = 1 for entry in times:
on_time_pattern = times[idx]['on_time'] on_time_pattern = entry['on_time']
on_time_pattern = on_time_pattern.split(':') on_time_pattern = on_time_pattern.split(':')
on_time = now.replace(hour=int(on_time_pattern[0]), on_time = now.replace(hour=int(on_time_pattern[0]),
minute=int(on_time_pattern[1]), minute=int(on_time_pattern[1]),
second=0, second=0,
microsecond=0) microsecond=0)
off_time_pattern = times[idx]['off_time'] off_time_pattern = entry['off_time']
off_time_pattern = off_time_pattern.split(':') off_time_pattern = off_time_pattern.split(':')
off_time = now.replace(hour=int(off_time_pattern[0]), off_time = now.replace(hour=int(off_time_pattern[0]),
minute=int(off_time_pattern[1]), minute=int(off_time_pattern[1]),
second=0, second=0,
microsecond=0) microsecond=0)
if now > on_time and now <= off_time:
switch_on = True
break
url = "http://" + config["host"] + ":" + str(config["port"]) url = "http://" + config["host"] + ":" + str(config["port"])
if now > on_time and now <= off_time and not self.water_state[water_index]: water_state = True
try: try:
client = xmlrpc.client.ServerProxy(url) client = xmlrpc.client.ServerProxy(url)
client.switch_relay(water["relay"], True) water_state = client.get_relay_state(water["relay"])
self.water_state[water_index] = client.get_relay_state(water["relay"])
except OSError as error: except OSError as error:
print(error) print(error)
elif now > off_time and self.water_state[water_index]: if switch_on and not water_state:
try:
client = xmlrpc.client.ServerProxy(url)
water_state = client.switch_relay(water["relay"], True)
except OSError as error:
print(error)
elif not switch_on and water_state:
try: try:
client = xmlrpc.client.ServerProxy(url) client = xmlrpc.client.ServerProxy(url)
client.switch_relay(water["relay"], False) client.switch_relay(water["relay"], False)
self.water_state[water_index] = client.get_relay_state(water["relay"])
except OSError as error: except OSError as error:
print(error) print(error)
water_index += 1 water_index += 1
@ -108,6 +109,36 @@ def tomatentuppen():
return render_template('tomatentuppen.html') return render_template('tomatentuppen.html')
@app.route('/rasen_1', methods=['GET'])
def rasen_1():
"""Handle GET to rasen_1.html"""
return render_template('rasen_1.html')
@app.route('/rasen_2', methods=['GET'])
def rasen_2():
"""Handle GET to rasen_2.html"""
return render_template('rasen_2.html')
@app.route('/rasen_3', methods=['GET'])
def rasen_3():
"""Handle GET to rasen_3.html"""
return render_template('rasen_3.html')
@app.route('/gewaechshaus', methods=['GET'])
def gewaechshaus():
"""Handle GET to gewaechshaus.html"""
return render_template('gewaechshaus.html')
@app.route('/wasseranschluss', methods=['GET'])
def wasseranschluss():
"""Handle GET to wasseranschluss.html"""
return render_template('wasseranschluss.html')
@app.route('/sample/<idx>', methods=['GET']) @app.route('/sample/<idx>', methods=['GET'])
def get_sample(idx='0'): def get_sample(idx='0'):
"""Handle GET to /sample/<idx>""" """Handle GET to /sample/<idx>"""
@ -213,6 +244,5 @@ def start_control():
control.start() control.start()
if __name__ == 'app':
start_control() start_control()
app.run(debug=True, host='0.0.0.0', port=8000) app.run(debug=True, host='0.0.0.0', port=8000)

View File

@ -1,6 +1,5 @@
{ {
"configs": "configs": [
[
{ {
"id": "hochbeet", "id": "hochbeet",
"host": "hochbeet", "host": "hochbeet",
@ -8,16 +7,11 @@
"water": "water":
{ {
"relay": 2, "relay": 2,
"autostate": false, "autostate": true,
"times": "times": [
[
{ {
"on_time": "7:00", "on_time": "8:00",
"off_time": "7:20" "off_time": "8:10"
},
{
"on_time": "19:00",
"off_time": "19:20"
} }
] ]
} }
@ -29,16 +23,91 @@
"water": "water":
{ {
"relay": 3, "relay": 3,
"autostate": false, "autostate": true,
"times": "times": [
[
{ {
"on_time": "7:00", "on_time": "8:00",
"off_time": "7:20" "off_time": "9:00"
}
]
}
}, },
{ {
"on_time": "19:00", "id": "rasen_1",
"off_time": "19:20" "host": "garten",
"port": 64001,
"water":
{
"relay": 3,
"autostate": true,
"times": [
{
"on_time": "6:00",
"off_time": "6:30"
}
]
}
},
{
"id": "wasseranschluss",
"host": "garten",
"port": 64001,
"water":
{
"relay": 2,
"autostate": true,
"times": [
{
"on_time": "6:30",
"off_time": "7:00"
}
]
}
},
{
"id": "gewaechshaus",
"host": "garten",
"port": 64001,
"water":
{
"relay": 1,
"autostate": true,
"times": [
{
"on_time": "8:00",
"off_time": "8:10"
}
]
}
},
{
"id": "rasen_2",
"host": "wels",
"port": 64001,
"water":
{
"relay": 1,
"autostate": true,
"times": [
{
"on_time": "7:30",
"off_time": "8:00"
}
]
}
},
{
"id": "rasen_3",
"host": "wels",
"port": 64001,
"water":
{
"relay": 2,
"autostate": true,
"times": [
{
"on_time": "7:00",
"off_time": "7:30"
} }
] ]
} }

View File

@ -0,0 +1,139 @@
var on_switch_water = function() {
var state = true;
if(document.getElementById("water_switch").value == "ausschalten") {
state = false;
}
var json_str = JSON.stringify(
{
"id": "gewaechshaus",
"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(
{
"id": "gewaechshaus",
"water":
{
"autostate": state
}
}
);
patch_config(json_str);
}
var on_change_config = function() {
var on_time_one = document.getElementById("water_on").value;
var off_time_one = document.getElementById("water_off").value;
var json_str = JSON.stringify(
{
"id": "gewaechshaus",
"water":
{
"times":
[
{
"on_time": on_time,
"off_time": off_time
}
]
}
}
);
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/gewaechshaus");
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/gewaechshaus");
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) {
if(config.water.autostate) {
output = "ausschalten"
visibility = "visible"
document.getElementById("water_on").value = config.water.times[0].on_time;
document.getElementById("water_off").value = config.water.times[0].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 == 'gewaechshaus') {
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/gewaechshaus');
http.send();
}, 500);
}
} else {
// request error
}
}
http.open("GET", "sample/gewaechshaus");
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/gewaechshaus");
http_get_config.send();

View File

@ -30,10 +30,8 @@ var on_switch_auto_state = function() {
} }
var on_change_config = function() { var on_change_config = function() {
var on_time_one = document.getElementById("water_on_one").value; var on_time_one = document.getElementById("water_on").value;
var off_time_one = document.getElementById("water_off_one").value; var off_time_one = document.getElementById("water_off").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( var json_str = JSON.stringify(
{ {
"id": "hochbeet", "id": "hochbeet",
@ -42,12 +40,8 @@ var on_change_config = function() {
"times": "times":
[ [
{ {
"on_time": on_time_one, "on_time": on_time,
"off_time": off_time_one "off_time": off_time
},
{
"on_time": on_time_two,
"off_time": off_time_two
} }
] ]
} }
@ -91,10 +85,8 @@ var parse_config = function (event) {
if(config.water.autostate) { if(config.water.autostate) {
output = "ausschalten" output = "ausschalten"
visibility = "visible" visibility = "visible"
document.getElementById("water_on_one").value = config.water.times[0].on_time; document.getElementById("water_on").value = config.water.times[0].on_time;
document.getElementById("water_off_one").value = config.water.times[0].off_time; document.getElementById("water_off").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("auto_switch").value = output;
document.getElementById("water_times").style.visibility = visibility document.getElementById("water_times").style.visibility = visibility

View File

@ -0,0 +1,139 @@
var on_switch_water = function() {
var state = true;
if(document.getElementById("water_switch").value == "ausschalten") {
state = false;
}
var json_str = JSON.stringify(
{
"id": "rasen_1",
"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(
{
"id": "rasen_1",
"water":
{
"autostate": state
}
}
);
patch_config(json_str);
}
var on_change_config = function() {
var on_time_one = document.getElementById("water_on").value;
var off_time_one = document.getElementById("water_off").value;
var json_str = JSON.stringify(
{
"id": "rasen_1",
"water":
{
"times":
[
{
"on_time": on_time,
"off_time": off_time
}
]
}
}
);
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/rasen_1");
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/rasen_1");
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) {
if(config.water.autostate) {
output = "ausschalten"
visibility = "visible"
document.getElementById("water_on").value = config.water.times[0].on_time;
document.getElementById("water_off").value = config.water.times[0].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 == 'rasen_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/rasen_1');
http.send();
}, 500);
}
} else {
// request error
}
}
http.open("GET", "sample/rasen_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/rasen_1");
http_get_config.send();

View File

@ -0,0 +1,139 @@
var on_switch_water = function() {
var state = true;
if(document.getElementById("water_switch").value == "ausschalten") {
state = false;
}
var json_str = JSON.stringify(
{
"id": "rasen_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(
{
"id": "rasen_2",
"water":
{
"autostate": state
}
}
);
patch_config(json_str);
}
var on_change_config = function() {
var on_time_one = document.getElementById("water_on").value;
var off_time_one = document.getElementById("water_off").value;
var json_str = JSON.stringify(
{
"id": "rasen_2",
"water":
{
"times":
[
{
"on_time": on_time,
"off_time": off_time
}
]
}
}
);
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/rasen_2");
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/rasen_2");
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) {
if(config.water.autostate) {
output = "ausschalten"
visibility = "visible"
document.getElementById("water_on").value = config.water.times[0].on_time;
document.getElementById("water_off").value = config.water.times[0].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 == 'rasen_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/rasen_2');
http.send();
}, 500);
}
} else {
// request error
}
}
http.open("GET", "sample/rasen_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/rasen_2");
http_get_config.send();

View File

@ -0,0 +1,139 @@
var on_switch_water = function() {
var state = true;
if(document.getElementById("water_switch").value == "ausschalten") {
state = false;
}
var json_str = JSON.stringify(
{
"id": "rasen_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(
{
"id": "rasen_3",
"water":
{
"autostate": state
}
}
);
patch_config(json_str);
}
var on_change_config = function() {
var on_time_one = document.getElementById("water_on").value;
var off_time_one = document.getElementById("water_off").value;
var json_str = JSON.stringify(
{
"id": "rasen_3",
"water":
{
"times":
[
{
"on_time": on_time,
"off_time": off_time
}
]
}
}
);
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/rasen_3");
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/rasen_3");
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) {
if(config.water.autostate) {
output = "ausschalten"
visibility = "visible"
document.getElementById("water_on").value = config.water.times[0].on_time;
document.getElementById("water_off").value = config.water.times[0].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 == 'rasen_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/rasen_3');
http.send();
}, 500);
}
} else {
// request error
}
}
http.open("GET", "sample/rasen_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/rasen_3");
http_get_config.send();

View File

@ -30,24 +30,17 @@ var on_switch_auto_state = function() {
} }
var on_change_config = function() { var on_change_config = function() {
var on_time_one = document.getElementById("water_on_one").value; var on_time = document.getElementById("water_on").value;
var off_time_one = document.getElementById("water_off_one").value; var off_time = document.getElementById("water_off").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( var json_str = JSON.stringify(
{ {
"id": "tomatentuppen", "id": "tomatentuppen",
"water": "water":
{ {
"times": "times": [
[
{ {
"on_time": on_time_one, "on_time": on_time,
"off_time": off_time_one "off_time": off_time
},
{
"on_time": on_time_two,
"off_time": off_time_two
} }
] ]
} }
@ -91,10 +84,8 @@ var parse_config = function (event) {
if(config.water.autostate) { if(config.water.autostate) {
output = "ausschalten" output = "ausschalten"
visibility = "visible" visibility = "visible"
document.getElementById("water_on_one").value = config.water.times[0].on_time; document.getElementById("water_on").value = config.water.times[0].on_time;
document.getElementById("water_off_one").value = config.water.times[0].off_time; document.getElementById("water_off").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("auto_switch").value = output;
document.getElementById("water_times").style.visibility = visibility document.getElementById("water_times").style.visibility = visibility

View File

@ -0,0 +1,139 @@
var on_switch_water = function() {
var state = true;
if(document.getElementById("water_switch").value == "ausschalten") {
state = false;
}
var json_str = JSON.stringify(
{
"id": "wasseranschluss",
"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(
{
"id": "wasseranschluss",
"water":
{
"autostate": state
}
}
);
patch_config(json_str);
}
var on_change_config = function() {
var on_time_one = document.getElementById("water_on").value;
var off_time_one = document.getElementById("water_off").value;
var json_str = JSON.stringify(
{
"id": "wasseranschluss",
"water":
{
"times":
[
{
"on_time": on_time,
"off_time": off_time
}
]
}
}
);
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/wasseranschluss");
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/wasseranschluss");
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) {
if(config.water.autostate) {
output = "ausschalten"
visibility = "visible"
document.getElementById("water_on").value = config.water.times[0].on_time;
document.getElementById("water_off").value = config.water.times[0].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 == 'wasseranschluss') {
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/wasseranschluss');
http.send();
}, 500);
}
} else {
// request error
}
}
http.open("GET", "sample/wasseranschluss");
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/wasseranschluss");
http_get_config.send();

View File

@ -0,0 +1,61 @@
<!DOCTYPE html>
<html>
<head>
<title>Gewächshaus</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="/static/css/style.css" rel="stylesheet">
<script src="/static/scripts/gewaechshaus.js"></script>
</head>
<body>
<h1>Gewächshaus</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>
<table>
<tr>
<td>Einschaltzeit</td>
<td class="input">
<input type="text" id="water_on" style="width: 70px;" onchange="on_change_config()"></input>
</td>
</tr>
<tr>
<td>Ausschaltzeit</td>
<td class="input">
<input type="text" id="water_off" style="width: 70px;" onchange="on_change_config()"></input>
</td>
</tr>
</table>
</td>
</tr>
</table>
</div>
</body>
<footer>
<nav>
<a href="/">Home</a>&nbsp|&nbsp
<a href="/rasen_1" class="center">Rasen 1</a>&nbsp|&nbsp
<a href="/rasen_2" class="center">Rasen 2</a>&nbsp|&nbsp
<a href="/rasen_3" class="center">Rasen 3</a>&nbsp|&nbsp
<a href="/gewaechshaus" class="center">Gewächshaus</a>&nbsp|&nbsp
<a href="/wasseranschluss" class="center">Wasseranschluss</a>&nbsp|&nbsp
<a href="/hochbeet" class="center">Hochbeet</a>&nbsp|&nbsp
<a href="/tomatentuppen" class="center">Tomatentuppen</a>
</nav>
</footer>
</html>

View File

@ -26,38 +26,18 @@
<div id="water_times" style="visibility:hidden;"> <div id="water_times" style="visibility:hidden;">
<table class="center"> <table class="center">
<tr> <tr>
<td>Vormittag</td>
<td> <td>
<table> <table>
<tr> <tr>
<td>Einschaltzeit</td> <td>Einschaltzeit</td>
<td class="input"> <td class="input">
<input type="text" id="water_on_one" style="width: 70px;" onchange="on_change_config()"></input> <input type="text" id="water_on" style="width: 70px;" onchange="on_change_config()"></input>
</td> </td>
</tr> </tr>
<tr> <tr>
<td>Ausschaltzeit</td> <td>Ausschaltzeit</td>
<td class="input"> <td class="input">
<input type="text" id="water_off_one" style="width: 70px;" onchange="on_change_config()"></input> <input type="text" id="water_off" 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> </td>
</tr> </tr>
</table> </table>
@ -69,6 +49,11 @@
<footer> <footer>
<nav> <nav>
<a href="/">Home</a>&nbsp|&nbsp <a href="/">Home</a>&nbsp|&nbsp
<a href="/rasen_1" class="center">Rasen 1</a>&nbsp|&nbsp
<a href="/rasen_2" class="center">Rasen 2</a>&nbsp|&nbsp
<a href="/rasen_3" class="center">Rasen 3</a>&nbsp|&nbsp
<a href="/gewaechshaus" class="center">Gewächshaus</a>&nbsp|&nbsp
<a href="/wasseranschluss" class="center">Wasseranschluss</a>&nbsp|&nbsp
<a href="/hochbeet" class="center">Hochbeet</a>&nbsp|&nbsp <a href="/hochbeet" class="center">Hochbeet</a>&nbsp|&nbsp
<a href="/tomatentuppen" class="center">Tomatentuppen</a> <a href="/tomatentuppen" class="center">Tomatentuppen</a>
</nav> </nav>

View File

@ -17,6 +17,11 @@
<footer> <footer>
<nav> <nav>
<a href="/">Home</a>&nbsp|&nbsp <a href="/">Home</a>&nbsp|&nbsp
<a href="/rasen_1" class="center">Rasen 1</a>&nbsp|&nbsp
<a href="/rasen_2" class="center">Rasen 2</a>&nbsp|&nbsp
<a href="/rasen_3" class="center">Rasen 3</a>&nbsp|&nbsp
<a href="/gewaechshaus" class="center">Gewächshaus</a>&nbsp|&nbsp
<a href="/wasseranschluss" class="center">Wasseranschluss</a>&nbsp|&nbsp
<a href="/hochbeet" class="center">Hochbeet</a>&nbsp|&nbsp <a href="/hochbeet" class="center">Hochbeet</a>&nbsp|&nbsp
<a href="/tomatentuppen" class="center">Tomatentuppen</a> <a href="/tomatentuppen" class="center">Tomatentuppen</a>
</nav> </nav>

View File

@ -0,0 +1,61 @@
<!DOCTYPE html>
<html>
<head>
<title>Rasen 1</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="/static/css/style.css" rel="stylesheet">
<script src="/static/scripts/rasen_1.js"></script>
</head>
<body>
<h1>Rasen 1</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>
<table>
<tr>
<td>Einschaltzeit</td>
<td class="input">
<input type="text" id="water_on" style="width: 70px;" onchange="on_change_config()"></input>
</td>
</tr>
<tr>
<td>Ausschaltzeit</td>
<td class="input">
<input type="text" id="water_off" style="width: 70px;" onchange="on_change_config()"></input>
</td>
</tr>
</table>
</td>
</tr>
</table>
</div>
</body>
<footer>
<nav>
<a href="/">Home</a>&nbsp|&nbsp
<a href="/rasen_1" class="center">Rasen 1</a>&nbsp|&nbsp
<a href="/rasen_2" class="center">Rasen 2</a>&nbsp|&nbsp
<a href="/rasen_3" class="center">Rasen 3</a>&nbsp|&nbsp
<a href="/gewaechshaus" class="center">Gewächshaus</a>&nbsp|&nbsp
<a href="/wasseranschluss" class="center">Wasseranschluss</a>&nbsp|&nbsp
<a href="/hochbeet" class="center">Hochbeet</a>&nbsp|&nbsp
<a href="/tomatentuppen" class="center">Tomatentuppen</a>
</nav>
</footer>
</html>

View File

@ -0,0 +1,61 @@
<!DOCTYPE html>
<html>
<head>
<title>Rasen 2</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="/static/css/style.css" rel="stylesheet">
<script src="/static/scripts/rasen_2.js"></script>
</head>
<body>
<h1>Rasen 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>
<table>
<tr>
<td>Einschaltzeit</td>
<td class="input">
<input type="text" id="water_on" style="width: 70px;" onchange="on_change_config()"></input>
</td>
</tr>
<tr>
<td>Ausschaltzeit</td>
<td class="input">
<input type="text" id="water_off" style="width: 70px;" onchange="on_change_config()"></input>
</td>
</tr>
</table>
</td>
</tr>
</table>
</div>
</body>
<footer>
<nav>
<a href="/">Home</a>&nbsp|&nbsp
<a href="/rasen_1" class="center">Rasen 1</a>&nbsp|&nbsp
<a href="/rasen_2" class="center">Rasen 2</a>&nbsp|&nbsp
<a href="/rasen_3" class="center">Rasen 3</a>&nbsp|&nbsp
<a href="/gewaechshaus" class="center">Gewächshaus</a>&nbsp|&nbsp
<a href="/wasseranschluss" class="center">Wasseranschluss</a>&nbsp|&nbsp
<a href="/hochbeet" class="center">Hochbeet</a>&nbsp|&nbsp
<a href="/tomatentuppen" class="center">Tomatentuppen</a>
</nav>
</footer>
</html>

View File

@ -0,0 +1,61 @@
<!DOCTYPE html>
<html>
<head>
<title>Rasen 3</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="/static/css/style.css" rel="stylesheet">
<script src="/static/scripts/rasen_3.js"></script>
</head>
<body>
<h1>Rasen 3</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>
<table>
<tr>
<td>Einschaltzeit</td>
<td class="input">
<input type="text" id="water_on" style="width: 70px;" onchange="on_change_config()"></input>
</td>
</tr>
<tr>
<td>Ausschaltzeit</td>
<td class="input">
<input type="text" id="water_off" style="width: 70px;" onchange="on_change_config()"></input>
</td>
</tr>
</table>
</td>
</tr>
</table>
</div>
</body>
<footer>
<nav>
<a href="/">Home</a>&nbsp|&nbsp
<a href="/rasen_1" class="center">Rasen 1</a>&nbsp|&nbsp
<a href="/rasen_2" class="center">Rasen 2</a>&nbsp|&nbsp
<a href="/rasen_3" class="center">Rasen 3</a>&nbsp|&nbsp
<a href="/gewaechshaus" class="center">Gewächshaus</a>&nbsp|&nbsp
<a href="/wasseranschluss" class="center">Wasseranschluss</a>&nbsp|&nbsp
<a href="/hochbeet" class="center">Hochbeet</a>&nbsp|&nbsp
<a href="/tomatentuppen" class="center">Tomatentuppen</a>
</nav>
</footer>
</html>

View File

@ -26,38 +26,18 @@
<div id="water_times" style="visibility:hidden;"> <div id="water_times" style="visibility:hidden;">
<table class="center"> <table class="center">
<tr> <tr>
<td>Vormittag</td>
<td> <td>
<table> <table>
<tr> <tr>
<td>Einschaltzeit</td> <td>Einschaltzeit</td>
<td class="input"> <td class="input">
<input type="text" id="water_on_one" style="width: 70px;" onchange="on_change_config()"></input> <input type="text" id="water_on" style="width: 70px;" onchange="on_change_config()"></input>
</td> </td>
</tr> </tr>
<tr> <tr>
<td>Ausschaltzeit</td> <td>Ausschaltzeit</td>
<td class="input"> <td class="input">
<input type="text" id="water_off_one" style="width: 70px;" onchange="on_change_config()"></input> <input type="text" id="water_off" 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> </td>
</tr> </tr>
</table> </table>
@ -69,6 +49,11 @@
<footer> <footer>
<nav> <nav>
<a href="/">Home</a>&nbsp|&nbsp <a href="/">Home</a>&nbsp|&nbsp
<a href="/rasen_1" class="center">Rasen 1</a>&nbsp|&nbsp
<a href="/rasen_2" class="center">Rasen 2</a>&nbsp|&nbsp
<a href="/rasen_3" class="center">Rasen 3</a>&nbsp|&nbsp
<a href="/gewaechshaus" class="center">Gewächshaus</a>&nbsp|&nbsp
<a href="/wasseranschluss" class="center">Wasseranschluss</a>&nbsp|&nbsp
<a href="/hochbeet" class="center">Hochbeet</a>&nbsp|&nbsp <a href="/hochbeet" class="center">Hochbeet</a>&nbsp|&nbsp
<a href="/tomatentuppen" class="center">Tomatentuppen</a> <a href="/tomatentuppen" class="center">Tomatentuppen</a>
</nav> </nav>

View File

@ -0,0 +1,61 @@
<!DOCTYPE html>
<html>
<head>
<title>Wasseranschluss</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="/static/css/style.css" rel="stylesheet">
<script src="/static/scripts/wasseranschluss.js"></script>
</head>
<body>
<h1>Wasseranschluss</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>
<table>
<tr>
<td>Einschaltzeit</td>
<td class="input">
<input type="text" id="water_on" style="width: 70px;" onchange="on_change_config()"></input>
</td>
</tr>
<tr>
<td>Ausschaltzeit</td>
<td class="input">
<input type="text" id="water_off" style="width: 70px;" onchange="on_change_config()"></input>
</td>
</tr>
</table>
</td>
</tr>
</table>
</div>
</body>
<footer>
<nav>
<a href="/">Home</a>&nbsp|&nbsp
<a href="/rasen_1" class="center">Rasen 1</a>&nbsp|&nbsp
<a href="/rasen_2" class="center">Rasen 2</a>&nbsp|&nbsp
<a href="/rasen_3" class="center">Rasen 3</a>&nbsp|&nbsp
<a href="/gewaechshaus" class="center">Gewächshaus</a>&nbsp|&nbsp
<a href="/wasseranschluss" class="center">Wasseranschluss</a>&nbsp|&nbsp
<a href="/hochbeet" class="center">Hochbeet</a>&nbsp|&nbsp
<a href="/tomatentuppen" class="center">Tomatentuppen</a>
</nav>
</footer>
</html>