Now we need to declare an object of Observer Library so we can access its functions.
The constructor of the object to export were the server will be listening to as a parameter since 80
is the default port for HDTV requests.
We will use this value and you can easily do that by writing this very simple line.
Before the setup method, what to observer
and it should be called webserver server, and at 80, yeah, so we have declared an object from the
observer with this part.
Eighty four request.
Next, we declare that yes, we have 32 general purpose input output pins to which lids are connected
and we are going to set that initial state.
Now, do that sort of the setup method define an integer?
And call it led.
And one and we already know that we have connected the to pin number two and five.
So we would like to hear the same line will be retained for bill number five.
For the second.
Let.
Now, let's give them initial value led one status.
Turn it off low and same thing for little.
Make it law.
OK, now that we have furnished everything before the setup method, we will go back to our wireless
network name and password.
Let's move on to the setup function.
Well, going to configure our H2B request or server before actually running it.
First of all, we open a serial connection for debugging purposes and we are going to set general purpose
input output ports to output because they are basically LEDs and we are going to control them as outputs.
So inside the setup by Serial to begin and use and moderate.
Next, Penaud, just lighting an Arduino, and we are going to either take the print name lid pin one
and make it output.
Same thing for the second pen and two, it will be treated as outputs.
Then we are going to set up a soft access point to establish our Wi-Fi network by providing that I.D.
password, IP address, IP subnet mask and IP Gateway, which are basically this information that we
provided or we added here.
To do that, what you need to do inside the setup method is like Wi-Fi.
Not soft.
AP.
And this will take two parameters.
This aside, the passport, then try to qualify the soft AP config, and it will take three parameters
the local IP gateway, the subnet.
After that, you can't add a delay to make sure that everything is stable.
Now that's it.
Let's verify to make sure that we don't have rules.
I'd like to find a villain then to make sure that if there is an error, I can fix it when it happened.
OK, Duncan Bilang, we don't have any rules.
Now we come to the most important part of this code in order to handle incoming entry requests.
We need to specify which code to execute went up articulate well on his hit.
To do so, we use on method.
This method takes two parameters.
First, one is a real path and second one is dynamic of function, which we want to execute when that
you are always hit.
For example.
Let's try to write one line on that, explain it as we write it.
Let's hear what.
Not on.
Now open to parentheses, the first part of that will take.
Is this large and you need to write Comma?
Then why the method name that will take control when something's happened?
OK, now this line.
When a server receives an entity built on the path, it will trigger the handle connect.
Function, not that they are specified is our relative path.
Likewise, we can do the same for other URLs.
We call it here led one on and we can name the function led one on.
Same for other lives server on.
And we are going to try different values here.
Slash led one off and handle led one off.
Same for led to a lot of going to change.
This led to little.
And same for here led to led to just to save time and to make sure that we don't care about lighting
now.
What will happen here?
Whenever you light the IP, address this one.
Let's say that you and your browser, I will give you an example 180 to 168 one 0.10.
And you write this slash.
When they ask people to receive this request, it will run this method.
Now, if you write one on it will execute this method and you are going to like this method.
Methods in the loop section.
But for now, this is what I need you to understand.
Now we haven't specified what the server should do if the client requests and you are other than the
specified with server on either of these, it should respond with an issue with status 404 error, which
is basically not found page and a message for the user.
We put this in a function as well, and we can easily do that by writing Server Dot on not found, which
is one of the functions that we can easily use.
Here you need to write the name of the function.
Don't take.
It will take only one parameter.
So not found.
OK.
Now.
To start ourselves what we need to write server to begin.
And on tech and parameters, and we can fight a line and the CO2 monitor to make sure that it will show
us Sarah has started OK.
A.B. Silva has started.
This is how to start your server once you finish the configuration.
Now let's make a quick review of what we have done here.
We initialized the soft access point mode and gave it to parameters, the Wi-Fi network name and the
password, and we gave it the local IP getaway on subnet mask.
Then we had a delay to make sure that everything is stable.
After that, we wrote these lines.
The surfer looked on will take two parameters first parameter is they are all on the second parameter
is the method.
So when someone requests the manual, this one.
It will call the handle on connect method, and when someone lights lit one, when someone calls this
real, it will call this method and we are going to create these methods in the loop section.
But what you need to know now is that you can add more your allies and more requests.
And if someone until you are all that you haven't set here, you can direct him to handle not found
methods on not found.
Now, to solve the server like terror begin, then serial dot print line and apply this line and the
settlement or indicating that the server has started.
Let's verify.
OK, now we have problem, which is hand-held internet was not declared, which means that this method
was not yet declared and we haven't yet declared anything in the loop section.
So this is an area that we can't ignore.
And in the next lesson, we are going to start writing the code inside a loop section.
That's it for now.
Thanks for watching.
This is Ashraf from educational engineering team.