Page 1 of 1

how to WatchDog in ESP8266?

Posted: Thu Feb 27, 2020 11:15 am
by VladVons
esp8266-v1.12 firmware
https://docs.micropython.org/en/latest/ ... e.WDT.html

Code: Select all

import machine

WD = machine.WDT(timeout=2000)
TypeError: function doesn't take keyword arguments

WD = machine.WDT(0, 2000)
TypeError: function expected at most 1 arguments, got 2 

WD = machine.WDT(2000)
ValueError:
I wrote my own based on hardware timer

Code: Select all

# software watchdog, to prevent ESP freezing
class TWDog:
    def __init__(self, aID: int, aTOut: int):
        self._TOut = aTOut
        self._Cnt  = 0
        Timer = machine.Timer(aID)
        Timer.init(period = int(1 * 1000), mode = machine.Timer.PERIODIC, callback = self._CallBack)

    def _CallBack(self, aTimer):
        self._Cnt += 1
        if (self._Cnt >= self._TOut):
            print("WDT timeout")
            aTimer.deinit()
            machine.reset()

    def Feed(self):
        self._Cnt = 0
        
WDog = TWDog(0, 60)

Re: how to WatchDog asyncio application in ESP8266?

Posted: Thu Feb 27, 2020 12:29 pm
by jimmo
On ESP8266 the machine.WDT constructor takes either no arguments at all, or a single "id" argument, which must be zero.

so you should be able to use

Code: Select all

WD = machine.WDT()
VladVons wrote:
Thu Feb 27, 2020 11:15 am
OK, I wrote my own based on hardware timer, but with an asyncio it immediately reboots a programm
Without an asyncio it works fine
At first glance that looks fine, I'm not sure why it's interacting badly with asyncio. Would need to see the whole program I think.

Re: how to WatchDog in ESP8266?

Posted: Thu Feb 27, 2020 4:44 pm
by VladVons
1)
jimmo wrote:
Thu Feb 27, 2020 12:29 pm
On ESP8266 the machine.WDT constructor takes either no arguments at all, or a single "id" argument, which must be zero.
so you should be able to use
WD = machine.WDT()
What is a default timeout value for no arguments?


2)
When i run a hardware timer and asyncroniously call gc.collect() than system reboots.
I think 11K of free memory causes it.
I tested small application with only timer and async (25k of free RAM) - it is ok

Obviously i should freeze my project's libraries into firmware to reduce RAM consumption.
It is new for me....

Re: how to WatchDog in ESP8266?

Posted: Thu Feb 27, 2020 7:09 pm
by kevinkk525
I'm not sure the esp8266 hardware wdt can be used like that. I checked it a few months back and I think it was used by the micropython VM? So not for use for the user..

I wrote a software WDT that is still in use by all my esp8266 units and it works without any problems with uasyncio https://github.com/kevinkk525/pysmartno ... atchdog.py
The linked code still has some project specific code in it, that would need to be removed.
However I posted a clean code probably a few times on the forum already, so you might find it if you use the search :D

My esp8266 units typically run with 5-9kb of free RAM, so this shouldn't be an issue, unless your RAM is extremely fragmented but then you should receive a memory exception.

Re: how to WatchDog in ESP8266?

Posted: Fri Feb 28, 2020 6:58 am
by VladVons
I installed esp-open-sdk, micropython sources and finanly have my own firmware with all my libraries integrated.
(if some one needs a linux batch script to build firmvare write me privat)

The free RAM size inceased from 11k to 19k, but application still crashes when i use hardware timer.

without a timer invoked application works stable for a long time.
I can send misc requests to http. mqtt, etc

Code: Select all

rst cause:2, boot mode:(3,6)