Total noob has a question.

I have a project I am working on use 433MHz radios and I am not getting an expected result.

Here is the transmitter code:

#include <RH_ASK.h>
#include <SPI.h>
RH_ASK rf_driver(2000, 11, 11, 0); // (speed, Tx pin, Rx pin, PTT enable)
   
void setup() {
  Serial.begin(115200);  //setting baud rate
  pinMode(11, OUTPUT);
   rf_driver.init();
}

void loop() {
     const char *msg = "013:0";
     rf_driver.send((uint8_t *)msg, 5);
     rf_driver.waitPacketSent();
}

And here is my receiver code:

#include <RH_ASK.h>
#include <SPI.h>
RH_ASK rf_driver(2000, 11, 11, 0); // (speed, Tx pin, Rx pin, PTT enable)
   
void setup() {
  Serial.begin(115200);  //setting baud rate
  pinMode(11, INPUT);
   rf_driver.init();
}

void loop() {
    uint8_t buf[5];
    uint8_t buflen =  sizeof(buf);
     if (rf_driver.recv(buf, &buflen)) {
        Serial.print("Message received: ");
        Serial.println((char*)buf);  
      }
}

It works but the message that prints on the screen is

https://ibb.co/Gt03T1F

I am posting an image because it contains an invalid character that I cannot copy and paste here.

Obviously I just want the 013:0.

I feel like I am messing up data types or something but I such a noob with this stuff so be gentle with me....lol

I can't see the message that it puts on screen - did you omit it?

Have you remembered that C strings are NULL terminated? This means the buffer to receive the data has to be 6 chars long and you will probably have to NULL terminate before you do anything, such as print it.

Have a read of this article: How to get the best out of this forum - Programming Questions - Arduino Forum
It makes it much easier for everyone if you put your code in code blocks, and also if you post all your code as most problems stem from assuming there is an error in the snippet of code posted when it usually is not that simple.

I updated the original post.

Try this in your receiver:

void loop() {
    uint8_t buf[6];
    uint8_t buflen =  sizeof(buf) - 1;
     if (rf_driver.recv(buf, &buflen)) {  
        buf[5] = 0;
        Serial.print("Message received: ");
        Serial.println((char*)buf);  
      }
}

Those invalid characters that are appearing after the data you want is a classic sign of an unterminated string - try the code ToddL1962 has put up.

Thanks. That was it. I appreciate the help.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.