Converting bytes to char when receiving from 433mhz

I am trying to combine the buf[] received into a char (strRec).
The Serial.print((char)buf[i]); prints the correct information received.

This is not a project so any assistance would be appreciated.

#include <VirtualWire.h>

/*
   sent example =  A001*, A002* etc
*/

void setup()
{
  Serial.begin(115200); // Debugging only
  Serial.println("Receiver setup");

  // Initialise the IO and ISR
  //  vw_set_ptt_inverted(true); // Required for DR3100
  vw_set_rx_pin(11);           // Arduino pin (default 11)
  vw_setup(2000);             // Bits per sec
  vw_rx_start();              // Start the receiver PLL running
}


void loop() {
  char strRec;
  uint8_t buf[VW_MAX_MESSAGE_LEN];
  uint8_t buflen = VW_MAX_MESSAGE_LEN;
  if (vw_get_message(buf, &buflen)) // Non-blocking
  {

    digitalWrite(13, true); // Flash a light to show received good message
    // Message with a good checksum received, dump it

    for ( int i = 0; i < buflen; i++)
    {
      **strRec += ((char)buf[i]);**
      Serial.print((char)buf[i]);
    }
    Serial.print(" received: "); Serial.print(strRec);
    Serial.println();
    digitalWrite(13, false);
    delay(200);
  }
}

strRec is a single character - it isn't going to hold a very large sum.
What do you want here?

I want to add the character's received into one string.

If your received message is buflen chars, just copy them over

if (vw_get_message(buf, &buflen)) // Non-blocking
  {
    char newBuffer[VW_MAX_MESSAGE_LEN];
    memcpy(newBuffer, buf, buflen);  // copy the contents
    newBuffer[buflen] = '\0';  make sure string is nul terminated
    Serial.print(newBuffer);
  }

vw_get_message() stays right there until the ENTIRE MESSAGE is received.
That function Blocks! The code that uses the data expects it all, there's no exit or re-entry, execution stays Locked on vw_get_message that receives chars over time.

Beyond that.... '\0' is ASCII 48, text zero. The NUL is ASCII 0.

Perfect thank you.

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