[Music] Hello dear students of the channel Fernando K,
Today I'm going to show you a subject which is very important, which is a
business calls Watchdog, but after all What is this business coming to?
Security dog? You see that a dog here is not atoa, watch dog, watch dog means a watchdog
guard. What happens here people, we Let's talk about a problem that occurs
with their microcontrollable circuits I already did a test, I
I left it with ESP8266, with ESP32 and left it on my desk
sending, sending, sending something to the server, One fine day it hangs, why does it hang?
A lot makes a microcontroller crash people, is often an interference
electromagnetic radiation, can be a problem of power supply is not very good, it can
a lot and do the circuit brake.
So that's what happens, that's what I'll talk, here's the montage photo.
of one of the assemblies and I input Is this correct with you guys today?
So let's go! People in order to is a dog will implement the watchdog,
Using an interruption by time, by time, for a while and create a
example to simulate a lock and a watchdog I'll simulate with a little
The moment I trigger the key I go enter an infinite loop and there it will stay as
if I had set up a lock, okay? Good the staff is the next thing to do
if the program is frozen? And how to restart ESP32 without you
You have to reset physically, you will not ctrl + alt + del there right?
Understood? Even more knowing that an endPoint, with an ESP device, it may be
far away, it may be miles away from distance from you and is very
difficult then you have to have this mechanism, so the watchdog is for that, it's
that the translation is here I already told you guard dog and if it locks the
business here it will restart automatically and then we'll explain
how are we going to do it. Good how it works is this I'm not going here
too ... This is a little book, so I write only something,
because if you take the PDF later, you You know what I said here, you go.
remember. On this screen it is important talk here and I put it in red not to
forgetting is because we will use a interruption of time, an interruption
hardware, we will use a timer, a timer own ESP32 and I've been searching the
internet about ESP32 has almost no nothing, almost nobody talking about
interruption, I found it very important from here because
so professional use, let me speak here O
Professional use, people can not give you use a professional circuit micro-
controlled without you using the wacthdog why? Because watchdog it
prevents the system from locking and stays there stopped the eternal understood? So is
necessary to implement in many many cases, it is necessary to implement
watchdog and you will see that it is not difficult, not complicated, I'll explain
here, it's perfectly that or you'll get this piece of source code there and goes
to start using it is logical you have to know the criteria, I will explain that in your
criteria if you take this piece of my
source code and put it on your. So if there's already something working with ESP32
put on the watchdog it will get more stable. Well then here folks have some things,
some lines that are very important, Here I am initializing, I do
control of time, so I get This guy's pointer here, that hw_timer
and I initialize this guy already as NULL
because this guy is the one who will do the interrupt control, then I have a
timer here, that I have to make a timer, a timerBegin ie I play for
inside timer, the result of timerBegin to where i have 0 that is ed,
this zero is not zero time or nothing is a ad, the 80 is the 80 mega-hertz, knows how
config in arduino IDE? If you want a ESP32, because it has mega-hertz and the
ESP32's standard 80 mega-clock in there he multiplies this business
more frequently, but one official is that 80 megahertz you have to
Put this, I tested it, it's true and true. because you are enabling counter
progressive the timerAttachInterrupt, is as follows, it's here
this, function here, the true you have to set the timer You set to stay here and the resetModule
that's the guy who's callback him who function is it that will be called in
when the interruption occurs, which what time is it? What time does the interruption occur? At
time that time blows and I go explain well there in the source code, calm right,
but it's the next is three seconds 3 seconds,
passed these three seconds this function & resetModule here it
will be called. So, what happens? You have timeAlarmWrite
that's where you are setting what? 3 million micro second,
people I even put the 3 million micro second is a thing that three
seconds and true is because this will repeat always or always will tell
up to 3, count up to 3, count up to 3, but until he get up to 3, because so he is an accountant,
this guy is an accountant he is equal to C = C + 1 He's going to count the
time this guy counts the time if that face get to three seconds if he
reach for three seconds "pow" it resets so I can not ... How does this work?
The principle is this how it works? I can not let this timer get to
three seconds, he adds up microsecond by microsecond and goes, goes,
Go, it will arrive one hour, 3 seconds will reset. So why does it reset? It is for
if you can not increase the counter because your program
fought the "But fernando my program caught and how does he know he's going to
reset? Because it is hardware people, this timer is not a software, this timer
he is a physical accountant who has inside the chip understood that? Your program
being stopped, the time of it is rising. TimerAlarmEnable, or
timer enables interruption this is only enable function,
not here, that timerWrite what, that he does? Folks this is not a program, right? I'm
explaining function by function for later inside the program you do not get
lost, but all this is going to do meaning for you the time that people
starts to enter the source code, this does not It's the program yet, I'm just showing you how
is that we use the functions of interruption for time, right?
TimerWrite then I put timer that is that structure that I played there and this 0 ... there yes that
0 is an AID that 0 is a reset, I'm zeroing the accountant, the accountant was there
so many millions of seconds ... now Did he understand that?
B people Now I want you, more or
less with it in my head than I said I watched the video and let's go. This is
our assembly today, one of the assemblies huh?
Where do I have an ESP32, two LEDs, two managers and a push button here, then it's the next, what do I do? That
man over here, he's on a three-timer. seconds ie if I keep tight
less than three seconds it will not restart.
Now if I pass and burst the time of 3 seconds with finger pressing here that
push button what will happen? He goes restart and when it restarts it turns on
this green LED we will see? Look I'm going to keep tight the finger here, three seconds lit the green
Look, it's trashed, okay? What did I do? Everytime I rebound lights the green LED,
but look how interesting, dude that I like this pet, it restarts
Too fast, too fast, huh? So so, here again,
I pressed but I did not hold it? Now I'll hold the green LED will light up and
rebuked, so this is the watchdog already Working, okay? Well this one's personal is
following, it was an assembly I made of a master slave with a BME280, so I'm
sending temperature, humidity, pressure and This guy asks for this one and this one from here.
Send this one and I'm printing on both and here I did the following, I
I put watchdog of five seconds here and five seconds. It means that,
let's suppose that the endpoint hangs, passed, had electromagnetic interference
very big and this guy crashed, so I I'll simulate ... how do I simulate the
locking up I keep holding the inner loop
for five seconds, look, rebounded, restarted and is already sending
he has received and sent I am seeing? So if he had caught, he would
Do you understand the importance of watchdog? It's so much to teach that I should
have taught it here since the beginning. So here's the next one, here
caught, caught. You realize that you've caught on here? Catching can not go, rebounded
ready reducer is already receiving, already asked and already received back, see?
So you can crash here, you can crash here, that he always recovers, this is very
important when you have a device is miles away from
distance but rise above the building, on top of a
roof to stay giving ctrl + alt + del huh? So this here is the watchdog people,
this one is security, all the assembly that you do have to have a watchdog.
This is our montage today. Now that you've watched,
Let's continue here, let's continue. Here I want to give a message,
enter my blog fernandok se sign up with email to receive you have to
Verify your email there you will receive I'll send you an email, you confirm.
There are the following people, me too ... I I created my instagram now, so put it there.
the instagram, put on the screen the my instagram.
I want you to come into my instagram, in my facebook, did you understand? Because now I
I started recording some business, another day, boy. I received,
Dude, I got a st. I'm sleepless, man, I'm done.
sleep as long as I do not program this I do not know, I do not know. So I
ave maria I really like ST and the worst is that I I like ESP32 too.
So you'll like things like that there. far. But understand the instagram,
Facebook. In instagram I will show every time
receive a small plate from china USA I'm going to lay there first
no no instagram and then I want you to accompany, if
You have not subscribed to my channel if you subscribe and click on the bell, give
a jewel if you're liking my Video is good? Come on then, come on.
continue here. Pinout always right? What is my PDF? Booklet
huh? So here's my pinout of ESP32, the assembly that people
Did you see that I also talk about that LoRa then I both put watchdog
here in the assembly, in this simple assembly like ESP32, how much I put on the watchdog,
in the assembly of the ESP32 LoRa which is the same ESP né,
only one more chip, one LoRa chip I've already mentioned this in other videos right?
People the simplicity of the circuit, right? uses of GPIO03, GPIO04 and everyone goes
being happy is not true. So let's go ha ... I remembered one
business, i remembered a deal, The other day, I always said, I stayed
very happy because you look at mine. surprise a lot of people from portugal, put the
the flag here, a lot of people portugal is watching my videos
dude and I was very happy to know that my video crossed the sea
arrived there in portugal and it is very "spin" that right? Does not the Portuguese say that?
very cool, am I using the expression correctly? "Turn" there in
portugal means legal looks like a cool, beautiful thing, I do not know, something like that
so I'm talking like this already, I'm learning some expressions of portugal and a
hug to all our brothers Portuguese who are watching the
our video, my video and then I stayed Very happy, I get back, I get back.
I receive email from portugal I was really happy, even
Angola I already received, because after all we all we speak the same language, with some
difference or other there but it is the same language, We can understand each other, right?
So this is a big hug to you all. Let's go here,
continuing here and here is our program. We will have one each
interaction, we will, power reset our timer and
Let's use that business for that. of the lock button you already saw this on
video there, have watched, so it's a really cool business to us
will do the ESP restart is right?
Now let's start the source code. Here the source code is
here is the following the pinButton, the button I'm putting there,
I have red led, I have a green led I have to
set the pin. On here It's that timer that we defined it.
at start up as null and setup here It's not difficult, is not it, the thing is simple
until, I have serial.begin, there logic has pullup no input_pullup
because it's the button I'm going to tighten there you are
Red LED, green LED right? They have to be output right? Then I'll give you a delay.
500 milliseconds and then I do? I give a timerBegin to where?
This 0 is not an accountant 0 people, this one what is it? It's a timerID! Why is that?
timerID Fernando? Because if you want you can use four timers
You can pick up a timer every 2 Microsecond looks cool, the
every 2 microseconds I want to generate a wave, it generates a wave there with a timer,
so long, I want to do such a thing you can because you have a
control at the microsecond level, it is need? You need this business, you must,
you can trust it here. Division by 80, because it is 80 megahertz and
true it's because you're giving an okay on that guy. The timerAttachInterrupt you are passing the
timer, you already set this guy in there above, the callback function that is resetModule and
true because you're enabling this guy also and timerAlarmWrite because here
Write could be SET, could be timerAlarmSET, but I do not know what the guy wanted and put
Write, beauty same thing the structure of the timer there, 3 million microseconds that is
three seconds, I put it here also true because you're putting this in
as being true. TimerAlarmEnable hence I already agree with this writing and
I'm passing the timer argument right? Because I am enabled, from
from here this guy starts to work, only the from this Enable here, there is the following
what I do? Soon after I do the green LED
blink I give it a light on it.
he waits a second and erases, so much is that When he rebels he passes through here, then
the green LED lights up you saw in the video there the led green, did not they see? So that's all,
It's a simple thing, people. Here in the loop, now that the guy is going to stay all
repeating time, thank God it all fit into a screen, our face I love, that's why I do
code, think if I loop that has ten pages of loop you are
fried to understand this business Why do I even have to change the screen?
every time is complicated, so I always I do the programinha pequinhoininho so
What is didactic, right? I'll even make a comment here, let me do it
comment is the following face you've seen what the hell
when you take a code ... get one source code that is there in github
of a complicated trick, picks up the LoraOne protocol that is in github, wants to see
other business GRBL né for arduino there you take there face
Then you start trying to understand that business. giant code, huge code a lot of file
and such, what's wrong with that? You're not dumb, are not you, if you do not
you see stay calm you will not go to sleep
because of this, already noticed all you go on github and picks up a closed deal, who see a deal,
the firmware of a 3D printer, almost face nobody understands that "bagasse" there, but knows
because? The guy did not start doing the source code with 5,000 lines, with 10,000
line, he started with a program small, then it was increasing
increasing, increasing, increasing there is a business that has 20 thousand lines there,
complex, You go there to try to understand and not
Can you understand and what are you dumb? It is not! It is not! You know what this is, because the
complexity ... the guy started small and was increasing, increasing, increasing,
increasing, even these guys later, they other source codes in github and
they do not understand the other day I talked with a face
"I could not understand encryption algorithm, I did everything from
new Fernando, all over again I implemented everything again
I could not understand what the guy did there in the github there in encryption
there the guy took it and implemented it all over again,
Do you understand that? So stay calm. if you do not understand this lot of source code,
program soon so, because the guy presents everything in a single step, then you go crazy, but
It's not you, what's the problem, do you understand? O problem is that there is no didactic
look at a code made once its only, we know that the documentation you have
these guys over there github of life that faces "pindura" code
source there, there is no documentation, but neither a powerPoint
with the diagram does not have ne? Complicated that right? I think it was an outburst, this was broken because I too
I get code also in github that I do not understand, it's a hell not understand code and sometimes it is not because there is that
because the guy wrote the 3D printer code there, which is well done no, it is not! I get a lot, very, very, poorly written, but it works,
Everybody uses understood? There's a lot like this, there's a lot
thing in the world. Good continuing here people,
the first thing I do then, timerWrite, I count zero, first thing
I have to clear the counter, After what I do, I'll take the
current size, I get the current size ... sorry,
second thing I do here I get the current time, the initial time of the
loop, then what do I do here? I I check in this while line here,
digitalRead, I'm reading the pin and I'm Wondering if I'm squeezing the
button, because if I push the button, if I stay pushing the button it will stay
stuck in this tie and detail stuck in this loop is logical I give serial.println
that I am pressing the button and the digitalWrite the
the red LED I will turn on the LED red
I keep it 500 milliseconds on né and I continue my loop, if I take the
finger I can get out of this loop, I'm still going keep another second this guy here,
I'll turn red and then I'll put so "time spent inside the loop
milliseconds " Because? I took the time, because I got the
time up there and then I get the time down here are you seeing? I'll get the
current time minus the time I had taken up there, give me the amount of
time I got stuck there, so I give serial.println in this timer,
here in that time and after I do I turn off the red led and there it goes
so my loop, this way this while here, what does this while do?
It simulates your program crashed! It is logical that a program sometimes hangs and
does not mean that he got into a loop at Sometimes he caught, caught; an instruction pointer
there the "guy" is there everything "ragged" does not know nor where it goes,
does not always mean that he is in the loop, but the loop simulates a
blocking, because when locking happens the moment it crashes?
It prevents the timer from being reset, the team counter is reset, it goes
increasing, increasing, increasing, increasing, arrived at 3 seconds, he speaks ready now I
rebound, callback callback, callback function callback are you understanding?
So folks this is business here, so so logic and there is a business
Let's suppose, now you have a business. important that I have to talk,
let's suppose you have there a lot of thing you're doing in your
program there and you take more than three seconds then your time can ... your
Time burst can not be three seconds and let's assume another situation
that you do business very fast and you do not need to make a burst
of the time of a second can suddenly have a time overflow for example
200 milliseconds will then depend, this time here depends on your program,
then there are applications whose time It's very fast, it does not have to be the order.
seconds, was that clear? Depends on your application, okay? So let's go
over there, now we still have ground here, still
There's a LoRa business I'm going to talk about. People there are the following, right?
here the callback function reminds me that I already Did I tell you about this guy here, too? When you
puts this IRAM_ATTR this callback function, it is allocated in the
memory in a way that it calls Too fast, okay? So this here is a
issue of optimization. Ets_printf the same thing as printf tai I do not
I do not even know why I used this function here, I think To explain to you that you have her.
Also, here it is in this guy here in esp_restart_noos here you
restarts, here it resets in fact the ESP32 understood? I'm so sorry.
it's super simple, here people are the next time, to shoot the computer I
I thought it was not didactic, here a example of ESP32, where I turn it on, I
I call it, it does a lot of startup there after what happens? It's running here.
running setup is running and then he is in the loop to each one according to him
print loop here right, then what happens? I pressed the
button, at which I pressed the button it starts the counter and makes 0 500ms,
1 second, 1 second and a half, two seconds, two seconds and a half, 3 seconds "pow" burst.
Burst the time because I kept holding more of three seconds, look at the three here right? 3
second, here it happens, in that this guy will restart, then reboot and
appears a bunch of hexadecimal numbers of new and then it all starts over again
that's right? So here's to see for this place here. See if you can
increase here, it's terrible when you have small letter I do not think
didactic but I did not find another way to do this business here.
Here it's the same thing, here is as follows, holding down the
less than three seconds, so for example I rebutted, no, I started it, it was there, I called, I called, I called
I pressed the button, but here I I pressed the button and instead of
button when it gave a second I let go, I let out "pimba" what happened? When
I let it go, it was 2,500 milliseconds, it was close to locking
But I let it go, then he continued on loop, continued in the loop there it did not have the
treatment did not have to rebound, then situation here is ... there the first screen it
The 3 seconds burst, here he does not I told you before, did you understand? I wanted to
you understand the simple logic and It was here at 2500
milliseconds is fine. Now it's the following recalls in the video I showed
both, the two ESP32 LoRa a trading card
with the other there, BME280 né the endpoint so it's important that you
watch this video and understand the there because that's where I did
on here? I include the watchdog inside ... Because dude think about it, you have two lora
talking, you think this guy is not going to lock up
You think? Imagine the following you take and places in the middle of the pasture, a business
with the battery, you think this guy does not will lock
He will lock my friend! It is certain that Do you have any life that this guy is going to?
to brake so you have to have the wacthdog
connected on it, the other day I bought a Chinese radio of 5 watts, dude, have you seen 5Watts LoRa? Chinese
It makes a crazy deal right? Radio 5Watts LoRa is not LP ONE nor
here in China, where they did radio, have you thought of that?
But anyway the guys did I'm here in Brazil I I do not know, I'm going to record this video, 5 watts
1 watt but not lp one is not it not low power understood? It is not!
It's not low power anymore, understand? But Finally let me come back, let me go back, let's go back
here, watch this video here it is important.
Well then, let's go people now, now it's the next to implement whatchdog in the project, what we
let's do it? In the file ... remember that on here? Whoever watched the video remembers him,
LoRaSendReceiveBME280.im, what do you will do in it? You will add this
source code, people look there timer = NULL the people callback function, the
callback function, here we will have it, function that sets the timer,
I have already explained, the timerBegin, the timerAttach, the timerAlarmWhite
could be SET but they put it the name Write, timerAlarmEnable, beauty enabled and everyone
Go be happy. You start the serial and here you
calls all warm functions and set Whatchdog, which was a function
what did we do and people here? has timerWrite and the timer,
The timer you reset here is at that time. But when you zero ... Fernando when that
I zero my timer? It depends! You have to have a notion, do the following go with milles there, go
how much your principal bond spends, "to Fernando I My Head Tie It
is spending around 400ms. Beauty then put a burst
of 600 ms, cololoca one more time, one more time. You have security, 600ml
if you are sure the time maximum of your loop is 400ms. 400,
400ms you put 600, for you to have a margin understood? But it depends
much of the ... if you're messing with engine step, if you're messing with telekom,
you have great timeout time, everything This you have to analyze, why? Because
you have to keep clearing this counter, this little devil of that accountant there, I should not have
spoken of devil right? Anyway, good people look, it was not so
It's complicated, is not it? Was not, it was not, I do not know why I did not say that
matter before people are so important. But you You know why I did not? Because I do not
I could record two more videos for because you do not even have time to prepare
the "heck" of the video. Then it's the following
I want to thank the comments again cool fantastic that you are me
sending and until the next video [Music]
[Music]
No comments:
Post a Comment