i tried the example project of the Flask-MQTT (https://github.com/stlehmann/Flask-MQTT) with my local mosquitto broker. But unfortunatly it is not working. Subscription and publish are not forwared correctly. so i've added some logger messages:
def handle_connect(client, userdata, flags, rc):
print("CLIENT CONNECTED")
@mqtt.on_disconnect()
def handle_disconnect():
print("CLIENT DISCONNECTED")
@mqtt.on_log()
def handle_logging(client, userdata, level, buf):
print(level, buf)
16 Sending CONNECT (u0, p0, wr0, wq0, wf0, c1, k30) client_id=b'flask_mqtt'
CLIENT DISCONNECTED
16 Received CONNACK (0, 0)
CLIENT CONNECTED
16 Sending CONNECT (u0, p0, wr0, wq0, wf0, c1, k30) client_id=b'flask_mqtt'
CLIENT DISCONNECTED
16 Received CONNACK (0, 0)
The mosquitto Broker shows that it disconnects the flask app because of the client is already connected:
1580163250: New connection from 127.0.0.1 on port 1883.
1580163250: Client flask_mqtt already connected, closing old connection.
1580163250: New client connected from 127.0.0.1 as flask_mqtt (p2, c1, k30).
1580163250: No will message specified.
1580163250: Sending CONNACK to flask_mqtt (0, 0)
1580163251: New connection from 127.0.0.1 on port 1883.
1580163251: Client flask_mqtt already connected, closing old connection.
1580163251: New client connected from 127.0.0.1 as flask_mqtt (p2, c1, k30).
1580163251: No will message specified.
1580163251: Sending CONNACK to flask_mqtt (0, 0)
1580163251: Socket error on client flask_mqtt, disconnecting.
i also tested a simple python.paho mqtt client example without flask and it works as expected.
i also changed tried several loop starts inside the flask-mqtt code self.client.loop_start()
--> self.client.loop_forever()
... did not change anything.
so any idea where's the problem? i also debugged the flask-mqtt code and cannot find issues. (my python version is Python 3.6.9 (default, Nov 7 2019, 10:44:02) (my host system is elementary Linux)
maybe the FLASK-MQTT lib is deprecated ? any hint or idea is appreciated!