After freeze and press ctrl+c i have this output:
-------------------------------------------------------------
Disconnecting...
Traceback (most recent call last):
File "main.py", line 5, in <module>
File "mqtt.py", line 149, in connect
File "mqtt.py", line 143, in main
File "mqtt.py", line 140, in main
File "mqtt.py", line 131, in main
File "umqtt/simple.py", line 168, in wait_msg
KeyboardInterrupt:
-------------------------------------------------------------
Any help?
MQTT code freeze after some time.
-
- Posts: 969
- Joined: Sat Feb 03, 2018 7:02 pm
Re: MQTT code freeze after some time.
Ah right, I think I may know why it is blocking.
Try using c.check_msg() instead of c.wait_msg()
wait_msg uses a blocking socket and if there's nothing to read from the mqtt broker, it will block forever as you don't even send pings. However, it should stop blocking when you send a command but apparently that doesn't help. But check if it works if you change to check_msg().
Try using c.check_msg() instead of c.wait_msg()
wait_msg uses a blocking socket and if there's nothing to read from the mqtt broker, it will block forever as you don't even send pings. However, it should stop blocking when you send a command but apparently that doesn't help. But check if it works if you change to check_msg().
Kevin Köck
Micropython Smarthome Firmware (with Home-Assistant integration): https://github.com/kevinkk525/pysmartnode
Micropython Smarthome Firmware (with Home-Assistant integration): https://github.com/kevinkk525/pysmartnode
Re: MQTT code freeze after some time.
I will try with check_msg() and return if works.
Re: MQTT code freeze after some time.
Same using check_msg(), after some time code freeze and after press ctrl+c return this:
Disconnecting...
Traceback (most recent call last):
File "main.py", line 5, in <module>
File "mqtt.py", line 149, in connect
File "mqtt.py", line 143, in main
File "mqtt.py", line 140, in main
File "mqtt.py", line 133, in main
KeyboardInterrupt:
Disconnecting...
Traceback (most recent call last):
File "main.py", line 5, in <module>
File "mqtt.py", line 149, in connect
File "mqtt.py", line 143, in main
File "mqtt.py", line 140, in main
File "mqtt.py", line 133, in main
KeyboardInterrupt:
-
- Posts: 969
- Joined: Sat Feb 03, 2018 7:02 pm
Re: MQTT code freeze after some time.
Can you post the code of mqtt.py?
Because I can not find these lines in the code you previously posted:
File "mqtt.py", line 149, in connect
File "mqtt.py", line 143, in main
File "mqtt.py", line 140, in main
File "mqtt.py", line 133, in main
Because I can not find these lines in the code you previously posted:
File "mqtt.py", line 149, in connect
File "mqtt.py", line 143, in main
File "mqtt.py", line 140, in main
File "mqtt.py", line 133, in main
Kevin Köck
Micropython Smarthome Firmware (with Home-Assistant integration): https://github.com/kevinkk525/pysmartnode
Micropython Smarthome Firmware (with Home-Assistant integration): https://github.com/kevinkk525/pysmartnode
-
- Posts: 969
- Joined: Sat Feb 03, 2018 7:02 pm
Re: MQTT code freeze after some time.
I'm not sure this could lead to problems but you should implement a short waiting time in the while loop, time.sleep_ms(10) should be enough.
The lines in your error trace are a bit strange as they point towards c.disconnect(), machine.reset() and gc.collect(). It shouldn't freeze at any of these methods.
The lines in your error trace are a bit strange as they point towards c.disconnect(), machine.reset() and gc.collect(). It shouldn't freeze at any of these methods.
Kevin Köck
Micropython Smarthome Firmware (with Home-Assistant integration): https://github.com/kevinkk525/pysmartnode
Micropython Smarthome Firmware (with Home-Assistant integration): https://github.com/kevinkk525/pysmartnode
Re: MQTT code freeze after some time.
After a lot of tests, a solution to put sleep_ms(500) in code works fine.
I put too a check_status when a publish to a topic in every 500ms.
Now esp32 is online about some last 3 hours:
Here is the code:
I put too a check_status when a publish to a topic in every 500ms.
Now esp32 is online about some last 3 hours:
Here is the code:
Code: Select all
while True:
c.check_msg()
check_status(c)
gc.collect()
sleep_ms(500)