MQTT code freeze after some time.

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
bergpb
Posts: 16
Joined: Sun Jun 10, 2018 2:51 pm

MQTT code freeze after some time.

Post by bergpb » Mon Jul 01, 2019 1:05 pm

Hello, i have a mqtt code with subscribe method i my ESP32 with latest micropython build.
After some time, code froze and i cant receive more updates from subscribe.
I try to put gc.collect in code to clean garbage but not works.
Any solutions to this?

kevinkk525
Posts: 527
Joined: Sat Feb 03, 2018 7:02 pm

Re: MQTT code freeze after some time.

Post by kevinkk525 » Mon Jul 01, 2019 1:21 pm

Please give us more information on what libraries you use and your code.
Kevin Köck
Micropython Smarthome Firmware: https://github.com/kevinkk525/pysmartnode

bergpb
Posts: 16
Joined: Sun Jun 10, 2018 2:51 pm

Re: MQTT code freeze after some time.

Post by bergpb » Mon Jul 01, 2019 1:46 pm

Hello, i'm use this library: https://github.com/micropython/micropyt ... qtt.simple,
and this https://docs.micropython.org/en/latest/ ... ujson.html.
I'm use ujson to get a js from outher publisher device and execute based on command received.

kevinkk525
Posts: 527
Joined: Sat Feb 03, 2018 7:02 pm

Re: MQTT code freeze after some time.

Post by kevinkk525 » Mon Jul 01, 2019 3:09 pm

Please show us your code otherwise it would be just guesswork.
Kevin Köck
Micropython Smarthome Firmware: https://github.com/kevinkk525/pysmartnode

User avatar
pythoncoder
Posts: 3716
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: MQTT code freeze after some time.

Post by pythoncoder » Mon Jul 01, 2019 3:35 pm

While I agree with @kevinkk525 - there is little we can say without seeing your code - you could debug it yourself by issuing ctrl-c at the REPL when it hangs. The traceback will tell you what it was doing at the time, which might give you some clues. And us, if you show us your code and the traceback.

You might also read my notes on achieving reliable connections on WiFi. This was based on experience of myself and @kevinkk525 on the pitfalls on offer.
Peter Hinch

bergpb
Posts: 16
Joined: Sun Jun 10, 2018 2:51 pm

Re: MQTT code freeze after some time.

Post by bergpb » Mon Jul 01, 2019 11:41 pm

Hey, sorry for late answer.
This is my code:
https://pyfiddle.io/fiddle/135928ff-8e1 ... a9/?i=true

User avatar
pythoncoder
Posts: 3716
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: MQTT code freeze after some time.

Post by pythoncoder » Tue Jul 02, 2019 5:52 am

I can't see any obvious error and you have plenty of exception trapping in place. When it fails, do you get no output from your exception handlers? What happens if you enter ctrl-c after faulure?
Peter Hinch

kevinkk525
Posts: 527
Joined: Sat Feb 03, 2018 7:02 pm

Re: MQTT code freeze after some time.

Post by kevinkk525 » Tue Jul 02, 2019 6:46 am

Hmm me neither. Any connection problem should result in a reset in that code.
Might be helpful to know what exactly is happening when the device doesn't react anymore.
Kevin Köck
Micropython Smarthome Firmware: https://github.com/kevinkk525/pysmartnode

bergpb
Posts: 16
Joined: Sun Jun 10, 2018 2:51 pm

Re: MQTT code freeze after some time.

Post by bergpb » Tue Jul 02, 2019 10:06 am

@python coder and @kevinkk525 codes just freeze and dont receive any updates anymore.
I try to press ctrl+c to get error.

kevinkk525
Posts: 527
Joined: Sat Feb 03, 2018 7:02 pm

Re: MQTT code freeze after some time.

Post by kevinkk525 » Tue Jul 02, 2019 10:14 am

You could implement a publish every 10 seconds and a console output. Then you would see if the connection or the device itself freeze.
Kevin Köck
Micropython Smarthome Firmware: https://github.com/kevinkk525/pysmartnode

Post Reply