[SOLVED] Crashing/freezing every few hours

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
kevinkk525
Posts: 969
Joined: Sat Feb 03, 2018 7:02 pm

Re: Crashing/freezing every few hours

Post by kevinkk525 » Sat Dec 01, 2018 10:38 am

Considering that all this should be implemented in my code and heavily relies on your contribution in that part, I consider my application reliable and stable. The cause for freeze and crash must be outside of the application.
Also mkiotdev's code does not use wifi actively, it just checks periodically and reconnets. There's nothing that should freeze or crash the application.
Kevin Köck
Micropython Smarthome Firmware (with Home-Assistant integration): https://github.com/kevinkk525/pysmartnode

mkiotdev
Posts: 10
Joined: Sun Nov 11, 2018 9:12 am

Re: Crashing/freezing every few hours

Post by mkiotdev » Wed Dec 26, 2018 11:59 am

Hi guys!

I see there was much activity on this forum when I was partially unavailable. This gives me good feeling about community and platform!

To the subject. Stability or stability + WDT as it was described here remained unchainged, so my setup is stable, small software WDT with timer did the trick. This thread can be marked as SOLVED. I do not mind if board resets itself now or then. My situation is set to the 1 minute pace, process is not fast, it is controlling house heating, so 1 minute for data delivery to outside server is just fine. On the control level, timing is 1 second, but that is another sitiation.

Having stable situation is very extremely important, I think that this software WDT trick should be part of official documentation, it would
save me much of the time. I will look into ways of suggesting that.

Just to comment about WIFI interface. I am using STA, but AP has been active also. After reading your posts, I have just now disabled AP .

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

Re: Crashing/freezing every few hours

Post by kevinkk525 » Wed Dec 26, 2018 12:34 pm

You can mark your post as solved yourself, just edit the first post in the thread and change the subject.

I disabled AP too and that did not improve my stability. Sometimes they are stable 7 days, sometimes they reboot 5 times a day. But as they recover from it, all is good.
Kevin Köck
Micropython Smarthome Firmware (with Home-Assistant integration): https://github.com/kevinkk525/pysmartnode

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

They should never crash.

Post by pythoncoder » Thu Dec 27, 2018 9:43 am

I'm running a test with three ESP8266 devices connected to a server. Each communicates in both directions every five seconds. Code is designed according to the principles in this doc. This test runs 24/7.

I have accumulated some 1500 device hours of running with only one crash. This may have had an electrical cause: currently I'm using generic USB charger adaptors which can be of variable quality. I plan to get some branded Raspbery Pi adaptors designed for 24/7 operation.

I am of the view that properly written ESP8266 applications running on quality hardware do not crash.
Peter Hinch
Index to my micropython libraries.

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

Re: [SOLVED] Crashing/freezing every few hours

Post by kevinkk525 » Thu Dec 27, 2018 10:09 am

Maybe that is the difference, you are using quality hardware. I'm using cheap china NodeMCU with whatever power supply I have laying around. Sometimes they are stable for 7 days, sometimes they get stuck 4 times a day (although the interrupts work, which is weird).
There sure seems to be some external influences too and maybe some power spikes causes them to freeze as well.
The code surely is not the problem as we experienced this kind of behaviour even on the simplest code that is not even using sockets.
Kevin Köck
Micropython Smarthome Firmware (with Home-Assistant integration): https://github.com/kevinkk525/pysmartnode

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

Cheap hardware

Post by pythoncoder » Fri Dec 28, 2018 8:11 am

There is no question that hardware quality is very variable, both ESP8266 modules and USB power supplies. I have a USB PSU which works fine for charging phones. It even works for a couple of days running an ESP8266. Then it generates a burst of about 1000 power spikes before resuming normal operation. I also have ESP8266 kit suitable only for landfill.

There are two choices. Buy cheap hardware and waste days tracking down non-existent bugs. Or pay for reliability. Adafruit may not be cheap but their kit works.
Peter Hinch
Index to my micropython libraries.

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

Re: [SOLVED] Crashing/freezing every few hours

Post by kevinkk525 » Fri Dec 28, 2018 8:18 am

True enough but I don't have the money to buy expensive hardware, especially as the price quickly gets close to Raspberry Pis and then I'd definitely buy Raspberry Pis instead of esp8266/esp32. Would the Raspberry Pi Zero W be better available, I'd probably not buy esp32 at all.
Therefore I'm happy to equip my home with NodeMCUs that cost 2.5€ per unit + 1.5€ custom board + ~2€ components (htu21d, buzzer, led) + old and used usb power supplies = 6€ per unit.
For that price I accept that I have to use a software watchdog because the device partly freezes from time to time.
Kevin Köck
Micropython Smarthome Firmware (with Home-Assistant integration): https://github.com/kevinkk525/pysmartnode

User avatar
ebolisa
Posts: 55
Joined: Thu Feb 21, 2019 11:43 am
Location: Madrid, Spain

Re: Crashing/freezing every few hours

Post by ebolisa » Sat Oct 30, 2021 12:07 pm

mkiotdev wrote:
Fri Nov 30, 2018 4:45 pm

Code: Select all

## Simple software WDT implementation
wdt_counter = 0

def wdt_callback():
    global wdt_counter
    wdt_counter += 1
    if (wdt_counter >= 10):
        machine.reset()

def wdt_feed():
    global wdt_counter
    wdt_counter = 0

wdt_timer = machine.Timer(-1)
wdt_timer.init(period=1000, mode=machine.Timer.PERIODIC, callback=lambda t:wdt_callback())
## END Simple software WDT implementation
Code was copied to the board on 24th this month; no freezing/crashin since then!
@mkiotdev
Hi,
I'm experiencing the same problem with an ESP32 running MQTT. It pub/sub fine within the first few hours and then, interesting enough, it only publishes. So, a reset is in order.
Analizing your code, I noticed that you're running a simple timer and every 10 seconds, you're issuing a board reset. The feed function is never called and the counter is reset at reboot.
Having said that, why not just using a WDT as mentioned here?https://docs.micropython.org/en/latest/ ... hdog-timer and, BTW, are you still experiencing these types of problems?
TIA

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

Re: [SOLVED] Crashing/freezing every few hours

Post by davef » Sat Oct 30, 2021 5:34 pm

ebolisa,

You need to call wdt_feed() in your application before the 10 seconds run-out.

I have used this script often as in def wdt_callback() I get the time and log the state of various variables before the PERIOD runs out. It was very useful for debugging.

User avatar
ebolisa
Posts: 55
Joined: Thu Feb 21, 2019 11:43 am
Location: Madrid, Spain

Re: [SOLVED] Crashing/freezing every few hours

Post by ebolisa » Sat Oct 30, 2021 10:39 pm

davef wrote:
Sat Oct 30, 2021 5:34 pm
You need to call wdt_feed() in your application before the 10 seconds run-out.
Not sure I understand that. If I call wdt_feed() before the counter reaches 10 then, machine.reset() never gets executed. So, the whole code is null.
In my code I call machine.reset() via timer every 15 minutes and solved my problem but I don’t think it’s not a good solution.

Post Reply