Need explanation for some lines of code

I tried building a simple wireless communication on arduino unos using 315mhz transmitter/ receiver modules with Radiohead library which I found online.
here is a code for transmitter

// Include RadioHead Amplitude Shift Keying Library
#include <RH_ASK.h>
// Include dependant SPI Library 
#include <SPI.h> 
 
// Create Amplitude Shift Keying Object
RH_ASK rf_driver;
 
void setup()
{   Serial.begin(9600);
    // Initialize ASK Object
    rf_driver.init();
}
 
void loop()
{
    const char *msg = "welcome";
    rf_driver.send((uint8_t *)msg, strlen(msg));
    rf_driver.waitPacketSent();
    delay(10);
    Serial.println(strlen(msg));
}

In the code for transmitter I dont understand what exactly this line does.

 rf_driver.send((uint8_t *)msg, strlen(msg));

And here’s code for receiver

#include <RH_ASK.h>
// Include dependant SPI Library 
#include <SPI.h> 
 
// Create Amplitude Shift Keying Object
RH_ASK rf_driver;
 
void setup()
{
   
     
    // Initialize ASK Object
    rf_driver.init();
    // Setup Serial Monitor
    Serial.begin(9600);
}
 
void loop()
{
    // Set buffer to size of expected message
    uint8_t buf[7];
    uint8_t buflen = sizeof(buf);
    // Check if received packet is correct size
    if (rf_driver.recv(buf, &buflen))
    {
      
      // Message received with valid checksum
      Serial.print("Message Received: ");
      Serial.println((char*)buf);      
      delay(1000);
      }
}

What function does the following line serve in this code especially : ((char*) buff ) what is it doing ??

 Serial.println((char*)buf);

Can someone please explain this in detail.

rf_driver.send((uint8_t *)msg, strlen(msg));

Treat the 'char *' named 'msg' as a 'byte *' and send the number of bytes in the string it points to.

Serial.println((char*)buf);

Treat the address of the byte array as a character pointer and print the characters it contains, up until a null character is reached. WARNING: You are not sending a null character so you are not receiving a null character so the buffer is not properly terminated. Even if you WERE sending a null character, the buffer is not large enough to receive it.

I appreciate your response . How would it be possible to store the incoming string instead of printing it to serial monitor?

Rishi_kesh:
I appreciate your response . How would it be possible to store the incoming string instead of printing it to serial monitor?

The bytes you received stored are in 'buf'. The variable 'buflen' should contain the number of bytes you received. You can move those bytes to another variable or use them directly from 'buf'.

You should NOT use 'buf' as a string since it has no terminator. The printing SHOULD have been written as:

      Serial.write(buf, buflen);  // Write the specified number of bytes
      Serial.write('\n');  // Since there is not .writeln() we have to write the Newline separately