Page 1 of 2

MQTT code freeze after some time.

Posted: Mon Jul 01, 2019 1:05 pm
by bergpb
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?

Re: MQTT code freeze after some time.

Posted: Mon Jul 01, 2019 1:21 pm
by kevinkk525
Please give us more information on what libraries you use and your code.

Re: MQTT code freeze after some time.

Posted: Mon Jul 01, 2019 1:46 pm
by bergpb
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.

Re: MQTT code freeze after some time.

Posted: Mon Jul 01, 2019 3:09 pm
by kevinkk525
Please show us your code otherwise it would be just guesswork.

Re: MQTT code freeze after some time.

Posted: Mon Jul 01, 2019 3:35 pm
by pythoncoder
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.

Re: MQTT code freeze after some time.

Posted: Mon Jul 01, 2019 11:41 pm
by bergpb
Hey, sorry for late answer.
This is my code:
https://pyfiddle.io/fiddle/135928ff-8e1 ... a9/?i=true

Re: MQTT code freeze after some time.

Posted: Tue Jul 02, 2019 5:52 am
by pythoncoder
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?

Re: MQTT code freeze after some time.

Posted: Tue Jul 02, 2019 6:46 am
by kevinkk525
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.

Re: MQTT code freeze after some time.

Posted: Tue Jul 02, 2019 10:06 am
by bergpb
@python coder and @kevinkk525 codes just freeze and dont receive any updates anymore.
I try to press ctrl+c to get error.

Re: MQTT code freeze after some time.

Posted: Tue Jul 02, 2019 10:14 am
by kevinkk525
You could implement a publish every 10 seconds and a console output. Then you would see if the connection or the device itself freeze.