persistent wifi/mqtt connections or not

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
javilonso
Posts: 3
Joined: Fri May 20, 2022 11:38 am

Re: persistent wifi/mqtt connections or not

Post by javilonso » Fri May 20, 2022 11:51 am

pythoncoder wrote:
Wed Nov 20, 2019 9:13 am
The rating of the wall wart tells you little. The problem is reliability. You can charge a cellphone battery even if the PSU has occasional glitches, perhaps caused by electrical noise on the mains. Hardware devices will crash. I find wall warts designed for continuous running are best - e.g. the ones sold to power Raspberry Pi's.
Hi Peter, first of all thank for your amazing mqtt async library for micropython.

I am using MQTT at home with an ESP32 for sending temperature and humidity of my plants every 5 minutes through a Mosquito Broker, and plotting values in Grafana.

I started using mqtt simple but after some hours, or sometimes after just sending one message, I did not receive more values from the board.

I suspected that problem could be related with losing WiFI connection, so I decided to try your MQTT Async library.
Your library has worked well for 48h but after that, I experienced again the same problem.

The ESP32 does not send more messages, it is like froken.

The power for the ESP32 comes from an 18650 battery with a step up converter to 5V.
This battery is charged from a solar panel. The battery voltage is always above 4V.

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

Re: persistent wifi/mqtt connections or not

Post by pythoncoder » Fri May 20, 2022 5:48 pm

It is hard for me to debug this remotely. The library has been tested for long periods (many weeks) on ESP32.

I would try to determine whether, after a failure, the code is still running or whether the board has crashed. Write a task to flash an LED while running: a crash will stop the flashing. If failure is due to a crash one option is to use the watchdog timer (WDT) to reset the board. Crashing can be caused by electrical interference, although your power setup should be very robust. But it could pick up transients from an external source.
Peter Hinch
Index to my micropython libraries.

davef
Posts: 811
Joined: Thu Apr 30, 2020 1:03 am
Location: Christchurch, NZ

Re: persistent wifi/mqtt connections or not

Post by davef » Fri May 20, 2022 7:16 pm

Show a link to the little boost supply. Also, which ESP32 dev board?

javilonso
Posts: 3
Joined: Fri May 20, 2022 11:38 am

Re: persistent wifi/mqtt connections or not

Post by javilonso » Fri May 20, 2022 9:12 pm

pythoncoder wrote:
Fri May 20, 2022 5:48 pm
It is hard for me to debug this remotely. The library has been tested for long periods (many weeks) on ESP32.

I would try to determine whether, after a failure, the code is still running or whether the board has crashed. Write a task to flash an LED while running: a crash will stop the flashing. If failure is due to a crash one option is to use the watchdog timer (WDT) to reset the board. Crashing can be caused by electrical interference, although your power setup should be very robust. But it could pick up transients from an external source.
davef wrote:
Fri May 20, 2022 7:16 pm
Show a link to the little boost supply. Also, which ESP32 dev board?
Thank you for your replies!

I will add an LED as @pythoncoder suggests to check whether the crash stops the code.

@davef I am using an ESP32 clone (ESP-32 30Pin - https://es.aliexpress.com/item/1005001636295529.html)
And this is the boost supply https://es.aliexpress.com/item/4000626913742.html

I hope tol post news in the following days if the esp32 freezes again to debug!

Thanks again!

davef
Posts: 811
Joined: Thu Apr 30, 2020 1:03 am
Location: Christchurch, NZ

Re: persistent wifi/mqtt connections or not

Post by davef » Tue May 24, 2022 10:21 pm

Your ESP32 are using the same USB and 3V3 regulator chips as mine. You would have to put an oscilloscope on the output of your boost supply to see if it really handles the high current pulses you get when the WiFi fires up. I would try a 1000uF electro on the output. Also that 3V3 regulator chip has had some "bad-press", so I often put another 1000uF on the 3V3 pin on the header.

I have been chasing random lock-ups for more than a year ... now trying both a SW WDT and machine.WDT to see if that helps. Search <Simple software WDT implementation> on the forum. Peter also has an implementation., search <Peter Hinch github>

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

Re: persistent wifi/mqtt connections or not

Post by pythoncoder » Wed May 25, 2022 8:12 am

Peter Hinch
Index to my micropython libraries.

javilonso
Posts: 3
Joined: Fri May 20, 2022 11:38 am

Re: persistent wifi/mqtt connections or not

Post by javilonso » Wed May 25, 2022 9:14 pm

davef wrote:
Tue May 24, 2022 10:21 pm
Your ESP32 are using the same USB and 3V3 regulator chips as mine. You would have to put an oscilloscope on the output of your boost supply to see if it really handles the high current pulses you get when the WiFi fires up. I would try a 1000uF electro on the output. Also that 3V3 regulator chip has had some "bad-press", so I often put another 1000uF on the 3V3 pin on the header.

I have been chasing random lock-ups for more than a year ... now trying both a SW WDT and machine.WDT to see if that helps. Search <Simple software WDT implementation> on the forum. Peter also has an implementation., search <Peter Hinch github>

pythoncoder wrote:
Wed May 25, 2022 8:12 am
This is my soft WDT.


Thanks again for your responses!

I think the error came from the digital temperature sensor ds18b20. Due to some lose jump wire connections, the temp. sensor did not get power and when trying to read from the code, there was an error. I soldered the cables and hope this was the problem.
I have not experience yet the blocking state, so this might be the mistake, but I am not sure.

I have added a couple of leds as suggested to check the status of the code.

I also added the Watchdog time to reset the board after 2 minutes in case something goes wrong.
I used the official librar https://docs.micropython.org/en/latest/ ... e.WDT.html
@pythoncoder is there a big difference with your Soft WD library?

davef
Posts: 811
Joined: Thu Apr 30, 2020 1:03 am
Location: Christchurch, NZ

Re: persistent wifi/mqtt connections or not

Post by davef » Wed May 25, 2022 9:28 pm

DS18B20 errors, yep had those as well. If you don't handle the errors you can get lock-ups.

Code: Select all

     #  read 1-wire room temperature
        try:
            ds1.convert_temp()
        except onewire.OneWireError as error:
            try:
                with open('errors.txt', 'a') as outfile:
                    outfile.write('room temp ' + str(error) + '\n')
            except OSError:
                pass

        utime.sleep_ms(1000) #  min of 750ms for 1wire conversion

        try:
            room_temp = ds1.read_temp(bytearray(b'(\xe7q\xee\x04\x00\x00\xd0'))
        except Exception as error:
            try:
                with open('errors.txt', 'a') as outfile:
                    outfile.write('room temp ' + str(error) + '\n')
            except OSError:
                pass

        print ('Room temp = ', str(room_temp))

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

Re: persistent wifi/mqtt connections or not

Post by pythoncoder » Thu May 26, 2022 8:53 am

javilonso wrote:
Wed May 25, 2022 9:14 pm
...
I used the official librar https://docs.micropython.org/en/latest/ ... e.WDT.html
@pythoncoder is there a big difference with your Soft WD library?
A hardware WDT is always preferable to a software one because in a crash situation a soft WDT can be corrupted. My soft WDT is intended for platforms which lack a hardware implementation.
Peter Hinch
Index to my micropython libraries.

sopelekraspi
Posts: 1
Joined: Sun May 29, 2022 9:07 pm

Re: persistent wifi/mqtt connections or not

Post by sopelekraspi » Sun May 29, 2022 9:30 pm

It seams I have an issue with the simple.py library. I tried to run mqtt code and it was stopping/hanging after random number of cycles. I tried simple, umqttsimple (looks pretty the same code anyway), but with same results.

I run your code https://github.com/peterhinch/micropyth ... nchmark.py and it hangs on line 65

Code: Select all

c.check_msg()
.

Looks like

Code: Select all

 check_msg
waits for message or just hang/freeze.

Any ideas?

Device is MicroPython v1.18 on 2022-01-17; Arduino Nano RP2040 Connect with RP2040, connected via Thony 3.2.7 to Linux Mint 20.3, Python 3.8.10 and Tk8.6.10

Post Reply