WEBVTT

00:00.420 --> 00:05.700
Let's now see how to combine together the two sides of cellular communication.

00:06.330 --> 00:11.370
And we're going to start from the previous program where we send something from the Raspberry Pi to

00:11.370 --> 00:12.000
the Arduino.

00:12.270 --> 00:16.640
What we are going to do is we're going to send back the message to the Raspberry Pi.

00:16.770 --> 00:18.750
We have something that we are the kit.

00:18.780 --> 00:21.330
OK, so this program is already working.

00:21.510 --> 00:24.330
If you don't have this, please go back to the previous view.

00:24.630 --> 00:28.920
So what I'm going to do is I'm going to add something to the message here.

00:29.310 --> 00:36.480
For example, a counter that we're going to increase every time so we can see a progression on the message.

00:37.350 --> 00:44.490
So I'm going to create here and global viral and counter is equal to zero.

00:44.500 --> 00:46.050
Let's initialize it to zero.

00:46.830 --> 00:56.250
And so once we receive the message, what we are going to do is to do this, each is equal to so message.

00:56.970 --> 00:59.340
Plus, let's add a space.

01:00.150 --> 01:06.330
Plus, let's add to counter the counter is an integer, so we're going to need to convert it to a string.

01:06.330 --> 01:09.270
So we use string we've come to.

01:10.720 --> 01:18.100
So if we receive hello from Raspberry Bay, we're going to know transform it to hello from Raspberry

01:18.100 --> 01:21.160
Pi Zero and then one two three four two.

01:21.640 --> 01:28.210
So of course, if we want to increase the content we encounter plus plus after we have used it and then,

01:28.510 --> 01:31.210
well, here we receive some data.

01:31.810 --> 01:37.490
We transform the data and we can do cellular print elements, do and print.

01:37.540 --> 01:40.600
Then another time we've missed each.

01:41.380 --> 01:41.750
All right.

01:41.770 --> 01:44.460
And let's run that on the audio.

01:44.510 --> 01:45.550
It's this.

01:48.140 --> 01:53.690
Don't applauding and actually before we write anything on the Raspberry Pi side, we can already debug

01:53.690 --> 01:59.060
this program because, yeah, we would be able to see the message we've printed and which means that

01:59.270 --> 02:01.850
we can do with the say and monitor.

02:02.030 --> 02:02.270
OK.

02:02.570 --> 02:07.820
So I opened a site in moneyto and I'm going to send the stream, let's say ABC.

02:08.930 --> 02:12.710
And you can see I have ABC zero eight.

02:12.920 --> 02:15.290
I sent another stream, a random stream.

02:16.370 --> 02:18.320
I have one a hello.

02:18.770 --> 02:20.570
Hello to hello.

02:20.900 --> 02:21.260
Three.

02:22.040 --> 02:24.870
So we know that the original programs correct.

02:24.870 --> 02:25.520
Keep walking.

02:26.090 --> 02:27.590
So we send this train.

02:27.860 --> 02:28.670
We also have.

02:28.760 --> 02:29.560
So that's very important.

02:29.570 --> 02:31.970
We have new lines with New Line.

02:32.570 --> 02:34.880
Was going to add a backslash thing at the end.

02:35.060 --> 02:36.230
OK, and new line character.

02:36.650 --> 02:40.310
If you want to add nothing, you go with no line ending, but I'm going to keep new name.

02:40.850 --> 02:46.250
So you send a stream and you received a stream space and we will counter it increases every time.

02:46.850 --> 02:47.240
All right.

02:47.600 --> 02:50.240
So no, that we know it's working on the other side.

02:50.270 --> 02:52.100
Let's go to the Raspberry Pi sign side.

02:52.490 --> 02:53.180
And here what?

02:53.180 --> 02:55.070
We're going to send a message to the area.

02:55.700 --> 02:57.680
So let's keep yellow from Raspberry Pi.

02:57.950 --> 02:58.370
Great.

02:58.910 --> 03:01.670
And then we're going to receive this message.

03:02.390 --> 03:08.090
So as you can see here, we directly read the string we modified and we send it back.

03:08.090 --> 03:10.010
So it should be almost immediate.

03:10.130 --> 03:10.430
OK.

03:10.820 --> 03:14.840
So I'm going to stay just off to the right and then read the string.

03:15.260 --> 03:20.930
But before that, as let's see a way to be sure, we have received the data I'm going to do.

03:22.010 --> 03:33.290
While Sara notes in waiting is a lower or equal than zero, which means that here we check if we have

03:33.290 --> 03:36.350
received some byte if this is equal to zero.

03:36.890 --> 03:38.610
Well, I'm going to do time.

03:38.630 --> 03:39.920
Don't sleep.

03:41.270 --> 03:44.030
0.01 OK, so we're going to wait.

03:44.360 --> 03:52.070
Zero point zero one Second in an infinite loop as long as we haven't received any data once we have

03:52.070 --> 03:53.540
received data.

03:53.960 --> 03:56.720
What I'm going to do is I'm going to do Sara.

03:56.780 --> 04:00.830
So basically, the way loop is going to exit, I'm going to do set a red line.

04:03.290 --> 04:08.840
Don't decode we've UTF eight.

04:10.430 --> 04:21.950
But a trick, and I'm going to put that inside a viable named, let's say a response is equal to that

04:21.980 --> 04:25.910
and then let's sprint response.

04:26.990 --> 04:32.960
OK, so every one second we send a message to the other know we wait until we receive something.

04:33.680 --> 04:35.960
We read that thing we've printed.

04:36.470 --> 04:37.970
We go back to the beginning.

04:38.660 --> 04:43.760
What you can see on the rise of the right and I'm coming to that know is we also have a timeout is equal

04:43.760 --> 04:47.060
to one here when we open the cell communication.

04:47.630 --> 04:53.030
So basically, we set a one second timeout, the same that we have under Arduino.

04:53.030 --> 04:57.140
But on the, you know, we don't need to write it to have one second, if you don't.

04:57.140 --> 05:00.980
But this it means you have infinite timeout.

05:01.280 --> 05:04.400
And the timeout is actually not the timeout for everything.

05:04.550 --> 05:07.640
It's a timeout for when you read, we said.

05:07.970 --> 05:13.310
So when you use this red line, basically it's going to do the same thing as here.

05:13.610 --> 05:18.790
He's going to read the next line, OK, until basically this backslash and character.

05:19.490 --> 05:25.730
So if you receive something that ends with a backslash and character, it's going to return immediately.

05:26.210 --> 05:30.110
If not, it's going to wait at least one second.

05:30.410 --> 05:36.830
So normally, if you correctly put backslash in with print L.A., you should not have any timeout problem.

05:37.010 --> 05:40.400
But I have still included it here just in case.

05:40.400 --> 05:46.070
So we don't have an infinite timeout that's going to completely block our code if we have one error

05:46.220 --> 05:47.450
coming from the Arduino.

05:48.110 --> 05:48.380
OK.

05:48.500 --> 05:51.860
The Arduino is correctly running the codes.

05:52.070 --> 05:54.170
Let's bring the cool in the Raspberry Pi.

05:56.960 --> 05:58.570
Say, OK, send a message.

05:58.850 --> 05:59.300
You can see.

05:59.330 --> 06:02.880
And hello from Raspberry Pi one two three four.

06:02.900 --> 06:03.860
Etc., etc..

06:04.160 --> 06:04.700
Voice control.

06:04.720 --> 06:05.090
See?

06:08.020 --> 06:14.560
And you can see it is currently working, so now you have a bi directional communication, so great.

06:14.800 --> 06:21.400
Now you can communicate from Raspberry Pi to Arduino and from other the Raspberry Pi in the same program.

06:21.580 --> 06:28.960
And so to conclude on that, the examples we have seen here are actually super super simple, OK, but

06:28.960 --> 06:34.960
they are good to make you familiar with cellular in the following in the course, you will practice

06:34.960 --> 06:41.920
more real applications so that you can better understand how to use cellular in a more complex situation.

06:42.460 --> 06:48.820
There are so many possibilities, and so instead of listing them all here, which is going to be quite

06:48.820 --> 06:55.660
boring, well, you will simply discover them while going through the course and through the activities.
