server-test
This commit is contained in:
@@ -15,6 +15,15 @@ def fetch_command():
|
||||
shared.reset_command()
|
||||
return jsonify(pCd)
|
||||
|
||||
@esp.route('/online', methods=['POST'])
|
||||
def esp_online():
|
||||
data = request.get_json()
|
||||
sender_ip = request.remote_addr
|
||||
esp_ip = data.get("ip", "unknown")
|
||||
|
||||
print(f"ESP ONLINE von IP: {esp_ip}, roher IP: {sender_ip}")
|
||||
return jsonify({"status": "ok"})
|
||||
|
||||
@esp.route('/toggle-machine', methods=['GET'])
|
||||
def toggle_machine():
|
||||
|
||||
|
||||
@@ -20,6 +20,6 @@ def send_command():
|
||||
return f"Befehl '{pCd}' gespeichert."
|
||||
return "Kein Befehl angegeben.", 400
|
||||
|
||||
@unsecure.route('/live')
|
||||
def test():
|
||||
return render_template('live.html', users=[{'name': 'Max'}, {'name': 'Moritz'}, {'name': 'Hans'}])
|
||||
# @unsecure.route('/live')
|
||||
# def test():
|
||||
# return render_template('live.html', users=[{'name': 'Max'}, {'name': 'Moritz'}, {'name': 'Hans'}])
|
||||
|
||||
33
server.py
33
server.py
@@ -8,7 +8,8 @@ import paho.mqtt.client as mqtt
|
||||
|
||||
MQTT_BROKER = "localhost"
|
||||
MQTT_PORT = 1883
|
||||
MQTT_TOPIC = "coffee/status"
|
||||
MQTT_TOPIC_SUB = "coffee/status"
|
||||
MQTT_TOPIC_SEND = "coffee/command"
|
||||
|
||||
app = Flask(__name__, static_url_path='/unsecure/static')
|
||||
app.config['SECRET_KEY'] = 'super-secret-key'
|
||||
@@ -21,8 +22,8 @@ app.register_blueprint(esp)
|
||||
# MQTT Callback-Funktionen
|
||||
def on_connect(client, userdata, flags, rc):
|
||||
print(f"[MQTT] Verbunden mit Code {rc}")
|
||||
client.subscribe(MQTT_TOPIC)
|
||||
print(f"[MQTT] Subscribed to topic: {MQTT_TOPIC}")
|
||||
client.subscribe(MQTT_TOPIC_SUB)
|
||||
print(f"[MQTT] Subscribed to topic: {MQTT_TOPIC_SUB}")
|
||||
|
||||
def on_message(client, userdata, msg):
|
||||
print(f"[MQTT] Nachricht empfangen: {msg.topic} -> {msg.payload.decode()}")
|
||||
@@ -41,20 +42,22 @@ def mqtt_thread():
|
||||
client.loop_forever()
|
||||
|
||||
# Dummy-Daten-Thread
|
||||
def send_data():
|
||||
counter = 0
|
||||
while True:
|
||||
data = {
|
||||
'test': 'Live-Daten',
|
||||
'status': 'OK',
|
||||
'counter': counter
|
||||
}
|
||||
socketio.emit('update_data', data)
|
||||
counter += 1
|
||||
time.sleep(2)
|
||||
# def send_data():
|
||||
# counter = 0
|
||||
# while True:
|
||||
# data = {
|
||||
# 'test': 'Live-Daten',
|
||||
# 'status': 'OK',
|
||||
# 'counter': counter
|
||||
# }
|
||||
# socketio.emit('update_data', data)
|
||||
# counter += 1
|
||||
# time.sleep(2)
|
||||
|
||||
# Beide Threads starten
|
||||
threading.Thread(target=send_data, daemon=True).start()
|
||||
#threading.Thread(target=send_data, daemon=True).start()
|
||||
|
||||
|
||||
threading.Thread(target=mqtt_thread, daemon=True).start()
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
@@ -80,17 +80,6 @@
|
||||
function toggleMachine() {
|
||||
document.getElementById("machine-status").innerText = "PENDING";
|
||||
document.getElementById("machine-status-butt").classList.add("blink-orange");
|
||||
// fetch('/unsecure/esp/toggle-machine', { method: 'POST' })
|
||||
// .then(res => res.json())
|
||||
// .then(data => {
|
||||
// //console.log(data);
|
||||
// const inner = JSON.parse(data.status);
|
||||
// if (inner.command === 'machineToggle') {
|
||||
|
||||
// } else {
|
||||
// document.getElementById("machine-status").innerText = "SOME_ERR";
|
||||
// }
|
||||
// });
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
|
||||
Reference in New Issue
Block a user