mqqt test v4 (with web)

This commit is contained in:
derlole
2025-04-25 10:39:07 +00:00
parent fbe64760e0
commit 476524b6c1
3 changed files with 88 additions and 5 deletions

View File

@@ -1,10 +1,30 @@
from flask import Blueprint, render_template, request, jsonify
import routes.shared as shared
from flask import Flask, jsonify, request
import paho.mqtt.client as mqtt
esp = Blueprint('eps', __name__, url_prefix='/unsecure/esp')
MQTT_BROKER = "localhost" # oder IP/Domain
MQTT_PORT = 1883
MQTT_TOPIC = "iot/machine"
@esp.route('/')
def fetch_command():
pCd = shared.pending_command
shared.reset_command()
return jsonify(pCd)
return jsonify(pCd)
@esp.route('/toggle-machine', methods=['POST'])
def toggle_machine():
pCd = shared.pending_command
pCd['command'] = 'machineToggle'
pCd['command-URL'] = 'NO_URL'
pCd['command-expected'] = 'machineStatusResponse'
pCd['command-expected-URL'] = 'http://lires.de/unsecure/esp/machine-status'
client = mqtt.Client()
client.connect(MQTT_BROKER, MQTT_PORT, 60)
client.publish(MQTT_TOPIC, pCd)
client.disconnect()
return jsonify({"status": pCd})