And now I'm just going to continue with you where we are off.
So we've talked about callbacks and now we know how important it is and.
Oh, Kutty.
Now we're going to ride the callback function itself ourselves, and we're going to start doing this
now, so we're going to create a function from void.
We're going to call it, of course, callback.
Now, what will we pass to this?
We're going to pass a topic.
And it's a pointer, we're going to pass the payload.
So this is a flight payload, it's also a pointer.
And finally, I need to pass the length of the payload.
So this will be unsigned integer.
Lent or Lent?
OK.
Now, you might ask, what the hell is this?
OK, so the topic is the topic we are subscribing to and remember, the topic is a string, right?
And when you have multiple characters, as I have mentioned to you before, when you have multiple characters
connected together as a string of characters, we refer to them by a pointer like this.
OK, so whenever you have a chain of something, it's very similar to an array, but the deeper meaning
of it is different.
But you can think about it as an array and every element is holding a character.
OK, so this is why we put this story right here next to the topic so that we know this is a string
of characters.
Next we have the bite, the payload.
Do you remember the payload?
If I go back here or not read, I am sending a message when I press on.
Right.
I mean, when I press on, I should be sending some content in the topic.
So it's like I'm sending a message that is called internal LSD and its content is to write.
So this is the payload.
This is a bite.
OK, so the payload here, it's going to be either number one or number two on and off.
Next, we have the length.
The length is a compulsory parameter that we need to pass in order to match this goal.
That I mean, this goal back here is expecting three parameters, topic payload.
And it's not like the callback is customary function.
No, this client is expecting a callback that has a certain form that looks exactly like this topic,
payload and length.
And the length is what is the length of payload?
How many payloads are we sending?
I could be sending multiple payloads at the same time.
I could be sending 10 bytes over there.
I am sending only one byte and it is the one or two in Madrid.
I could be sending a whole package that consists of 16 bytes or 24 bytes or whatever number I need.
So this length here is to specify what is the length of my message.
In my case, it's going to be always what in this case, because it's either on a separate packet of
separate packet.
As simple as that.
No.
How about.
We decode the message we receive, we are receiving, I'm going to decode it very simply, I'm going
to say if.
Payload zero.
Is equal to 49, and I'm going to tell you and I'm going to tell you why we are using 49 in a minute.
I'm going to digital.
Right.
LSD.
Built in regardless of the number on the board, hi.
I'm going to say, Elsbeth.
I'll get a copy this just pasted here and I'm going to put number 50 here.
And I'm going to copy this as well.
I'm going to paste it here.
And I'm going to convert this to low.
What does that mean?
Well, 49 is actually number one as a character, and 50 is actually number two as a character.
Now, you should be familiar with the ASCII code.
If not, I'm going to explain it a little bit.
No, I'm going to get here and I'm going to type ASCII code now.
I'm going to go to pictures and I'm going to go here and I'm going to open this to.
So what is this, the table now?
Every character let it be a capital B. All the way to Z, all the special characters, all the small
characters have a corresponding decimal number because let's say that you are sending a bite message,
all ones and zeros.
As we have learned in the virtual code, you are sending ones and zeros, but how are you going to decode
it to a character?
Write Every character has a decimal number.
So when I am sending you, let's say, of a serial ABC, what I'm doing, actually I'm sending 97,
98 and 99 and then I have a function that decodes these numbers and convert them according to the table.
OK, so this is the ASCII table.
This is what it does.
Now, you can see that there is no doubt as well these are not decimal numbers.
I am not talking about decimal numbers.
I am talking about if you define the character and you say this character is zero or one or two, it's
not actually decimal zero.
It is 48 and 49 and 50.
I remember in my payload I am using remember, if I go here in my payload, I am using number to fall
on and I am using number one for all.
However, this one here and this too here are not decimals.
I'm not sending decimals in the payload.
I am sending characters.
OK, I am sending a bite that has this content in it, which is a character ASCII content.
As you can see, it's a string.
I could be sending booleans, I could be sending a number.
But right now I am sending a string here.
And a string is whenever you say string, you need to go out and decoded in the ASCII table.
This is exactly what we are doing here.
If you go and check number one, it's 49.
If you go and check number two, it's actually 50.
So in my sketch, when I say if the bailout equals forty nine, I mean that this should be my signal.
And if I receive 50, this should be my low signal.
I believe we did them here of the opposite.
It should be the other way around.
So here it should be low because forty nine is for low and here it should be high.
Forty nine corresponds to one.
This is forty nine.
It corresponds to one and this is forty nine.
It's all so simple here for tonight's four of 50 is on, this is a great now we have the call back up
and ready.
There is one more thing I want to change here.
Is this digital right?
Well, not all the boards are going to take the internal LCD and turns it into an output.
So you need to do that.
Definitely.
So there is just one more thing here that I need to modify.
I'm going to delete this digital right right here.
It's not necessary.
I need to define exactly what led I'm going to be using right here.
So.
In my case, there is a built in led on 16 and on two, so I want to use the number two in order to
do that.
I'm going to do the following.
I need to say, Ben Moad.
Being number two output.
OK, this is the built in I lead now 16 is another Leidy's, but this is not the main building one.
The main one is being number two.
And if I don't specify it like this, well, the code might or might not work.
It depends on the internal configuration of your MCU.
So in order to avoid all of this probability, I'm just going to go and define it specifically that
I need this to be as an output.
OK, great.