Now that we are done with the first part of our code, let's move on and create a method so that we
can connect to Wi-Fi networks easily listening and void who set up wi fi.
Now,
inside this method to add a delay of twenty milliseconds and serial, the prompt new line.
Let's bring something to tell you, though, that we are connecting to Wi-Fi from the remnants of.
OK, now.
That's right.
The name of the wi fi.
Right is a side after that wi fi dot begin to start connecting to this wi fi, is this I.D. and password.
So it will take the Wi-Fi as ID and password and will try to connect.
Now, we can't otherwise statement if Wi-Fi
the status.
It's not connected
then we need it to delay and try again.
And while it's trying to connect, we need to bring Dot K now.
After this, after the wall, that wall keeps trying, we'll keep trying.
Connecting to the Wi-Fi network we need to add.
Once it's connected, it will keep rolling this until it's connected.
Now, once it's connected, we need to write a serial footprint.
New line now Wi-Fi
is connected.
And we can even print the IP address.
And to print it, we need to call a function called wi fi
dot, local IP.
And this will tell the IP address to which our ISP 32 boards connected and will print it out on the
serial monitor.
Now let's verify the code to make sure that everything is working just fine.
OK.
That's it.
Now, this is the first function.
Now the second function is to reconnect now by void, reconnect.
Now we will loop until we are reconnected.
So we will add our oil statement.
And this is basically a function to make sure that we are connected to the uncute server.
So one
player that connected
is not true.
We need to try.
To reconnect.
So let's try to Brent.
Attempting to reconnect and you take an extra.
OK, now the next line will be on.
The publish
inside, it will write out topic
about how to were.
Now, let's create a random client I.D., strong client I.D..
Let's call it E.S.P 30 to climb, and you can add anything
after that.
We cannot add client already.
Plus, equal strength.
And so the strength we can add around function.
and for us now, we can make sure that Hicks has the time and this will make sure that each side will
have a new client ID, that is unique because we are getting the value.
And we are adding it to that previous value so we can move this number and each time it will be granted,
it will be this.
Plus, the strength that comes out from this line now.
Let's attempt to connect, right if statement then else.
Let's start with that statement now, inside that statement, we need to ask if a client that cannot
function, which usually takes their client idea to this one, does.
Now we're going to use a function called C String, which basically converts the contents of a string
as a CEO, which is the one that we need for this F statement.
And to use it, we just need to write C, underscore ETR, then we can add INF treaty, use that which
is basically the user name for the server and NQ G.T. password.
OK, last word now, as you can see, uh, it takes the connect function, takes three things the client
ID, the user and the password after that.
If that statement is true, we can can print
the word connected and Barceloneta.
So print newline.
OK, now, once connected, we can publish an announcement by writing client, not publish
inside it, we can write.
I see.
Rhizomes.
And E.S.P, first to.
Now, the announcement will be hello worth.
Now, otherwise, if this condition didn't hit, we need to go to the EL statement and inside it we
need to Roitfeld.
And we can also add another line that says our see equal and leave us space and we will print out the
client state.
So serial, the trend
client, not state.
Now.
Let's make sure that we have everything correct, that client.
The state function.
OK, now try again, five seconds.
And we can add a delay of five or six seconds
to give it time to try again.
OK.
That's it, this is the reconnect function for Van Kutty server.
Now we can have this call at the end, but for now, this is everything that we need.
First, we need to make sure that the client is not connected.
If it's not connected, we need to write that you are attempting to connect and we need to set a client
I.D..
Now, if we have sent the client already and cutesie user name and password, it will connect if there
is any problem.
There is no Internet connection or any other problem.
It will print failed and it will print the state of this client and will print that.
You should try again in a few seconds and will add a delay to ensure that you are sound after a good
amount of time.
Now, if we didn't verify our code, we would get an OK and all that land, it is not defined because
we have very small.
So let's make it a capital.
OK, Duncan, darling, everything is correct, and the next lesson, we are going to start the set
up and look function coding, but that's it for now.
If you have any questions, please ask in the Q&A about this is Ashar from educational engineering team.