You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
899 B

from flask import Flask, render_template, request
from flask_mqtt import Mqtt
app = Flask(__name__)
app.config['MQTT_BROKER_URL'] = 'localhost'
app.config['MQTT_KEEPALIVE'] = 5
app.config['MQTT_TLS_ENABLED'] = False
mqtt = Mqtt(app)
DATA = []
def connect(client, userdata, flags, rc):
def message(client, userdata, message):
data = dict(
def get():
if not DATA:
return ''
return '<ul>' + ''.join(
[f"<li>{data['topic']}: {data['payload']}" for data in DATA]
) + '</ul>'
@app.route('/send', methods=["POST"])
def send():
message = request.form.get('msg')
mqtt.publish('main', message)
return 'OK'
def home():
return render_template("index.html")