Closed BasKloet closed 8 months ago
Hi guys, i have similar issue to this one where my client continues to publish messages but stops receiving them. It is started through systemd and restart fixes the problem.
Here is my source code.
Only logs i get looks like this:
Dec 19 21:53:48.463784 alarmpi python[292]: [19.12 21:53:48.462] [INF] [MQTT]: CONNACK received with code Success.
Dec 19 21:53:50.104132 alarmpi python[292]: [19.12 21:53:50.102] [INF] [MQTT]: CONNACK received with code Success.
Dec 19 21:53:51.855444 alarmpi python[292]: [19.12 21:53:51.846] [INF] [MQTT]: CONNACK received with code Success.
Dec 19 21:53:53.584828 alarmpi python[292]: [19.12 21:53:53.583] [INF] [MQTT]: CONNACK received with code Success.
Dec 19 21:53:55.373861 alarmpi python[292]: [19.12 21:53:55.372] [INF] [MQTT]: CONNACK received with code Success.
Dec 19 21:53:57.115493 alarmpi python[292]: [19.12 21:53:57.106] [INF] [MQTT]: CONNACK received with code Success.
Dec 19 21:53:58.885446 alarmpi python[292]: [19.12 21:53:58.875] [INF] [MQTT]: CONNACK received with code Success.
Dec 19 21:54:00.594539 alarmpi python[292]: [19.12 21:54:00.593] [INF] [MQTT]: CONNACK received with code Success.
Dec 19 21:54:02.342644 alarmpi python[292]: [19.12 21:54:02.341] [INF] [MQTT]: CONNACK received with code Success.
Dec 19 21:54:04.064335 alarmpi python[292]: [19.12 21:54:04.063] [INF] [MQTT]: CONNACK received with code Success.
Dec 19 21:54:05.784226 alarmpi python[292]: [19.12 21:54:05.782] [INF] [MQTT]: CONNACK received with code Success.
Dec 19 21:54:07.484318 alarmpi python[292]: [19.12 21:54:07.483] [INF] [MQTT]: CONNACK received with code Success.
Dec 19 21:54:09.265547 alarmpi python[292]: [19.12 21:54:09.253] [INF] [MQTT]: CONNACK received with code Success.
Dec 19 21:54:10.994314 alarmpi python[292]: [19.12 21:54:10.993] [INF] [MQTT]: CONNACK received with code Success.
I'd suggest moving the call to subscribe
into on_connect
(see the example in the readme).
If the connection goes down and the client reconnects then any existing subscriptions will be lost (clean_session
defaults to True
so subscriptions will not survive a loss of connection). Calling subscribe
from the on_connect
callback means that the subscription will be reinstated following reconnection. See this answer from Roger.
Thanks. I have updated the code and will see what happens. :)
@MattBrittan Hi!. Keeping clean_session=False
should do the trick of mantaining previous subscribes. So why after a long period of time the client losses all receiving messages but broker appears to be OK?
So why after a long period of time the client losses all receiving messages but broker appears to be OK?
In theory a qos1+ subscription can last forever (MQTT V3) if you always connect with cleansession=false
. However real life does not always match up to theory and things go wrong (e.g. broker restarted and fails to load sessions from storage) and the spec is not always followed (sometimes for good reason, many brokers set a limit to how long a session state is retained).
If you have a specific problem I'd suggest asking it in a different issue (or ideally somewhere like stackoverflow if it's not a bug in this client).
Closing as it looks like an answer was provided (and the question has been inactive for some time).
Hello, I have a python script that listens for MQTT from my thermostat messages (using paho) and updates my home automation accordingly. Both the program creating the MQTT messages, as well as the script that handles them run as Linux services on the same raspberry pi. They work very well together in most situations, but I have noticed the following problems:
I have a simple workaround that restarts the listener service at midnight and whenever the sending service restarts, but I feel that there is probably an underlying problem in my script that I should actually fix. My script is as follows:
It's not the prettiest script in the world, but I'd like to get it fully functioning and robust before I clean it up. Can anyone help me point out what I'm doing wrong or give me tips on how to analyze this problem further?
Thanks!