1
00:00:00,210 --> 00:00:07,830
So let's begin by replacing the daily function with the SHIGEMATSU, what you're looking at is version

2
00:00:07,830 --> 00:00:09,120
three of the sketch.

3
00:00:09,500 --> 00:00:18,210
This delay is a blocking execution of anything on the security for one second and obviously is very

4
00:00:18,220 --> 00:00:18,820
inefficient.

5
00:00:18,840 --> 00:00:22,290
So I'm going to replace it with.

6
00:00:24,300 --> 00:00:25,320
Version for.

7
00:00:26,360 --> 00:00:34,540
Of our sketch, which then introduces the task scheduler, then show the necessary modifications to

8
00:00:34,540 --> 00:00:40,780
use a as a scheduler in place of delay, if you want to learn more about the tasks because you have

9
00:00:40,780 --> 00:00:46,840
a look at this GitHub location, it's this page here which contains lots of examples and of course,

10
00:00:46,840 --> 00:00:51,870
an introduction to the various bits and pieces of the task scheduler and how to use it.

11
00:00:51,880 --> 00:00:58,420
It's actually an excellent and very high quality library that I have used in a couple of other courses,

12
00:00:58,690 --> 00:01:07,000
especially in E.S.P 32 for busy people and be to unleash the Fuster, the desks because you casula extensively

13
00:01:07,420 --> 00:01:14,590
in these courses and it's very reliable, very efficient and very configurable as well.

14
00:01:14,970 --> 00:01:16,690
So check the documentation out.

15
00:01:17,020 --> 00:01:21,820
Now, as far as the necessary changes are concerned, that you see is very straightforward.

16
00:01:22,160 --> 00:01:25,380
First of all, we need to include the tasks cédula here.

17
00:01:26,050 --> 00:01:31,510
First of all, you will need to import the task scheduler and you can do it using the library manager.

18
00:01:32,720 --> 00:01:35,360
Just search for a task scheduler.

19
00:01:43,730 --> 00:01:50,750
It's this one here by utterly Pankow amusing version three point one point six to install the latest

20
00:01:50,750 --> 00:02:00,020
available version and then include the original head of file at the head of your sketch.

21
00:02:00,740 --> 00:02:05,600
Then what we do here is to declare a callback.

22
00:02:06,020 --> 00:02:16,070
I mark any function that I'll be using as a callback from the scheduler with the letters C B at the

23
00:02:16,070 --> 00:02:17,610
end of the name of the function.

24
00:02:17,960 --> 00:02:22,010
So this function here is implemented further down in the sketch.

25
00:02:22,130 --> 00:02:29,060
I'm going to jump right there to show you and then go back up in the header where we said.

26
00:02:30,910 --> 00:02:38,350
They released a report, so your humidity go back and so your humidity core back, you may remember

27
00:02:38,350 --> 00:02:39,620
it from previous versions.

28
00:02:39,640 --> 00:02:42,470
This was formally known as reports.

29
00:02:42,470 --> 00:02:47,040
So your humidity could have just left it as this without renaming it.

30
00:02:47,350 --> 00:02:54,640
But I find that by putting this at the end of the function name, it's easy to recognize that this function

31
00:02:55,000 --> 00:03:00,110
is being called back by the scheduler inside the function.

32
00:03:00,280 --> 00:03:01,900
There's nothing changed.

33
00:03:01,930 --> 00:03:04,070
It's exactly the same as in version three.

34
00:03:04,180 --> 00:03:09,580
All I've done is to change the name because now it is not called by the loop.

35
00:03:09,860 --> 00:03:15,520
As you can see, this is what it used to be like in version three, the loop would call this function

36
00:03:15,520 --> 00:03:20,770
and then the various functions inside the security function would be triggered.

37
00:03:21,130 --> 00:03:29,110
But now, of course, in our because this function is being called by the scheduler.

38
00:03:30,420 --> 00:03:36,360
Let's go back up the top in line eight on creating a task, and this is its name, which is another

39
00:03:36,360 --> 00:03:44,040
reason why I added Sibi in the name of report so that the original function name is now used as a task

40
00:03:44,040 --> 00:03:45,660
name and every one second.

41
00:03:45,690 --> 00:03:51,960
This task will be called by the scheduler and it's going to trigger the reports.

42
00:03:51,960 --> 00:03:53,910
So the humidity callback function.

43
00:03:54,810 --> 00:04:03,120
Then I create a runner in line number nine in this row now, especially what keeps track of what to

44
00:04:03,120 --> 00:04:03,510
do.

45
00:04:03,510 --> 00:04:11,910
And when I jump down to this set up function, so in the search function in line 66, we initialize

46
00:04:12,150 --> 00:04:14,900
the runner and then we add a task to it.

47
00:04:14,900 --> 00:04:17,120
So we add the task of the report.

48
00:04:17,130 --> 00:04:22,110
So your humidity, which contains a callback that we want to trigger every one second, and then we'll

49
00:04:22,110 --> 00:04:27,360
enable this task so that it's especially the clock starts ticking.

50
00:04:30,040 --> 00:04:35,530
No changes here and then insert we call the execute function off the runner every time we go through

51
00:04:35,530 --> 00:04:43,460
the loop so that it can update its internal clock to know when to trigger the callback function.

52
00:04:44,290 --> 00:04:45,200
And that's about it.

53
00:04:45,310 --> 00:04:50,890
Every one second the callback function is called and the code inside it is executed.

54
00:04:53,320 --> 00:05:02,860
So I'm going to now upload this sketch to my especially two and make sure that our functionality remains

55
00:05:02,860 --> 00:05:04,660
just more efficient this time.

56
00:05:06,950 --> 00:05:09,790
OK, I'm going to turn on the power supply.

57
00:05:11,230 --> 00:05:17,660
But to make sure that everything is still working and here's the dashboard, the right.

58
00:05:18,290 --> 00:05:20,270
So let's let's see.

59
00:05:20,270 --> 00:05:23,090
What we have is a threshold is five hundred and twenty.

60
00:05:23,090 --> 00:05:26,150
And the soil humidity rule is now four full.

61
00:05:26,810 --> 00:05:28,000
So let's move that up a bit.

62
00:05:30,730 --> 00:05:32,020
And that works.

63
00:05:34,230 --> 00:05:34,620
Right.

64
00:05:36,240 --> 00:05:39,850
So as far as functionality is concerned, nothing has changed.

65
00:05:39,870 --> 00:05:45,000
Everything still works as it was with version three of the editorships sketches.

66
00:05:45,000 --> 00:05:50,140
Just now we're using the scheduler and things are running a lot better, a lot more efficient.

67
00:05:51,030 --> 00:05:58,470
So let's continue with our changes now, taking advantage of the scheduler in the next lecture.

68
00:05:58,480 --> 00:06:00,330
I'm going to do a bit of refactoring.

69
00:06:00,330 --> 00:06:06,680
For example, you can see here that I'm calling the report that year as part of the report Community

70
00:06:06,690 --> 00:06:07,260
Call Back.

71
00:06:07,290 --> 00:06:14,520
But what I want to do is to separate the voltage reporting into its own task that can run independently

72
00:06:14,520 --> 00:06:16,410
of the soil humidity task.

73
00:06:17,130 --> 00:06:25,140
And also, what I want to do is to include a safety timer for the motor so that it automatically cuts

74
00:06:25,140 --> 00:06:31,980
off five seconds after it begins to prevent flooding the terrorism, which I have done.

75
00:06:32,310 --> 00:06:39,480
And that's why I decided to use the cutoff time to prevent my terrorism from running again first thing

76
00:06:39,510 --> 00:06:42,620
in the next election to implement those changes.
