1
00:00:00,570 --> 00:00:06,390
Now we need to declare an object of Observer Library so we can access its functions.

2
00:00:07,020 --> 00:00:14,820
The constructor of the object to export were the server will be listening to as a parameter since 80

3
00:00:15,210 --> 00:00:17,850
is the default port for HDTV requests.

4
00:00:18,330 --> 00:00:24,870
We will use this value and you can easily do that by writing this very simple line.

5
00:00:27,790 --> 00:00:30,370
Before the setup method, what to observer

6
00:00:33,460 --> 00:00:46,450
and it should be called webserver server, and at 80, yeah, so we have declared an object from the

7
00:00:46,450 --> 00:00:49,970
observer with this part.

8
00:00:50,170 --> 00:00:52,420
Eighty four request.

9
00:00:53,620 --> 00:01:00,670
Next, we declare that yes, we have 32 general purpose input output pins to which lids are connected

10
00:01:01,210 --> 00:01:03,730
and we are going to set that initial state.

11
00:01:06,220 --> 00:01:12,810
Now, do that sort of the setup method define an integer?

12
00:01:17,480 --> 00:01:18,590
And call it led.

13
00:01:19,670 --> 00:01:29,510
And one and we already know that we have connected the to pin number two and five.

14
00:01:31,300 --> 00:01:39,430
So we would like to hear the same line will be retained for bill number five.

15
00:01:43,460 --> 00:01:44,390
For the second.

16
00:01:45,380 --> 00:01:45,800
Let.

17
00:01:47,610 --> 00:01:54,600
Now, let's give them initial value led one status.

18
00:01:56,930 --> 00:02:02,120
Turn it off low and same thing for little.

19
00:02:04,670 --> 00:02:05,450
Make it law.

20
00:02:06,470 --> 00:02:13,760
OK, now that we have furnished everything before the setup method, we will go back to our wireless

21
00:02:13,760 --> 00:02:15,470
network name and password.

22
00:02:16,700 --> 00:02:19,190
Let's move on to the setup function.

23
00:02:20,390 --> 00:02:25,760
Well, going to configure our H2B request or server before actually running it.

24
00:02:26,150 --> 00:02:33,220
First of all, we open a serial connection for debugging purposes and we are going to set general purpose

25
00:02:33,230 --> 00:02:41,390
input output ports to output because they are basically LEDs and we are going to control them as outputs.

26
00:02:42,260 --> 00:02:49,490
So inside the setup by Serial to begin and use and moderate.

27
00:02:53,290 --> 00:03:03,160
Next, Penaud, just lighting an Arduino, and we are going to either take the print name lid pin one

28
00:03:04,630 --> 00:03:06,280
and make it output.

29
00:03:07,990 --> 00:03:15,460
Same thing for the second pen and two, it will be treated as outputs.

30
00:03:16,240 --> 00:03:23,930
Then we are going to set up a soft access point to establish our Wi-Fi network by providing that I.D.

31
00:03:24,190 --> 00:03:31,720
password, IP address, IP subnet mask and IP Gateway, which are basically this information that we

32
00:03:31,720 --> 00:03:33,430
provided or we added here.

33
00:03:34,780 --> 00:03:40,840
To do that, what you need to do inside the setup method is like Wi-Fi.

34
00:03:44,330 --> 00:03:45,830
Not soft.

35
00:03:47,710 --> 00:03:48,290
AP.

36
00:03:49,660 --> 00:03:51,960
And this will take two parameters.

37
00:03:52,420 --> 00:04:06,100
This aside, the passport, then try to qualify the soft AP config, and it will take three parameters

38
00:04:07,000 --> 00:04:14,860
the local IP gateway, the subnet.

39
00:04:17,870 --> 00:04:23,960
After that, you can't add a delay to make sure that everything is stable.

40
00:04:26,350 --> 00:04:27,940
Now that's it.

41
00:04:28,420 --> 00:04:31,090
Let's verify to make sure that we don't have rules.

42
00:04:33,370 --> 00:04:40,480
I'd like to find a villain then to make sure that if there is an error, I can fix it when it happened.

43
00:04:42,400 --> 00:04:44,530
OK, Duncan Bilang, we don't have any rules.

44
00:04:46,270 --> 00:04:53,410
Now we come to the most important part of this code in order to handle incoming entry requests.

45
00:04:53,440 --> 00:04:59,470
We need to specify which code to execute went up articulate well on his hit.

46
00:05:00,370 --> 00:05:02,890
To do so, we use on method.

47
00:05:03,730 --> 00:05:05,530
This method takes two parameters.

48
00:05:05,770 --> 00:05:14,440
First, one is a real path and second one is dynamic of function, which we want to execute when that

49
00:05:14,440 --> 00:05:15,520
you are always hit.

50
00:05:16,540 --> 00:05:17,350
For example.

51
00:05:18,570 --> 00:05:23,310
Let's try to write one line on that, explain it as we write it.

52
00:05:23,790 --> 00:05:24,600
Let's hear what.

53
00:05:26,370 --> 00:05:27,960
Not on.

54
00:05:29,990 --> 00:05:36,770
Now open to parentheses, the first part of that will take.

55
00:05:38,450 --> 00:05:43,410
Is this large and you need to write Comma?

56
00:05:44,000 --> 00:05:50,870
Then why the method name that will take control when something's happened?

57
00:05:53,880 --> 00:05:56,640
OK, now this line.

58
00:05:58,550 --> 00:06:05,780
When a server receives an entity built on the path, it will trigger the handle connect.

59
00:06:07,530 --> 00:06:12,360
Function, not that they are specified is our relative path.

60
00:06:13,710 --> 00:06:16,750
Likewise, we can do the same for other URLs.

61
00:06:19,200 --> 00:06:28,920
We call it here led one on and we can name the function led one on.

62
00:06:30,840 --> 00:06:34,880
Same for other lives server on.

63
00:06:37,110 --> 00:06:39,570
And we are going to try different values here.

64
00:06:40,110 --> 00:06:48,720
Slash led one off and handle led one off.

65
00:06:50,100 --> 00:06:54,900
Same for led to a lot of going to change.

66
00:06:54,900 --> 00:06:56,920
This led to little.

67
00:06:57,870 --> 00:07:05,300
And same for here led to led to just to save time and to make sure that we don't care about lighting

68
00:07:05,310 --> 00:07:05,640
now.

69
00:07:06,210 --> 00:07:07,380
What will happen here?

70
00:07:07,770 --> 00:07:11,640
Whenever you light the IP, address this one.

71
00:07:12,210 --> 00:07:18,840
Let's say that you and your browser, I will give you an example 180 to 168 one 0.10.

72
00:07:19,320 --> 00:07:21,330
And you write this slash.

73
00:07:21,840 --> 00:07:26,490
When they ask people to receive this request, it will run this method.

74
00:07:27,360 --> 00:07:34,290
Now, if you write one on it will execute this method and you are going to like this method.

75
00:07:34,710 --> 00:07:37,590
Methods in the loop section.

76
00:07:38,750 --> 00:07:41,360
But for now, this is what I need you to understand.

77
00:07:42,170 --> 00:07:48,920
Now we haven't specified what the server should do if the client requests and you are other than the

78
00:07:48,920 --> 00:07:58,720
specified with server on either of these, it should respond with an issue with status 404 error, which

79
00:07:58,730 --> 00:08:03,320
is basically not found page and a message for the user.

80
00:08:03,920 --> 00:08:17,060
We put this in a function as well, and we can easily do that by writing Server Dot on not found, which

81
00:08:17,060 --> 00:08:20,510
is one of the functions that we can easily use.

82
00:08:21,080 --> 00:08:22,880
Here you need to write the name of the function.

83
00:08:23,120 --> 00:08:23,780
Don't take.

84
00:08:24,050 --> 00:08:25,430
It will take only one parameter.

85
00:08:26,570 --> 00:08:29,690
So not found.

86
00:08:30,830 --> 00:08:31,190
OK.

87
00:08:33,140 --> 00:08:33,620
Now.

88
00:08:35,260 --> 00:08:39,580
To start ourselves what we need to write server to begin.

89
00:08:42,280 --> 00:08:51,100
And on tech and parameters, and we can fight a line and the CO2 monitor to make sure that it will show

90
00:08:51,100 --> 00:08:54,450
us Sarah has started OK.

91
00:08:55,360 --> 00:08:59,710
A.B. Silva has started.

92
00:09:02,660 --> 00:09:05,610
This is how to start your server once you finish the configuration.

93
00:09:05,630 --> 00:09:08,630
Now let's make a quick review of what we have done here.

94
00:09:10,790 --> 00:09:18,500
We initialized the soft access point mode and gave it to parameters, the Wi-Fi network name and the

95
00:09:18,500 --> 00:09:24,140
password, and we gave it the local IP getaway on subnet mask.

96
00:09:24,830 --> 00:09:27,890
Then we had a delay to make sure that everything is stable.

97
00:09:28,490 --> 00:09:30,560
After that, we wrote these lines.

98
00:09:32,800 --> 00:09:39,250
The surfer looked on will take two parameters first parameter is they are all on the second parameter

99
00:09:39,250 --> 00:09:39,970
is the method.

100
00:09:40,420 --> 00:09:44,020
So when someone requests the manual, this one.

101
00:09:45,390 --> 00:09:51,660
It will call the handle on connect method, and when someone lights lit one, when someone calls this

102
00:09:51,660 --> 00:09:57,570
real, it will call this method and we are going to create these methods in the loop section.

103
00:09:59,350 --> 00:10:05,260
But what you need to know now is that you can add more your allies and more requests.

104
00:10:05,620 --> 00:10:12,790
And if someone until you are all that you haven't set here, you can direct him to handle not found

105
00:10:13,750 --> 00:10:16,000
methods on not found.

106
00:10:17,000 --> 00:10:25,430
Now, to solve the server like terror begin, then serial dot print line and apply this line and the

107
00:10:25,430 --> 00:10:28,340
settlement or indicating that the server has started.

108
00:10:29,030 --> 00:10:29,960
Let's verify.

109
00:10:36,370 --> 00:10:43,360
OK, now we have problem, which is hand-held internet was not declared, which means that this method

110
00:10:43,870 --> 00:10:47,560
was not yet declared and we haven't yet declared anything in the loop section.

111
00:10:47,560 --> 00:10:50,350
So this is an area that we can't ignore.

112
00:10:50,860 --> 00:10:55,600
And in the next lesson, we are going to start writing the code inside a loop section.

113
00:10:56,290 --> 00:10:57,100
That's it for now.

114
00:10:57,130 --> 00:10:57,940
Thanks for watching.

115
00:10:57,970 --> 00:11:01,300
This is Ashraf from educational engineering team.
