def panel(): name = request.form.to_dict() createConfig(name['rejestracja']) server_number = str(counter()) new_serwer = name['rejestracja'] updateconf(serwer_file, server_number, new_serwer) global current_serwer current_serwer = new_serwer print(current_serwer) return render_template("index.html")
def aktuator(): client_data = request.args.to_dict() if "aktuator" in client_data: global aktuator aktuator = client_data["aktuator"] validation = ["True" == aktuator, "False" == aktuator] if any(validation): topic = "aktuator" updateconf(config_file, topic, client_data['aktuator']) return client_data else: return { "status": 400, "message": "Wybrana opcja nie jest obslugiwana" }, 400 else: return {"status": 400, "message": "Zle argumenty"}, 400
def wybor_metody(): client_data = request.args.to_dict() if "metoda" in client_data: global metoda metoda = client_data["metoda"] validation = ["HTTP" == metoda, "MQTT" == metoda] if any(validation): topic = "metoda" updateconf(config_file, topic, client_data['metoda']) return client_data else: return { "status": 400, "message": "Wybrana metoda nie jest obslugiwana" }, 400 else: return {"status": 400, "message": "Zle argumenty"}, 400
def wlacznik(): updateconf(config_file, "message", "Temperatura jest zbyt wysoka, wlaczam klimatyzacje") updateconf(config_file, "active", "10") updateconf(config_file, "breakpoint", "30") client_data = request.args.to_dict() if "wlacz" in client_data: global wlacz wlacz = client_data["wlacz"] validation = ["True" == wlacz, "False" == wlacz] if any(validation): topic = config_keys["switch"] topic2 = config_keys["frequency"] updateconf(config_file, topic, client_data['wlacz']) status = readconf(config_file, topic) if status == 'True': print("jestem tu3") for data in data_list: status = readconf(config_file, topic) freq = readconf(config_file, topic2) if status == 'True': metoda = readconf(config_file, config_keys["method"]) if metoda == "HTTP": print("wysylam http") data = {"data": data} requests.post("http://127.0.0.1:5060/", data=data) else: print("wysylam mqtt") data = int(data) triger = {"data": 1} requests.post("http://127.0.0.1:5060/", data=triger) client.publish("temat", payload=data) else: return {"1": 1} time.sleep(int(freq)) else: return {"1": 1} else: return { "status": 400, "message": "Wybrana opcja nie jest obslugiwana" }, 400 else: return {"status": 400, "message": "Zle argumenty"}, 400
def czestotliwosc(): topic = "czestotliwosc" client_data = request.args.to_dict() updateconf(config_file, topic, client_data['czestotliwosc']) return client_data