Let's now see how to combine together the two sides of cellular communication.
And we're going to start from the previous program where we send something from the Raspberry Pi to
the Arduino.
What we are going to do is we're going to send back the message to the Raspberry Pi.
We have something that we are the kit.
OK, so this program is already working.
If you don't have this, please go back to the previous view.
So what I'm going to do is I'm going to add something to the message here.
For example, a counter that we're going to increase every time so we can see a progression on the message.
So I'm going to create here and global viral and counter is equal to zero.
Let's initialize it to zero.
And so once we receive the message, what we are going to do is to do this, each is equal to so message.
Plus, let's add a space.
Plus, let's add to counter the counter is an integer, so we're going to need to convert it to a string.
So we use string we've come to.
So if we receive hello from Raspberry Bay, we're going to know transform it to hello from Raspberry
Pi Zero and then one two three four two.
So of course, if we want to increase the content we encounter plus plus after we have used it and then,
well, here we receive some data.
We transform the data and we can do cellular print elements, do and print.
Then another time we've missed each.
All right.
And let's run that on the audio.
It's this.
Don't applauding and actually before we write anything on the Raspberry Pi side, we can already debug
this program because, yeah, we would be able to see the message we've printed and which means that
we can do with the say and monitor.
OK.
So I opened a site in moneyto and I'm going to send the stream, let's say ABC.
And you can see I have ABC zero eight.
I sent another stream, a random stream.
I have one a hello.
Hello to hello.
Three.
So we know that the original programs correct.
Keep walking.
So we send this train.
We also have.
So that's very important.
We have new lines with New Line.
Was going to add a backslash thing at the end.
OK, and new line character.
If you want to add nothing, you go with no line ending, but I'm going to keep new name.
So you send a stream and you received a stream space and we will counter it increases every time.
All right.
So no, that we know it's working on the other side.
Let's go to the Raspberry Pi sign side.
And here what?
We're going to send a message to the area.
So let's keep yellow from Raspberry Pi.
Great.
And then we're going to receive this message.
So as you can see here, we directly read the string we modified and we send it back.
So it should be almost immediate.
OK.
So I'm going to stay just off to the right and then read the string.
But before that, as let's see a way to be sure, we have received the data I'm going to do.
While Sara notes in waiting is a lower or equal than zero, which means that here we check if we have
received some byte if this is equal to zero.
Well, I'm going to do time.
Don't sleep.
0.01 OK, so we're going to wait.
Zero point zero one Second in an infinite loop as long as we haven't received any data once we have
received data.
What I'm going to do is I'm going to do Sara.
So basically, the way loop is going to exit, I'm going to do set a red line.
Don't decode we've UTF eight.
But a trick, and I'm going to put that inside a viable named, let's say a response is equal to that
and then let's sprint response.
OK, so every one second we send a message to the other know we wait until we receive something.
We read that thing we've printed.
We go back to the beginning.
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
to one here when we open the cell communication.
So basically, we set a one second timeout, the same that we have under Arduino.
But on the, you know, we don't need to write it to have one second, if you don't.
But this it means you have infinite timeout.
And the timeout is actually not the timeout for everything.
It's a timeout for when you read, we said.
So when you use this red line, basically it's going to do the same thing as here.
He's going to read the next line, OK, until basically this backslash and character.
So if you receive something that ends with a backslash and character, it's going to return immediately.
If not, it's going to wait at least one second.
So normally, if you correctly put backslash in with print L.A., you should not have any timeout problem.
But I have still included it here just in case.
So we don't have an infinite timeout that's going to completely block our code if we have one error
coming from the Arduino.
OK.
The Arduino is correctly running the codes.
Let's bring the cool in the Raspberry Pi.
Say, OK, send a message.
You can see.
And hello from Raspberry Pi one two three four.
Etc., etc..
Voice control.
See?
And you can see it is currently working, so now you have a bi directional communication, so great.
Now you can communicate from Raspberry Pi to Arduino and from other the Raspberry Pi in the same program.
And so to conclude on that, the examples we have seen here are actually super super simple, OK, but
they are good to make you familiar with cellular in the following in the course, you will practice
more real applications so that you can better understand how to use cellular in a more complex situation.
There are so many possibilities, and so instead of listing them all here, which is going to be quite
boring, well, you will simply discover them while going through the course and through the activities.