1
00:00:00,660 --> 00:00:04,230
Now, let's let's go to the setup function.

2
00:00:05,340 --> 00:00:13,980
The first thing that we need to do is initial overseer of communication, a specific Mod. A simple crate

3
00:00:13,980 --> 00:00:15,180
and I'll do an import.

4
00:00:16,860 --> 00:00:20,340
Then we need to set the timeout for the serial communication.

5
00:00:24,370 --> 00:00:27,790
It will be five hundred milliseconds, so half a second is enough.

6
00:00:28,570 --> 00:00:36,190
Then let's call the setup verify function, just make sure that we have the right name.

7
00:00:37,840 --> 00:00:38,700
This is it up.

8
00:00:38,710 --> 00:00:39,370
Why file?

9
00:00:42,490 --> 00:00:54,940
After that, we need to call the client to server to pass the server parameters and will take an Kutty

10
00:00:56,620 --> 00:01:04,000
server link and NQT port as input.

11
00:01:05,470 --> 00:01:10,960
Then we must call the function reconnect.

12
00:01:13,900 --> 00:01:15,910
Now let's look a file called.

13
00:01:19,600 --> 00:01:25,210
Great, we don't have any issues now we need to define a new function between the setup and lube.

14
00:01:25,840 --> 00:01:28,750
Let's call it populist, so avoid publish.

15
00:01:31,860 --> 00:01:35,160
Syrian data.

16
00:01:39,540 --> 00:01:41,400
Now, this functional take.

17
00:01:44,600 --> 00:01:46,970
Syrian data as input.

18
00:01:51,000 --> 00:01:54,720
And after taking serial death out, import it will.

19
00:01:57,190 --> 00:02:03,340
Make sure that then Kitty said if I was connected using an if statement.

20
00:02:07,330 --> 00:02:11,740
Now inside, they've said statement will, right, if client that connected.

21
00:02:19,240 --> 00:02:21,640
Now, it's not connected.

22
00:02:21,970 --> 00:02:27,100
Call that a connect function to connect it.

23
00:02:27,610 --> 00:02:30,250
Now, once it's connected.

24
00:02:31,240 --> 00:02:36,250
What we should do is publish the data, so publish

25
00:02:39,160 --> 00:02:48,250
the publish will take the MQ 30 Serial Publish channel.

26
00:02:49,570 --> 00:03:00,190
As input will also take the serial data from here, and this is already defined here.

27
00:03:03,300 --> 00:03:04,460
See our published channel.

28
00:03:06,170 --> 00:03:10,070
And you can't change it to your own population.

29
00:03:10,610 --> 00:03:12,410
But for now, let's go back.

30
00:03:13,780 --> 00:03:19,810
OK, now plan to publish the client will publish this.

31
00:03:21,260 --> 00:03:28,190
Syrian death to this channel after making sure that the NQT server is connected.

32
00:03:29,820 --> 00:03:34,680
No, this is the wrong goal from dysfunction inside the void, look, we are going to call this function

33
00:03:35,640 --> 00:03:36,870
so inside the void law?

34
00:03:37,080 --> 00:03:37,950
We will ask.

35
00:03:39,800 --> 00:03:44,570
First, let's call a client that loop function.

36
00:03:47,450 --> 00:03:48,650
Now we will ask if.

37
00:03:51,700 --> 00:04:03,070
That cereal that available is more than zero or above zero means that we have incoming cereal data.

38
00:04:03,730 --> 00:04:09,810
And in that case, if we have incoming cereal, that's what we need to do is take the cereal that aren't

39
00:04:09,820 --> 00:04:14,980
stored in a variable, so will define a character that's called puffer.

40
00:04:17,520 --> 00:04:18,020
Better.

41
00:04:20,150 --> 00:04:21,920
And you can't make it.

42
00:04:25,000 --> 00:04:30,350
This will be an array of characters, and its size will be five hundred ten.

43
00:04:30,400 --> 00:04:34,390
You can turn the site whatever fits your needs.

44
00:04:35,530 --> 00:04:36,610
After doing this?

45
00:04:38,640 --> 00:04:48,180
We are going to use function as our function called Mimi set the level function void limited.

46
00:04:48,180 --> 00:04:55,180
Kobe's the character to the first and characters of the string pointed by the arrow.

47
00:04:55,510 --> 00:04:58,900
Now I will write it down, then I will explain to you.

48
00:04:58,920 --> 00:05:08,630
And while you are using it here, the first thing that you need right here is me sits inside it.

49
00:05:08,940 --> 00:05:13,080
It will take the buffer as input.

50
00:05:14,460 --> 00:05:23,960
And zero then the buffer that of the size, which is 510 now.

51
00:05:24,240 --> 00:05:29,760
What this functional do is the following the first thing that buffer data.

52
00:05:30,300 --> 00:05:33,060
This is the point after the block of memory to fail.

53
00:05:33,270 --> 00:05:36,390
So we need to fill this block of memory with data.

54
00:05:37,080 --> 00:05:40,270
Now the second parameter, which is this number, is zero.

55
00:05:40,830 --> 00:05:42,750
This is the value to be set.

56
00:05:43,170 --> 00:05:49,710
The value is passed as integer, but the function fills the block of memory using the unsigned Charcol

57
00:05:49,710 --> 00:05:50,760
version of the value.

58
00:05:52,230 --> 00:05:57,540
Now we come to the last variable or the last in what which is five hundred and ten.

59
00:05:58,020 --> 00:06:02,370
This is the number of buys to be set to the value, which is basically the size of the array.

60
00:06:04,890 --> 00:06:11,910
This function will return a pointer to the area where buffered data is stored.

61
00:06:13,530 --> 00:06:20,220
Now we need to read that until we see a new line, which is basically what we did not do an accord.

62
00:06:20,580 --> 00:06:21,210
We sing it.

63
00:06:21,220 --> 00:06:22,530
We have send data.

64
00:06:22,710 --> 00:06:25,680
And at the end of each block of death, I think annual line.

65
00:06:26,250 --> 00:06:34,740
So write serial dot read bytes until.

66
00:06:37,740 --> 00:06:40,470
And here are going to other conditions.

67
00:06:41,480 --> 00:06:49,830
First thing is Iran, which is a new line and the data that we read will be stored here in the bazaar

68
00:06:49,830 --> 00:06:54,040
data and the data size.

69
00:06:54,060 --> 00:06:55,440
Let's make it 500.

70
00:06:55,620 --> 00:07:00,540
We already have an array with a size over 500 510.

71
00:07:00,960 --> 00:07:04,500
So five hundred is the same value to be inserted here.

72
00:07:04,890 --> 00:07:13,590
Usually, you have to set a value that's below battery size after this and you need to publish this

73
00:07:13,590 --> 00:07:17,700
data, so publish serial data.

74
00:07:19,410 --> 00:07:21,630
This is the function that we defined here.

75
00:07:25,100 --> 00:07:33,710
And take that that we did receive as input, which is the buffer data, so this function will read the

76
00:07:33,710 --> 00:07:42,710
incoming serial data and sort it here until a new line is sent from the entire ISP.

77
00:07:43,250 --> 00:07:50,870
Then it will send the data to the published serial data function, which takes the data's input.

78
00:07:51,470 --> 00:07:55,160
And this function will make sure that then Kutty server is connected.

79
00:07:55,820 --> 00:08:02,330
After making sure that it's connected, it will publish the data to the NQT serial channel.

80
00:08:03,020 --> 00:08:10,580
And as you can see it, this is a serial that which is the main function of our coding practice here.

81
00:08:10,790 --> 00:08:13,970
Now again, what we have done here.

82
00:08:14,150 --> 00:08:15,170
Let me zoom out.

83
00:08:18,250 --> 00:08:26,440
We have created defined some variables, and we have used the computer to library the wildfire library,

84
00:08:27,220 --> 00:08:33,010
set up wildfire to make sure that we are connecting or we are connected to our Wi-Fi network and we

85
00:08:33,010 --> 00:08:33,730
are online.

86
00:08:34,300 --> 00:08:41,980
That connect function is to make sure that we are connected to the NQT server and we have a set function

87
00:08:42,610 --> 00:08:48,340
where we have connect to Wi-Fi and to that community server.

88
00:08:49,360 --> 00:08:54,370
Then we have the loop, which will make sure that we are all.

89
00:08:54,370 --> 00:08:55,960
We have incoming serial data.

90
00:08:57,790 --> 00:09:04,150
And it will store the incoming serial data inside this variable before death, which is basically an

91
00:09:04,150 --> 00:09:11,140
idea of character and will send it to the public serial data function, which is this one first.

92
00:09:11,530 --> 00:09:14,830
We will make sure that we are connected to the security server.

93
00:09:15,340 --> 00:09:20,440
Then we will publish the data to this channel that we are defined here.

94
00:09:21,700 --> 00:09:26,810
So this is our main coding practice for DSP 32.

95
00:09:27,600 --> 00:09:32,860
The next lesson we are going to sort this out and make sure that it's working just fine.

96
00:09:33,550 --> 00:09:39,160
If you have any question regarding any of these lines, please ask and get you on their board now just

97
00:09:39,160 --> 00:09:40,790
to make sure that you don't have any errors.

98
00:09:40,810 --> 00:09:44,140
Let's verify our code one more time.

99
00:09:45,390 --> 00:09:51,870
OK, now we have a new, as you can see, Cyril, that was not declared, it's here.

100
00:09:52,260 --> 00:09:57,030
So we have a spelling error, but if I gain.

101
00:09:59,950 --> 00:10:02,050
Dan, combining without any errors.

102
00:10:02,380 --> 00:10:02,980
That's it.

103
00:10:03,280 --> 00:10:11,030
Now we might have to change the values for our Wi-Fi network name and password and for that and use

104
00:10:11,050 --> 00:10:18,100
the username and password and the channel all of the server links, depending on all needs.

105
00:10:18,130 --> 00:10:26,890
Now, if you are using your own API, you can simply send the serial data to your own API using JSON

106
00:10:26,890 --> 00:10:33,040
coding or any other method that fits your new, you know, your needs.

107
00:10:33,070 --> 00:10:35,650
But for now, I'm using them here to teach server.

108
00:10:35,650 --> 00:10:38,590
So this is the coding practice for this server.

109
00:10:39,070 --> 00:10:41,620
It's a very well-known and widely used one.

110
00:10:42,130 --> 00:10:50,050
So I will change that Wi-Fi network values and their username and password values with mine.

111
00:10:50,380 --> 00:10:52,810
Then we will test this called out.

112
00:10:53,200 --> 00:10:54,400
Thanks for watching this lesson.

113
00:10:54,550 --> 00:10:57,400
This is Ashraf from educational engineering team.
