BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

This is my code can anyone check for any major flaws Please

#include <SPI.h>
#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>

#define BLYNK_PRINT Serial
#define RELAY_PIN_1      12   //D6
#define RELAY_PIN_2      16   //D0

#define VPIN_BUTTON_1    V12
#define VPIN_BUTTON_2    V13

BlynkTimer timer;

int relay1State = LOW;
int relay2State = LOW;

char auth[] = "YourAuthToken";

char ssid[] = "YourNetworkName";
char pass[] = "YourPassword";

#include <SoftwareSerial.h>
SoftwareSerial EspSerial(2, 3);

#define ESP8266_BAUD 9600

ESP8266 wifi(&EspSerial);

RH_ASK rftrans;

BLYNK_CONNECTED()
{
  Blynk.syncVirtual(VPIN_BUTTON_1);
  Blynk.syncVirtual(VPIN_BUTTON_2);
}

BLYNK_WRITE(VPIN_BUTTON_1)
{
  relay1State = param.asInt();
  digitalWrite(RELAY_PIN_1, relay1State);
}

BLYNK_WRITE(VPIN_BUTTON_2)
{
  relay2State = param.asInt();
  digitalWrite(RELAY_PIN_2, relay2State);
}

void checkPhysicalButton()
{
  uint8_t buf[2];
  uint8_t buflen = sizeof(buf);
  if (rftrans.recv(buf, &buflen))
  {
    if ((char*)buf == "ze")
    {

    }
    else if ((char*)buf == "on")
    {
      relay1State = !relay1State;
      digitalWrite(RELAY_PIN_1, relay1State);
      Blynk.virtualWrite(VPIN_BUTTON_1, relay1State);
    }
    else if ((char*)buf == "tw")
    {
      relay2State = !relay2State;
      digitalWrite(RELAY_PIN_2, relay2State);
      Blynk.virtualWrite(VPIN_BUTTON_2, relay2State);
    }
    else if ((char*)buf == "th")
    {

    }
    else if ((char*)buf == "fo")
    {

    }
    else if ((char*)buf == "fi")
    {

    }
    else if ((char*)buf == "si")
    {

    }
    else if ((char*)buf == "se")
    {

    }
    else if ((char*)buf == "ei")
    {

    }
    else if ((char*)buf == "ni")
    {

    }
    else if ((char*)buf == "aa")
    {

    }
    else if ((char*)buf == "bb")
    {

    }
    else if ((char*)buf == "cc")
    {

    }
    else if ((char*)buf == "dd")
    {

    }
    else if ((char*)buf == "st")
    {

    }
    else if ((char*)buf == "ha")
    {

    }
  }
}

void setup()
{
  rftrans.init();
  Serial.begin(9600);
  EspSerial.begin(ESP8266_BAUD);
  delay(10);
  Blynk.begin(auth, wifi, ssid, pass);
  pinMode(RELAY_PIN_1, OUTPUT);
  digitalWrite(RELAY_PIN_1, relay1State);
  pinMode(RELAY_PIN_2, OUTPUT);
  digitalWrite(RELAY_PIN_2, relay2State);
  timer.setInterval(500L, checkPhysicalButton);
}

void loop()
{
  Blynk.run();
  timer.run();
}

This is a code for integrating RF remote with blynk can anyone check if this code has any major flaws. This project is about controlling relays with BLYNK and RF remote so whenever i change the relay state with the RF remote it should automatically update the state in the app.
I’m a beginner so can anyone help.
the rf codes like “ze”, “on” are the ones i used for my own RF remote using a transmitter so that one you can ignore.

The transmitter code if that’s somehow necessary.

#include <RH_ASK.h>
#include <SPI.h>

const byte ROWS = 4;
const byte COLS = 4;

RH_ASK rftrans;
const char *data;

char hexaKeys[ROWS][COLS] = {
  {'1', '2', '3', 'A'},
  {'4', '5', '6', 'B'},
  {'7', '8', '9', 'C'},
  {'*', '0', '#', 'D'}
};

byte rowPins[ROWS] = {2, 3, 4, 5}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {6, 7, 8, 9}; //connect to the column pinouts of the keypad

Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);

void setup()
{
  rftrans.init();
  Serial.begin(9600);
}

void loop()
{
  char customKey = customKeypad.getKey();

  if (customKey == '0')
  {
    data = "ze";
    rftrans.send((uint8_t *)data , strlen(data));
    rftrans.waitPacketSent();
    delay(500);
  }
  else if (customKey == '1')
  {
    data = "on";
    rftrans.send((uint8_t *)data , strlen(data));
    rftrans.waitPacketSent();
    delay(500);
  }
  else if (customKey == '2')
  {
    data = "tw";
    rftrans.send((uint8_t *)data , strlen(data));
    rftrans.waitPacketSent();
    delay(500);
  }
  else if (customKey == '3')
  {
    data = "th";
    rftrans.send((uint8_t *)data , strlen(data));
    rftrans.waitPacketSent();
    delay(500);
  }
  else if (customKey == '4')
  {
    data = "fo";
    rftrans.send((uint8_t *)data , strlen(data));
    rftrans.waitPacketSent();
    delay(500);
  }
  else if (customKey == '5')
  {
    data = "fi";
    rftrans.send((uint8_t *)data , strlen(data));
    rftrans.waitPacketSent();
    delay(500);
  }
  else if (customKey == '6')
  {
    data = "si";
    rftrans.send((uint8_t *)data , strlen(data));
    rftrans.waitPacketSent();
    delay(500);
  }
  else if (customKey == '7')
  {
    data = "se";
    rftrans.send((uint8_t *)data , strlen(data));
    rftrans.waitPacketSent();
    delay(500);
  }
  else if (customKey == '8')
  {
    data = "ei";
    rftrans.send((uint8_t *)data , strlen(data));
    rftrans.waitPacketSent();
    delay(500);
  }
  else if (customKey == '9')
  {
    data = "ni";
    rftrans.send((uint8_t *)data , strlen(data));
    rftrans.waitPacketSent();
    delay(500);
  }
  else if (customKey == 'A')
  {
    data = "aa";
    rftrans.send((uint8_t *)data , strlen(data));
    rftrans.waitPacketSent();
    delay(500);
  }
  else if (customKey == 'B')
  {
    data = "bb";
    rftrans.send((uint8_t *)data , strlen(data));
    rftrans.waitPacketSent();
    delay(500);
  }
  else if (customKey == 'C')
  {
    data = "cc";
    rftrans.send((uint8_t *)data , strlen(data));
    rftrans.waitPacketSent();
    delay(500);
  }
  else if (customKey == 'D')
  {
    data = "dd";
    rftrans.send((uint8_t *)data , strlen(data));
    rftrans.waitPacketSent();
    delay(500);
  }
  else if (customKey == '*')
  {
    data = "st";
    rftrans.send((uint8_t *)data , strlen(data));
    rftrans.waitPacketSent();
    delay(500);
  }
  else if (customKey == '#')
  {
    data = "ha";
    rftrans.send((uint8_t *)data , strlen(data));
    rftrans.waitPacketSent();
    delay(500);
  }
}