About the payload

Hi,
The below sketch modified the payload code doesn't work, why?

that was: char msg[23] = "744c7b04-a65f-11ea-bb37-0242ac130002";
works well.
changed as: char msg[15] = "StationAcmdA001"; no work.

Thanks for help.
Adam

#include <RH_ASK.h> // Radiohead Library
#include <SPI.h> // Dependency for Radiohead library

/*
   Trigger for Activation command
   A1 = Device A, LED ON
   A2 = Device A, LED OFF
   A3 = Device A, LED Blinking
*/

String state;
String cmd1 = "A1";
String cmd2 = "B3";
RH_ASK driver;
int delayTime = 1000;

void setup()
{
  Serial.begin(9600);
  Serial.println("xxx_setup!");
  Serial.print("File   : "), Serial.println(__FILE__);
  Serial.print("Date   : "), Serial.println(__DATE__);
  Serial.println("<Arduino is ready>");

  Serial.setTimeout(10);

  if (!driver.init())
    Serial.println("init failed");
  state = cmd1;
}

void loop()
{
  // Manage which payload to be transmitted

  if (Serial.available() > 0)
  {
    String cmdRead = Serial.readString();
    Serial.print("cmdRead = ");
    Serial.println(cmdRead);
  }

  if (state == cmd1 && cmd2 != "") {
    state = cmd2;
  } else {
    if (state == cmd2 && cmd1 != "") {
      state = cmd1;
    }
  }


  /* Device A */
  if (state == "A1") { //ON
    //  char msg[23] = "a74f689c-a66c-11ea-bb37-0242ac130002";

    char msg[15] = "StationAcmdA001";
    driver.send((uint8_t *)msg, strlen(msg));
    driver.waitPacketSent();
    delay(delayTime);
  } else {
    if (state == "A2") { //OFF
      // char msg[23] = "744c7b04-a65f-11ea-bb37-0242ac130002";

      char msg[15] = "StationAcmdA002";
      driver.send((uint8_t *)msg, strlen(msg));
      driver.waitPacketSent();
      delay(delayTime);
    } else {
      if (state == "A3") { //Blinking
        //  char msg[23] = "08d9d004-a675-11ea-bb37-0242ac130002";

        char msg[15] = "StationAcmdA003";
        driver.send((uint8_t *)msg, strlen(msg));
        driver.waitPacketSent();
        delay(delayTime);
      } else {

        /* Device B */
        if (state == "B1") { // ON
          //  char msg[23] = "b65e5b9c-a728-11ea-bb37-0242ac130002";

          char msg[15] = "StationBcmdB001";
          driver.send((uint8_t *)msg, strlen(msg));
          driver.waitPacketSent();
          delay(delayTime);
        } else {
          if (state == "B2") { // OFF
            // char msg[23] = "b65e5f0c-a728-11ea-bb37-0242ac130002";

            char msg[15] = "StationBcmdB002";
            driver.send((uint8_t *)msg, strlen(msg));
            driver.waitPacketSent();
            delay(delayTime);
          } else {
            if (state == "B3") { // OFF
              //  char msg[23] = "27daa3e4-a72d-11ea-bb37-0242ac130002";

              char msg[15] = "StationBcmdB003";
              driver.send((uint8_t *)msg, strlen(msg));
              driver.waitPacketSent();
              delay(delayTime);
            }
          }
        }
      }
    }
  }
}

No null terminator.

1 Like

This "string" needs to be 16 characters long. The final character needs to contain 0x00 to terminate the string.

1 Like

you don't need to specify a size nor a null terminator which is added by the compiler

simply define it as

char msg [] = "StationAcmdA001";
1 Like

And if you ever switch back, you can't fit 37 characters in a 23-character array. Change it to:
char msg[] = "744c7b04-a65f-11ea-bb37-0242ac130002";

1 Like

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