Now, let's let's go to the setup function.
The first thing that we need to do is initial overseer of communication, a specific Mod. A simple crate
and I'll do an import.
Then we need to set the timeout for the serial communication.
It will be five hundred milliseconds, so half a second is enough.
Then let's call the setup verify function, just make sure that we have the right name.
This is it up.
Why file?
After that, we need to call the client to server to pass the server parameters and will take an Kutty
server link and NQT port as input.
Then we must call the function reconnect.
Now let's look a file called.
Great, we don't have any issues now we need to define a new function between the setup and lube.
Let's call it populist, so avoid publish.
Syrian data.
Now, this functional take.
Syrian data as input.
And after taking serial death out, import it will.
Make sure that then Kitty said if I was connected using an if statement.
Now inside, they've said statement will, right, if client that connected.
Now, it's not connected.
Call that a connect function to connect it.
Now, once it's connected.
What we should do is publish the data, so publish
the publish will take the MQ 30 Serial Publish channel.
As input will also take the serial data from here, and this is already defined here.
See our published channel.
And you can't change it to your own population.
But for now, let's go back.
OK, now plan to publish the client will publish this.
Syrian death to this channel after making sure that the NQT server is connected.
No, this is the wrong goal from dysfunction inside the void, look, we are going to call this function
so inside the void law?
We will ask.
First, let's call a client that loop function.
Now we will ask if.
That cereal that available is more than zero or above zero means that we have incoming cereal data.
And in that case, if we have incoming cereal, that's what we need to do is take the cereal that aren't
stored in a variable, so will define a character that's called puffer.
Better.
And you can't make it.
This will be an array of characters, and its size will be five hundred ten.
You can turn the site whatever fits your needs.
After doing this?
We are going to use function as our function called Mimi set the level function void limited.
Kobe's the character to the first and characters of the string pointed by the arrow.
Now I will write it down, then I will explain to you.
And while you are using it here, the first thing that you need right here is me sits inside it.
It will take the buffer as input.
And zero then the buffer that of the size, which is 510 now.
What this functional do is the following the first thing that buffer data.
This is the point after the block of memory to fail.
So we need to fill this block of memory with data.
Now the second parameter, which is this number, is zero.
This is the value to be set.
The value is passed as integer, but the function fills the block of memory using the unsigned Charcol
version of the value.
Now we come to the last variable or the last in what which is five hundred and ten.
This is the number of buys to be set to the value, which is basically the size of the array.
This function will return a pointer to the area where buffered data is stored.
Now we need to read that until we see a new line, which is basically what we did not do an accord.
We sing it.
We have send data.
And at the end of each block of death, I think annual line.
So write serial dot read bytes until.
And here are going to other conditions.
First thing is Iran, which is a new line and the data that we read will be stored here in the bazaar
data and the data size.
Let's make it 500.
We already have an array with a size over 500 510.
So five hundred is the same value to be inserted here.
Usually, you have to set a value that's below battery size after this and you need to publish this
data, so publish serial data.
This is the function that we defined here.
And take that that we did receive as input, which is the buffer data, so this function will read the
incoming serial data and sort it here until a new line is sent from the entire ISP.
Then it will send the data to the published serial data function, which takes the data's input.
And this function will make sure that then Kutty server is connected.
After making sure that it's connected, it will publish the data to the NQT serial channel.
And as you can see it, this is a serial that which is the main function of our coding practice here.
Now again, what we have done here.
Let me zoom out.
We have created defined some variables, and we have used the computer to library the wildfire library,
set up wildfire to make sure that we are connecting or we are connected to our Wi-Fi network and we
are online.
That connect function is to make sure that we are connected to the NQT server and we have a set function
where we have connect to Wi-Fi and to that community server.
Then we have the loop, which will make sure that we are all.
We have incoming serial data.
And it will store the incoming serial data inside this variable before death, which is basically an
idea of character and will send it to the public serial data function, which is this one first.
We will make sure that we are connected to the security server.
Then we will publish the data to this channel that we are defined here.
So this is our main coding practice for DSP 32.
The next lesson we are going to sort this out and make sure that it's working just fine.
If you have any question regarding any of these lines, please ask and get you on their board now just
to make sure that you don't have any errors.
Let's verify our code one more time.
OK, now we have a new, as you can see, Cyril, that was not declared, it's here.
So we have a spelling error, but if I gain.
Dan, combining without any errors.
That's it.
Now we might have to change the values for our Wi-Fi network name and password and for that and use
the username and password and the channel all of the server links, depending on all needs.
Now, if you are using your own API, you can simply send the serial data to your own API using JSON
coding or any other method that fits your new, you know, your needs.
But for now, I'm using them here to teach server.
So this is the coding practice for this server.
It's a very well-known and widely used one.
So I will change that Wi-Fi network values and their username and password values with mine.
Then we will test this called out.
Thanks for watching this lesson.
This is Ashraf from educational engineering team.