Radiohead checking simple received radio data problem 433mhz

I’m trying to set up a basic 1 way link between two Uno’s.

The transmitting Uno sends a simple word or character which should be recognised on the receiving Uno in order to perform some command. Using “Hello World” gave an odd extra character. Smaller / 1 character long messages don’t have an extra strange character.

The idea is that a relay will either turn on or off by command.

I’m sure that I’m going wrong somewhere - the message is never confirmed on the receiving Uno.

Transmitter Uno Code: (DHT22 part isn’t doing anything much at the moment.)

#include <RH_ASK.h>
#include <SPI.h> // Not actually used but needed to compile
#include "DHT.h"

#define DHTPIN 2     // what pin we're connected to
#define DHTTYPE DHT22   // DHT 22  (AM2302)

RH_ASK driver;

int maxHum = 60;
int maxTemp = 40;

DHT dht(DHTPIN, DHTTYPE);

void setup()
{
    Serial.begin(9600);    // Debugging only
    if (!driver.init())
         Serial.println("init failed");
           dht.begin();
}

void loop()
{
    const char *msg = "A";
    driver.send((uint8_t *)msg, strlen(msg));
    driver.waitPacketSent();
    delay(2000);

// Reading temperature or humidity takes about 250 milliseconds!
  // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
  float h = dht.readHumidity();
  // Read temperature as Celsius
  float t = dht.readTemperature();
  
  // Check if any reads failed and exit early (to try again).
  if (isnan(h) || isnan(t)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }
  
    Serial.print("Humidity: "); 
  Serial.print(h);
  Serial.print(" %\t");
  Serial.print("Temperature: "); 
  Serial.print(t);
  Serial.println(" *C ");
  
}

Receiving Uno Code:

#include <RH_ASK.h>
#include <SPI.h> // Not actualy used but needed to compile

RH_ASK driver;

void setup()
{
    Serial.begin(9600);  // Debugging only
    if (!driver.init())
         Serial.println("init failed");
}

void loop()
{

  
    uint8_t buf[12];
    uint8_t buflen = sizeof(buf);
    if (driver.recv(buf, &buflen)) // Non-blocking
    {
      int i;
      // Message with a good checksum received, dump it.
      Serial.println((char*)buf);         
    }
    if (((char*)buf) == "A") {
    Serial.println("Message is confirmed as A");
    }    else {
    Serial.println("Something is wrong - confirmation did not work...");
    }
}

Thanks for reading :slight_smile:

    if (((char*)buf) == "A") {

First, buf is NOT a NULL terminated array of chars. Second, this is NOT how to compare strings.

You MUST NULL terminate buff and you MUST use strcmp() to compare strings.

Try something like this (untested):

if (driver.recv(buf, &buflen)) // Non-blocking
    {
      buf[buflen]=0;
      // Message with a good checksum received, dump it.
      Serial.println((char*)buf);         
      if (buf[0] == 'A') 
         {
         Serial.println("Message is confirmed as A");
          }    
         else  
         {
         Serial.println("Something is wrong - confirmation did not work...");
          }
    }

Try something like this (untested):

Which won't solve OP's problem which involves strings longer than 1 character.