Hardware watchdog

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
remko2000
Normal user
Posts: 53
Joined: 28 Dec 2017, 15:56

Hardware watchdog

#1 Post by remko2000 » 27 Oct 2019, 12:02

I've bought a hardware watchdog which I want to use with a wemos d1 and a temperature sensor I2C (GPIO 4 and 5).The intention is that my wemos reset if it crashes or lost his internetconnection.

This is the watchdog:
https://www.freetronics.com.au/pages/wa ... bVydy1x8dU

I read some info on internet but a lot of situations are speaking of softwarewatchdogs and not hardwaresolutions. I think I have to use some rules in ESP easy (version 20191003).

The sketch called in the wiki:
void resetWatchdog() {
digitalWrite(2, HIGH);
delay(20);
digitalWrite(2, LOW);
}
is for arduino IDE and I can't use in rules.

How do I connect this watchdog to my wemos:
VCC- VCC
GND- GND
IN- GPIO 2 (for example)
OUT- RST (?)

Is this correct?

How do I use this GPIO's in rules and do I have to make some other changes in ESP?

TD-er
Core team member
Posts: 1776
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Hardware watchdog

#2 Post by TD-er » 27 Oct 2019, 12:15

Well if it is unable to reconnect, you can set the "Connection Failure Threshold" (Tools -> Advanced, bottom of the page)
This will reset the node after N failed attempts. (0 = disabling this feature)

The ESP itself has 2 watchdog timers:
- Software Watchdog (triggered when a loop takes > 2 seconds without calling delay)
- Hardware Watchdog (triggered after ~6 seconds when there has been no call for delay)

Of course there are other causes possible where the ESP does run into some undefined state and not being able to continue.
As long as the code is still running and calling delay every now and then, it may continue to run like this forever.

Your external watchdog may then kick in if its timer has not been reset within due time.
I think you need to set a simple rule to trigger a GPIO pin to be set and reset every N seconds.

For example (GPIO 2 is where I have my LED connected on a NodeMCU, so easy to verify)

Code: Select all

On System#Boot Do
 Monitor,GPIO,2
 TimerSet,1,1
EndOn

On Rules#Timer=1 Do
 GPIOtoggle,2
 TimerSet,1,1
EndOn
Just to illustrate (and test) what else can be done on such a change of GPIO state:

Code: Select all

On GPIO#2 Do
 Let,5,%eventvalue% //This capture the GPIO state
 LogEntry,LED turned "[VAR#5#!O]" "[INT#5#!O]" ([Plugin#GPIO#Pinstate#2])
EndOn

remko2000
Normal user
Posts: 53
Joined: 28 Dec 2017, 15:56

Re: Hardware watchdog

#3 Post by remko2000 » 27 Oct 2019, 14:07

thx for your quick answer. I have immediately set the ' Connection Failure Threshold'. A good tip!

So if I understand you correctly; the way I describe to connect the watchdog is correct ('in' on gpio2 and 'out' on reset).
If I set the rule you described the wemos set the gpio2 if esp gets a undefined status and because the gpio2 switch his state the hardware watchdog gives a signal to the rst pin which reset the wemos. Am I correct?

The other piece of rule (rule 2?) sets a logrule when the GPIO 2 switch his state?

TD-er
Core team member
Posts: 1776
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Hardware watchdog

#4 Post by TD-er » 27 Oct 2019, 14:21

What this rule does is simply setting the GPIO high every set number of seconds (1 second in my example)
The whole idea is that it must be running in order to do so. If for whatever reason the ESP is no longer executing its rules engine, then the hardware watchdog will not reset its timer and when the timer reaches a set count value, then it will initiate a reset.

I don't know the watchdog chip you have. Just make sure the output level is correct and not "inverted" or else the ESP will never boot.

The extra part I added is just to illustrate what else you could do with such an interval timer.
For example monitoring another pin to see if a sensor has given a response lately.
Then you can use your ESP rules to do other things like resetting, switching off the sensor power, etc.

remko2000
Normal user
Posts: 53
Joined: 28 Dec 2017, 15:56

Re: Hardware watchdog

#5 Post by remko2000 » 27 Oct 2019, 20:23

I've connect my watchdog and connect it with D4 (GPIO2). The output of the watchdog connected on the reset of my wemos. I uploaded the rule described by TD-er:

Code: Select all

On System#Boot Do
 Monitor,GPIO,2
 TimerSet,1,1
EndOn

On Rules#Timer=1 Do
 GPIOtoggle,2
 TimerSet,1,1
EndOn
the blue led on my wemos flashes every second. This looks good.

How do I know if the watchdog reset in a good way when needed?

Each time the watchdog timer module is reset I see a green LED pulse (every second) on, giving a visual feedback of the activity. If the module resets my Wemos it must pulse a red LED but I want to test this.

This is the watchdog I have:
https://www.freetronics.com.au/pages/wa ... bVydy1x8dU

TD-er
Core team member
Posts: 1776
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Hardware watchdog

#6 Post by TD-er » 27 Oct 2019, 20:31

Just disable the rules (checkbox on the Advanced settings page) and after a while it will reset.
Depending on the set timer of your watchdog, it will reset after the set time (since the last pulse from the GPIO)
Only thing I don't know is whether the watchdog will also reset when the GPIO pin is still high.
This can also happen in a "normal" crash.
You could change the rules a bit to pull low and high in the same block, or by sending a single pulse command.

remko2000
Normal user
Posts: 53
Joined: 28 Dec 2017, 15:56

Re: Hardware watchdog

#7 Post by remko2000 » 27 Oct 2019, 22:02

I disable the rules but nothing happens. No red light/resetting of my watchdog after 5 minutes (the resttime of my watchdog).
I add a second timer to set gpio 2 also low (toggle 1?). I'm a little but a newbie with rules so maybe I doing it wrong? This doesn't work.

Code: Select all

On System#Boot Do
 Monitor,GPIO,2
 TimerSet,1,10
EndOn

On System#Boot Do
 Monitor,GPIO,2
 TimerSet,2,20
EndOn

On Rules#Timer=1 Do
 GPIOtoggle,2
 TimerSet,1,1
EndOn

On Rules#Timer=2 Do
 GPIOtoggle,1
TimerSet,2,1
EndOn

TD-er
Core team member
Posts: 1776
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Hardware watchdog

#8 Post by TD-er » 29 Oct 2019, 09:38

You could also try pulse or longpulse_ms.
See https://espeasy.readthedocs.io/en/lates ... mmand.html

I think you need to make sure the pin is at the default state.

Also you must check if the pin does need a pull-up resistor.
I don't know if the original Arduino board is using pull-up resistors. The example using an Arduino does not seem to need resistors, but maybe the ESP does need to actively pull up the GPIO.
Either by an internal pull-up resistor or an external one.

remko2000
Normal user
Posts: 53
Joined: 28 Dec 2017, 15:56

Re: Hardware watchdog

#9 Post by remko2000 » 29 Oct 2019, 20:33

I'm a little further now. The watchdog now resets my wemos around 5 minutes if I don't connect de input to a GPIO. If I do connect to GPIO0 and use this code:

Code: Select all

On System#Boot Do
 Monitor,GPIO,0
 TimerSet,1,1
EndOn

On Rules#Timer=1 Do
 GPIOtoggle,0
 TimerSet,1,1
EndOn
I see a green LED pulse (heartbeat) on my watchdog. The problem is that if I disable rules (and reboot) the green LED stays on dimmed and it don't reset my wemos.
To summarize, only if I don't connect the input GPIO to my wemos does the watchdog work properly. Is this indeed a problem with a pull-up resistor and if yes. how do I apply this? What kind of resistor do I need?

TD-er
Core team member
Posts: 1776
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Hardware watchdog

#10 Post by TD-er » 29 Oct 2019, 20:48

I don't know the watchdog chip.
You can check by configuring a switch plugin for that pin and set it to enable the (internal) pull up resistor.
Apparently you have some LED to verify the state of the pin.

If you need to use an external resistor (which is perhaps the best here, since the ESP could also be crashed before it activates the pull-up resistor), I would suggest to try a 10k or 12k.
Whatever is available between 4k7 and 22k

Remember to pull it to 3v3 (not 5V)

remko2000
Normal user
Posts: 53
Joined: 28 Dec 2017, 15:56

Re: Hardware watchdog

#11 Post by remko2000 » 02 Nov 2019, 14:43

I've checked the pull up with a switch input under devices.
No succes. On the moment I add a switch input (with of without enabled pull up, doens't matter) on GPIO 0 the green led on my watchdog doens't blink anymore but stays on. So I don't think the problem is a pull up resisitor. If I disable this switch input and reboot the wemos the green led blinking again.
The problem is that I don't have a clue what the problem could be els.

remko2000
Normal user
Posts: 53
Joined: 28 Dec 2017, 15:56

Re: Hardware watchdog

#12 Post by remko2000 » 04 Nov 2019, 15:44

I think it working now correctly:

I use this rule:
On System#Boot Do
Monitor,GPIO,0
TimerSet,1,1
EndOn

On Rules#Timer=1 Do
Pulse,0,1,500
TimerSet,1,1
EndOn
I connect the ' in' on GPIO0 and ' out' on RST. No switch input with pullup resisitor of hardware pull up needed.

If I disable 'rules' the watchdog timer resets my wemos after 5 minutes. The only strange thing is that after this reset the green led stays on on my watchdog (not flashing like before) and no reset for a second time after 5 minutes (still rules disabled).

TD-er
Core team member
Posts: 1776
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Hardware watchdog

#13 Post by TD-er » 04 Nov 2019, 19:13

GPIO-0 has a pull-up resistor to select the right boot mode.
So you better try another pin.
See: https://espeasy.readthedocs.io/en/lates ... on-esp8266

remko2000
Normal user
Posts: 53
Joined: 28 Dec 2017, 15:56

Re: Hardware watchdog

#14 Post by remko2000 » 05 Nov 2019, 16:23

I use now GPIO12, this needs a pull up resisitor (I use now the internal one). This works fine. When I enable 'rules' the watchdog keeps resetting my wemos every 5 minutes. It should be nice if I recieve a message (email/prowl) when the watchdog kicks in. Is this simple to realize?

This is my code:

Code: Select all

On System#Boot Do
 Monitor,GPIO,12
 TimerSet,1,1
EndOn

On Rules#Timer=1 Do
 Pulse,12,1,500
 TimerSet,1,1
EndOn

TD-er
Core team member
Posts: 1776
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Hardware watchdog

#15 Post by TD-er » 05 Nov 2019, 22:02

You can enable the notifications and let the unit send an email.

See: https://www.letscontrolit.com/wiki/inde ... ifications
Please note that this may be a bit outdated information.
You must also use a mail provider which allows to use a non-encrypted way of sending mails, like SMTP2go (mentioned in the wiki page)
So Google's Gmail will not work.

Post Reply

Who is online

Users browsing this forum: No registered users and 16 guests