def odbieranie(): if readconf(f'{current_serwer}.ini', "metoda") == "HTTP": client_data = request.args.to_dict() print(client_data['data']) elif readconf(f'{current_serwer}.ini', "metoda") == "MQTT": client.on_message = on_message return render_template("index.html")
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 serwer(): number = request.form.to_dict()['serwer'] server_adress = readconf(serwer_file, number) global current_serwer current_serwer = server_adress data = {"serwer": current_serwer} requests.post("http://127.0.0.1:5060/serwer", params=data) print(current_serwer) return render_template("index.html", value=number)
def on_message(client, userdata, message): config_file = f"{serwer}.ini" m_decode = str(message.payload.decode("utf-8")) if readconf(config_file, "aktuator") == 'True': signal = {"signal": 1} new_data = int(m_decode) new_data -= int(readconf(config_file, "active")) with open(f"data{serwer}.txt", "a") as file: file.write(new_data) file.write("\n") requests.post("http://127.0.0.1:5000/odbieranie", signal) client.publish("temat1", payload=new_data) elif int(m_decode) > int(readconf(config_file, "breakpoint")): signal = {"signal": 1} new_data = int(m_decode) new_data -= int(readconf(config_file, "active")) message_signal = readconf(config_file, "message") message_dict = {"message": message_signal} with open(f"data{serwer}.txt", "a") as file: file.write(str(new_data)) file.write("\n") requests.post("http://127.0.0.1:5000/updater/sygnal", message_dict) requests.post("http://127.0.0.1:5000/odbieranie", signal) client.publish("temat1", payload=new_data) else: signal = {"signal": 1} requests.post("http://127.0.0.1:5000/odbieranie", signal) client.publish("temat1", payload=m_decode) print(f"Received message:{m_decode}") return m_decode
def main(): data = request.form.to_dict() data = data["data"] config_file = f"{serwer}.ini" new_data = int(data) if readconf(config_file, "aktuator") == 'True': new_data -= int(readconf(config_file, "active")) data = str(new_data) with open(f"data{serwer}.txt", "a") as file: file.write(data) file.write("\n") data = {"data": data} requests.post("http://127.0.0.1:5000/odbieranie", params=data) elif int(new_data) > int(readconf(config_file, "breakpoint")): new_data -= int(readconf(config_file, "active")) data = str(new_data) with open(f"data{serwer}.txt", "a") as file: file.write(data) file.write("\n") data = {"data": data} message_signal = readconf(config_file, "message") message_dict = {"message": message_signal} requests.post("http://127.0.0.1:5000/updater/sygnal", message_dict) requests.post("http://127.0.0.1:5000/odbieranie", params=data) else: data = {"data": data} requests.post("http://127.0.0.1:5000/odbieranie", params=data) if readconf(config_file, "metoda") == 'MQTT': client.on_message = on_message return render_template("agregator.html")
def status(): status = readconf(f'{current_serwer}.ini', "wlacznik") return render_template("index.html", value2=status, value3=current_serwer)