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.
Let's limit the was set up by five.
Now
inside this method, just a delay of 20 milliseconds and serial the brand new line,
let's bring something to tell you, though, that we are connecting to I from the that motor.
OK, now.
It's quite dynamic with the I fight.
All right, it's a I thought that why I don't begin to start connecting to this, why is this I.D. and
passport so it would take to qualify this ID and password?
I will try to connect now, which are the line statement, if qualify
the status.
Is not connected,
then we need to delay and try again.
And while it's trying to connect, we need to train.
OK, now.
After this, after the wall, that wall keeps trying, we'll keep trying, connecting to the wife Typekit
work, 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 Syria to the brand
new line.
No Wi-Fi
is connected.
And we can't even print the IP address.
And to print it, we need to call a function called verify
the local IP.
This world will terror the IP address to our ISP, 32 bodies connected and will print it out on the
sea that I'm on it.
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 void to connect.
Now we will know until we are reconnected.
So we'll add a wild statement.
This is basically a function to make sure that we are connected to the NQT server.
So while it's clear that connected
is not true, we need to try.
To reconnect.
So let's try to the different.
A typical thing to reconnect and your TV connection.
OK, now the next line will be pliant.
The publisher
inside it will write out topic.
That's right.
Hello, world.
Now, let's create a random client ID, string client I.D..
Let's call it, yes, be 32 clients, and you cannot do anything
after that, we kind of had client idea.
B+ equal strength.
And so this thing, we can add a random function.
0X
and for us now, we can make sure that takes over 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 remove this number and which Typekit will be,
the idea will be this.
Plus, the last thing that comes out from this line now.
Let's attempt to connect, but if statement, then else.
Let's start with that statement now inside that statement, we need to ask if a client that connects
function, which usually takes that client I.D. to this one does.
Now they're going to use a function called C String, which basically converts the contents of a string
as a C style, which is the one that we need for this if statement and to use it, we just need to write
c underscore STR.
Then we can add MQ 3T user, which is basically the user name for the server in Q T password.
OK, last
now, as you can see, it takes the Kinect function, takes three things the client I.D., the user
and the password after that, if that statement is true, we can can print
the word connected and Barcelona later.
So brand new line.
OK, now, once connected, we can publish an announcement by writing Client not publish
inside that we can write.
I see.
Results.
And yes, we first saw.
Now that announcement will be.
Hello, world.
Now, otherwise, if this condition didn't hit, we need to go to the health department and inside it.
We need to right field.
And we can also add another line that says are equal and leave us space.
We will print out the Lion State, so serial the trend line the state.
Now.
Let's make sure that we have everything correct.
Battleground.
The state function, OK, now, try again in 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 the NQT server.
Now we can't 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 know that we are attempting to connect and we need to set a Client ID.
Now, if we have seen that Client I.D. MQ, the 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 to print the state of this client and to print that you should try again in a few
seconds and will add a delay to make sure that you are signed after a good amount of time.
Now we did verify our code.
We only get OK, an error that plant idea is not defined because we have c small.
So let's make it the capital.
OK.
Then compiling everything is correct.
And the next lesson, we are going to start the setup up and loop function coding, but that's it for
now.
If you have any question, please ask in the Q&A about this is Usha from educational engineering team.