I am debugging my python written flask application (using flask_mqtt) I just deployed on a raspberry pi zero wh. On my linux machine (notebook) everything works like a charm, however, on the raspberry pi I discovered that the MQTT client does not acknowledge that it connects to the mosquitto broker although the MQTT log states
1589448206: New client connected from ::1 as 15ae66e3-7fc3-4739-a5f5-a0fe16e6ed28 (c1, k5, u'test'). 1589448230: New connection from ::1 on port 1883.
I just discovered that the flask app does acknowledge its connection when I do
sudo service mosquitto restart
Does anyone what might cause this?
As I said I use flask_mqtt (https://github.com/stlehmann/Flask-MQTT) and the follwing callbacks:
def subscribe_topics(): for topic in packet_manager.packets.keys(): mqtt.subscribe(topic) @mqtt.on_connect() def handle_connect(client, userdata, flags, rc): print(" * Connected to MQTT Broker successfully") subscribe_topics()
and the follwing MQTT settings
MQTT_CLIENT_ID = "webserver" MQTT_BROKER_URL = 'localhost' MQTT_BROKER_PORT = 1883 MQTT_USERNAME = 'test' MQTT_PASSWORD = 'test' MQTT_KEEPALIVE = 5 MQTT_TLS_ENABLED = False
The print + subscription is only executed after restarting the mosquitto service