Has anyone had any success with 433 communication using Radiohead headers? I had some success transmitting integers but after a minute or two it would eventually print garbage to my lcd display, which leads me to think there is a memory addressing problem. All the examples I've seen use strings... usually "hello world". When I try to copy one of these very simple examples, they simply don't work.
I think this code was copied from the Radiohead Examples web page, as the receive code shows an an attempt to declare "int i;" which raises an error in Arduino IDE.
Thanks. This video proves that the software works, when implemented properly. I copied it exactly and finally got it to work. There is one difference, however. When I receive "Welcome to the Workshop!" there is an extra character at the end of the string. I prepared the buffer for 24 characters as in the video, but I get 25 when I check the length of the received string. Any ideas why this happens to me and not in the video?
The transmit code does not send the terminating zero of the C-string:
driver.send((uint8_t *)msg, strlen(msg));
The receive code assumes that the terminating zero is there, so you can expect random failures, depending on whatever is in memory following the receive buffer.
if (driver.recv(buf, &buflen)) // Non-blocking
{
//int i;
// Message with a good checksum received, dump it.
Serial.print("Message: ");
Serial.println((char*)buf);
To fix that, either send the terminating zero, or add one upon receive.
By "terminating 0" you mean a NULL character, right? Or I could add an extra character space to the buffer to accommodate an extra character? I'm thinking that this extra character is being written out of bounds and causing havoc in memory. Adding extra space in buffer should fix it, right?
That's exactly what I just tried to do and it worked! Oddly, on the receive side, for a transmission of "Welcome to the Workshop!", if I set the buffer size to 24, I get a string length of 25. But if I set the buffer size to 25, I get a string length of 24. I'll leave it at 25.
Yes, of course. There is also the possibility of using the max buffer length option (I don't remember the name) if you don't mind wasting a bit of memory, or your not sure of the length.
Actually, no I don't. I know I added +1 to allow for NULL. That would make 25. I may receive 25 characters, however, when I check for string length, the NULL should not be counted, and I should see 24.
But I think if I set the buffer to 24 and I get 25 characters, the 25th character (NULL) infringes on an area outside of it's bounds. If checking the length it will still see the NULL character marking the end of the string, but I don't know why it would count 25 characters.
Exactly. An out of bounds write to memory has unpredictable consequences, including loss of data and program crashes, on any computer. Pay close attention to array sizes, allowed read/write buffer lengths, etc.