char msgrx[10];
uint8_t buf[VW_MAX_MESSAGE_LEN]; // define the buffer
uint8_t buflen = VW_MAX_MESSAGE_LEN; // buffer length
if (vw_get_message(buf, &buflen)) // Non-blocking
{
int i;
Serial.print("Got: ");
for (i = 0; i < buflen; i++)
{
msgrx[i]=buf[i];
}
}
Well at the end inside my variable msgrx I will have "hello" + 5 + '\0' .
Then when I have my message into the variable i did all my check for example:
if (strcmp(msgrx, "hello") == 0)
{
Serial.println("Work are equal..."
}
Is this the correct use for the library ?
Could I improve in something ?
VirtualWire is the only library that can be used for send data via ASK Amplitude Shift Keying or could be used something else ?
It does not convert the byte array to a char array. It uses a different kind of pointer (char) to point to the data in the byte_array. Whatever is using array treads the data in byte_array as though it is char data. This works when byte_array only contains data that can be interpreted as char data.
A byte and a char are the same size (8 bits), but the byte is unsigned and the char is signed, so the two do not have the same range of values. As long as the data is in the overlapping range (0 to 127), the byte data is interpreted the same when interpreting as a char.
So then with virtual wire is only possible send out number from 0 to 127 correct in only one byte ...
is possible pass directly the value without pass from the past char variable since the moment that want a uint8_t ? in this way i think could be more linear ...
So then with virtual wire is only possible send out number from 0 to 127 correct in only one byte ...
No, you can send any value from 0 to 255. However, if the byte contains a value like 240, interpreting that as a character will not give the desired results.
If you ARE sending bytes, why are you casting to char?
Hi Paul,
so I would like send-out a byte ... kindly could you give me an example-code for send-out for example the number "240" like a byte ? and receive it like a byte ?
I ask to this because with the code i think will be more clear and maybe i can provide to you more information