Problem with BlynkEdgent.h File

I already include all the pins in Blynk.Edgent File

// Fill-in information from your Blynk Template here
#define BLYNK_TEMPLATE_ID           "TMPLxxxxxx"
#define BLYNK_DEVICE_NAME           "Device"

#define BLYNK_FIRMWARE_VERSION        "0.1.0"

#define BLYNK_PRINT Serial
//#define BLYNK_DEBUG

#define APP_DEBUG

// Uncomment your board, or configure a custom board in Settings.h
#define USE_WROVER_BOARD
//#define USE_TTGO_T7

#include "BlynkEdgent.h"
#include <IRremote.h>

#define IR_RECV_PIN 35 // D35 (IR receiver pin)

IRrecv irrecv(IR_RECV_PIN);
decode_results results;

#define RelayPin1 23  //D23
#define RelayPin2 22  //D22
#define RelayPin3 21  //D21
#define RelayPin4 19  //D19

#define SwitchPin1 13  //D13
#define SwitchPin2 12  //D12
#define SwitchPin3 14  //D14
#define SwitchPin4 27  //D27

#define wifiLed    2   //D2

#define VPIN_BUTTON_1    V1 
#define VPIN_BUTTON_2    V2
#define VPIN_BUTTON_3    V3 
#define VPIN_BUTTON_4    V4

#define VPIN_BUTTON_C    V9

bool toggleState_1 = LOW; //Define integer to remember the toggle state for relay 1
bool toggleState_2 = LOW; //Define integer to remember the toggle state for relay 2
bool toggleState_3 = LOW; //Define integer to remember the toggle state for relay 3
bool toggleState_4 = LOW; //Define integer to remember the toggle state for relay 4

bool SwitchState_1 = LOW;
bool SwitchState_2 = LOW;
bool SwitchState_3 = LOW;
bool SwitchState_4 = LOW;

BLYNK_WRITE(VPIN_BUTTON_1) {
  toggleState_1 = param.asInt();
  if(toggleState_1 == 1){
    digitalWrite(RelayPin1, LOW);
  }
  else { 
    digitalWrite(RelayPin1, HIGH);
  }
}

BLYNK_WRITE(VPIN_BUTTON_2) {
  toggleState_2 = param.asInt();
  if(toggleState_2 == 1){
    digitalWrite(RelayPin2, LOW);
  }
  else { 
    digitalWrite(RelayPin2, HIGH);
  }
}

BLYNK_WRITE(VPIN_BUTTON_3) {
  toggleState_3 = param.asInt();
  if(toggleState_3 == 1){
    digitalWrite(RelayPin3, LOW);
  }
  else { 
    digitalWrite(RelayPin3, HIGH);
  }
}

BLYNK_WRITE(VPIN_BUTTON_4) {
  toggleState_4 = param.asInt();
  if(toggleState_4 == 1){
    digitalWrite(RelayPin4, LOW);
  }
  else { 
    digitalWrite(RelayPin4, HIGH);
  }
}

BLYNK_WRITE(VPIN_BUTTON_C) {
  all_SwitchOff();
}


void all_SwitchOff(){
  toggleState_1 = 0; digitalWrite(RelayPin1, HIGH); Blynk.virtualWrite(VPIN_BUTTON_1, toggleState_1); delay(100);
  toggleState_2 = 0; digitalWrite(RelayPin2, HIGH); Blynk.virtualWrite(VPIN_BUTTON_2, toggleState_2); delay(100);
  toggleState_3 = 0; digitalWrite(RelayPin3, HIGH); Blynk.virtualWrite(VPIN_BUTTON_3, toggleState_3); delay(100);
  toggleState_4 = 0; digitalWrite(RelayPin4, HIGH); Blynk.virtualWrite(VPIN_BUTTON_4, toggleState_4); delay(100);

}


void setup()
{
  Serial.begin(115200);
  delay(100);
  
  pinMode(RelayPin1, OUTPUT);
  pinMode(RelayPin2, OUTPUT);
  pinMode(RelayPin3, OUTPUT);
  pinMode(RelayPin4, OUTPUT);

  pinMode(wifiLed, OUTPUT);

  pinMode(SwitchPin1, INPUT_PULLUP);
  pinMode(SwitchPin2, INPUT_PULLUP);
  pinMode(SwitchPin3, INPUT_PULLUP);
  pinMode(SwitchPin4, INPUT_PULLUP);

  digitalWrite(RelayPin1, HIGH);
  digitalWrite(RelayPin2, HIGH);
  digitalWrite(RelayPin3, HIGH);
  digitalWrite(RelayPin4, HIGH);

  irrecv.enableIRIn();
  BlynkEdgent.begin();
}

void loop() {
  manual_control(); //Manual Switch Control
  ir_remote(); //IR remote Control
  BlynkEdgent.run();
}

And the header file of blynkedgent.h

extern "C" {
  void app_loop();
  void eraseMcuConfig();
  void restartMCU();
}

#include "Settings.h"
#include <BlynkSimpleEsp32_SSL.h>

#ifndef BLYNK_NEW_LIBRARY
#error "Old version of Blynk library is in use. Please replace it with the new one."
#endif

#if !defined(BLYNK_TEMPLATE_ID) || !defined(BLYNK_DEVICE_NAME)
#error "Please specify your BLYNK_TEMPLATE_ID and BLYNK_DEVICE_NAME"
#endif

#include "BlynkState.h"
#include "ConfigStore.h"
#include "ResetButton.h"
#include "ConfigMode.h"
#include "Indicator.h"
#include "OTA.h"
#include "Console.h"

void manual_control();
void ir_remote();

inline
void BlynkState::set(State m) {
  if (state != m && m < MODE_MAX_VALUE) {
    DEBUG_PRINT(String(StateStr[state]) + " => " + StateStr[m]);
    state = m;

    // You can put your state handling here,
    // i.e. implement custom indication
  }
}

void printDeviceBanner()
{
  Blynk.printBanner();
  DEBUG_PRINT("--------------------------");
  DEBUG_PRINT(String("Product:  ") + BLYNK_DEVICE_NAME);
  DEBUG_PRINT(String("Firmware: ") + BLYNK_FIRMWARE_VERSION " (build " __DATE__ " " __TIME__ ")");
  if (configStore.getFlag(CONFIG_FLAG_VALID)) {
    DEBUG_PRINT(String("Token:    ...") + (configStore.cloudToken+28));
  }
  DEBUG_PRINT(String("Device:   ") + BLYNK_INFO_DEVICE + " @ " + ESP.getCpuFreqMHz() + "MHz");
  DEBUG_PRINT(String("MAC:      ") + WiFi.macAddress());
  DEBUG_PRINT(String("Flash:    ") + ESP.getFlashChipSize() / 1024 + "K");
  DEBUG_PRINT(String("ESP sdk:  ") + ESP.getSdkVersion());
  DEBUG_PRINT(String("Chip rev: ") + ESP.getChipRevision());
  DEBUG_PRINT(String("Free mem: ") + ESP.getFreeHeap());
  DEBUG_PRINT("--------------------------");
}

void runBlynkWithChecks() {
  Blynk.run();
  if (BlynkState::get() == MODE_RUNNING) {
    if (!Blynk.connected()) {
      if (WiFi.status() == WL_CONNECTED) {
        BlynkState::set(MODE_CONNECTING_CLOUD);
      } else {
        BlynkState::set(MODE_CONNECTING_NET);
      }
    }
  }
}

class Edgent {

public:
  void begin()
  {
    WiFi.persistent(false);
    WiFi.enableSTA(true); // Needed to get MAC

    indicator_init();
    button_init();
    config_init();
    console_init();

    printDeviceBanner();

    if (configStore.getFlag(CONFIG_FLAG_VALID)) {
      BlynkState::set(MODE_CONNECTING_NET);
    } else if (config_load_blnkopt()) {
      DEBUG_PRINT("Firmware is preprovisioned");
      BlynkState::set(MODE_CONNECTING_NET);
    } else {
      BlynkState::set(MODE_WAIT_CONFIG);
    }
  }

  void run() {
    app_loop();
    switch (BlynkState::get()) {
    case MODE_WAIT_CONFIG:       
    case MODE_CONFIGURING:       enterConfigMode();    break;
    case MODE_CONNECTING_NET:    enterConnectNet();    break;
    case MODE_CONNECTING_CLOUD:  enterConnectCloud();  break;
    case MODE_RUNNING:           runBlynkWithChecks(); break;
    case MODE_OTA_UPGRADE:       enterOTA();           break;
    case MODE_SWITCH_TO_STA:     enterSwitchToSTA();   break;
    case MODE_RESET_CONFIG:      enterResetConfig();   break;
    default:                     enterError();         break;
    }
  }

};

Edgent BlynkEdgent;
BlynkTimer edgentTimer;

void app_loop() {
    edgentTimer.run();
    edgentConsole.run();
     manual_control();
     ir_remote();
}

void manual_control()
{
  if (digitalRead(SwitchPin1) == LOW && SwitchState_1 == LOW) {
    digitalWrite(RelayPin1, LOW);
    Blynk.virtualWrite(VPIN_BUTTON_1, HIGH);
    toggleState_1 = HIGH;
    SwitchState_1 = HIGH;
    Serial.println("Switch-1 on");
  }
  if (digitalRead(SwitchPin1) == HIGH && SwitchState_1 == HIGH) {
    digitalWrite(RelayPin1, HIGH);
    Blynk.virtualWrite(VPIN_BUTTON_1, LOW);
    toggleState_1 = LOW;
    SwitchState_1 = 0;
    Serial.println("Switch-1 off");
  }
  if (digitalRead(SwitchPin2) == LOW && SwitchState_2 == LOW) {
    digitalWrite(RelayPin2, LOW);
    Blynk.virtualWrite(VPIN_BUTTON_2, HIGH);
    toggleState_2 = HIGH;
    SwitchState_2 = HIGH;
    Serial.println("Switch-2 on");
  }
  if (digitalRead(SwitchPin2) == HIGH && SwitchState_2 == HIGH) {
    digitalWrite(RelayPin2, HIGH);
    Blynk.virtualWrite(VPIN_BUTTON_2, LOW);
    toggleState_2 = LOW;
    SwitchState_2 = LOW;
    Serial.println("Switch-2 off");
  }
  if (digitalRead(SwitchPin3) == LOW && SwitchState_3 == LOW) {
    digitalWrite(RelayPin3, LOW);
    Blynk.virtualWrite(VPIN_BUTTON_3, HIGH);
    toggleState_3 = HIGH;
    SwitchState_3 = HIGH;
    Serial.println("Switch-3 on");
  }
  if (digitalRead(SwitchPin3) == HIGH && SwitchState_3 == HIGH) {
    digitalWrite(RelayPin3, HIGH);
    Blynk.virtualWrite(VPIN_BUTTON_3, LOW);
    toggleState_3 = LOW;
    SwitchState_3 = LOW;
    Serial.println("Switch-3 off");
  }
  if (digitalRead(SwitchPin4) == LOW && SwitchState_4 == LOW) {
    digitalWrite(RelayPin4, LOW);
    Blynk.virtualWrite(VPIN_BUTTON_4, HIGH);
    toggleState_4 = HIGH;
    SwitchState_4 = HIGH;
    Serial.println("Switch-4 on");
  }
  if (digitalRead(SwitchPin4) == HIGH && SwitchState_4 == HIGH) {
    digitalWrite(RelayPin4, HIGH);
    Blynk.virtualWrite(VPIN_BUTTON_4, LOW);
    toggleState_4 = LOW;
    SwitchState_4 = LOW;
    Serial.println("Switch-4 off");
  }
  }

void ir_remote(){
  if (irrecv.decode(&results)) {
      switch(results.value){
          case 0x80BF49B6:  
            digitalWrite(RelayPin1, toggleState_1);
            toggleState_1 = !toggleState_1;
            Blynk.virtualWrite(VPIN_BUTTON_1, toggleState_1);
            delay(100);            
            break;
          case 0x80BFC936:  
            digitalWrite(RelayPin2, toggleState_2);
            toggleState_2 = !toggleState_2;
            Blynk.virtualWrite(VPIN_BUTTON_2, toggleState_2);
            delay(100);            
            break;
          case 0x80BF33CC:  
            digitalWrite(RelayPin3, toggleState_3);
            toggleState_3 = !toggleState_3;
            Blynk.virtualWrite(VPIN_BUTTON_3, toggleState_3);
            delay(100);            
            break;
          case 0x80BF718E:  
            digitalWrite(RelayPin4, toggleState_4);
            toggleState_4 = !toggleState_4;
            Blynk.virtualWrite(VPIN_BUTTON_4, toggleState_4);
            delay(100);            
            break;
          default : break;         
        }   
        //Serial.println(results.value, HEX);    
        irrecv.resume();   
  } 
}

and ERROR

Arduino: 1.8.12 (Windows 10), Board: "ESP32 Dev Module, Disabled, Default 4MB with spiffs (1.2MB APP/1.5MB SPIFFS), 240MHz (WiFi/BT), QIO, 80MHz, 4MB (32Mb), 921600, None"

In file included from C:\Users\jamsa\OneDrive\Desktop\Edgent_ESP32_again_and_again\Edgent_ESP32_again_and_again.ino:17:0:

sketch\BlynkEdgent.h: In function 'void manual_control()':

BlynkEdgent.h:126:19: error: 'SwitchPin1' was not declared in this scope

   if (digitalRead(SwitchPin1) == LOW && SwitchState_1 == LOW) {

                   ^

BlynkEdgent.h:126:41: error: 'SwitchState_1' was not declared in this scope

   if (digitalRead(SwitchPin1) == LOW && SwitchState_1 == LOW) {

                                         ^

BlynkEdgent.h:127:18: error: 'RelayPin1' was not declared in this scope

     digitalWrite(RelayPin1, LOW);

                  ^

BlynkEdgent.h:128:24: error: 'VPIN_BUTTON_1' was not declared in this scope

     Blynk.virtualWrite(VPIN_BUTTON_1, HIGH);

                        ^

BlynkEdgent.h:129:5: error: 'toggleState_1' was not declared in this scope

     toggleState_1 = HIGH;

     ^

BlynkEdgent.h:133:19: error: 'SwitchPin1' was not declared in this scope

   if (digitalRead(SwitchPin1) == HIGH && SwitchState_1 == HIGH) {

                   ^

BlynkEdgent.h:133:42: error: 'SwitchState_1' was not declared in this scope

   if (digitalRead(SwitchPin1) == HIGH && SwitchState_1 == HIGH) {

                                          ^

BlynkEdgent.h:134:18: error: 'RelayPin1' was not declared in this scope

     digitalWrite(RelayPin1, HIGH);

                  ^

BlynkEdgent.h:135:24: error: 'VPIN_BUTTON_1' was not declared in this scope

     Blynk.virtualWrite(VPIN_BUTTON_1, LOW);

                        ^

BlynkEdgent.h:136:5: error: 'toggleState_1' was not declared in this scope

     toggleState_1 = LOW;

     ^

BlynkEdgent.h:140:19: error: 'SwitchPin2' was not declared in this scope

   if (digitalRead(SwitchPin2) == LOW && SwitchState_2 == LOW) {

                   ^

BlynkEdgent.h:140:41: error: 'SwitchState_2' was not declared in this scope

   if (digitalRead(SwitchPin2) == LOW && SwitchState_2 == LOW) {

                                         ^

BlynkEdgent.h:141:18: error: 'RelayPin2' was not declared in this scope

     digitalWrite(RelayPin2, LOW);

                  ^

BlynkEdgent.h:142:24: error: 'VPIN_BUTTON_2' was not declared in this scope

     Blynk.virtualWrite(VPIN_BUTTON_2, HIGH);

                        ^

BlynkEdgent.h:143:5: error: 'toggleState_2' was not declared in this scope

     toggleState_2 = HIGH;

     ^

BlynkEdgent.h:147:19: error: 'SwitchPin2' was not declared in this scope

   if (digitalRead(SwitchPin2) == HIGH && SwitchState_2 == HIGH) {

                   ^

BlynkEdgent.h:147:42: error: 'SwitchState_2' was not declared in this scope

   if (digitalRead(SwitchPin2) == HIGH && SwitchState_2 == HIGH) {

                                          ^

BlynkEdgent.h:148:18: error: 'RelayPin2' was not declared in this scope

     digitalWrite(RelayPin2, HIGH);

                  ^

BlynkEdgent.h:149:24: error: 'VPIN_BUTTON_2' was not declared in this scope

     Blynk.virtualWrite(VPIN_BUTTON_2, LOW);

                        ^

BlynkEdgent.h:150:5: error: 'toggleState_2' was not declared in this scope

     toggleState_2 = LOW;

     ^

BlynkEdgent.h:154:19: error: 'SwitchPin3' was not declared in this scope

   if (digitalRead(SwitchPin3) == LOW && SwitchState_3 == LOW) {

                   ^

BlynkEdgent.h:154:41: error: 'SwitchState_3' was not declared in this scope

   if (digitalRead(SwitchPin3) == LOW && SwitchState_3 == LOW) {

                                         ^

BlynkEdgent.h:155:18: error: 'RelayPin3' was not declared in this scope

     digitalWrite(RelayPin3, LOW);

                  ^

BlynkEdgent.h:156:24: error: 'VPIN_BUTTON_3' was not declared in this scope

     Blynk.virtualWrite(VPIN_BUTTON_3, HIGH);

                        ^

BlynkEdgent.h:157:5: error: 'toggleState_3' was not declared in this scope

     toggleState_3 = HIGH;

     ^

BlynkEdgent.h:161:19: error: 'SwitchPin3' was not declared in this scope

   if (digitalRead(SwitchPin3) == HIGH && SwitchState_3 == HIGH) {

                   ^

BlynkEdgent.h:161:42: error: 'SwitchState_3' was not declared in this scope

   if (digitalRead(SwitchPin3) == HIGH && SwitchState_3 == HIGH) {

                                          ^

BlynkEdgent.h:162:18: error: 'RelayPin3' was not declared in this scope

     digitalWrite(RelayPin3, HIGH);

                  ^

BlynkEdgent.h:163:24: error: 'VPIN_BUTTON_3' was not declared in this scope

     Blynk.virtualWrite(VPIN_BUTTON_3, LOW);

                        ^

BlynkEdgent.h:164:5: error: 'toggleState_3' was not declared in this scope

     toggleState_3 = LOW;

     ^

BlynkEdgent.h:168:19: error: 'SwitchPin4' was not declared in this scope

   if (digitalRead(SwitchPin4) == LOW && SwitchState_4 == LOW) {

                   ^

BlynkEdgent.h:168:41: error: 'SwitchState_4' was not declared in this scope

   if (digitalRead(SwitchPin4) == LOW && SwitchState_4 == LOW) {

                                         ^

BlynkEdgent.h:169:18: error: 'RelayPin4' was not declared in this scope

     digitalWrite(RelayPin4, LOW);

                  ^

BlynkEdgent.h:170:24: error: 'VPIN_BUTTON_4' was not declared in this scope

     Blynk.virtualWrite(VPIN_BUTTON_4, HIGH);

                        ^

BlynkEdgent.h:171:5: error: 'toggleState_4' was not declared in this scope

     toggleState_4 = HIGH;

     ^

BlynkEdgent.h:175:19: error: 'SwitchPin4' was not declared in this scope

   if (digitalRead(SwitchPin4) == HIGH && SwitchState_4 == HIGH) {

                   ^

BlynkEdgent.h:175:42: error: 'SwitchState_4' was not declared in this scope

   if (digitalRead(SwitchPin4) == HIGH && SwitchState_4 == HIGH) {

                                          ^

BlynkEdgent.h:176:18: error: 'RelayPin4' was not declared in this scope

     digitalWrite(RelayPin4, HIGH);

                  ^

BlynkEdgent.h:177:24: error: 'VPIN_BUTTON_4' was not declared in this scope

     Blynk.virtualWrite(VPIN_BUTTON_4, LOW);

                        ^

BlynkEdgent.h:178:5: error: 'toggleState_4' was not declared in this scope

     toggleState_4 = LOW;

     ^

sketch\BlynkEdgent.h: In function 'void ir_remote()':

BlynkEdgent.h:185:7: error: 'irrecv' was not declared in this scope

   if (irrecv.decode(&results)) {

       ^

BlynkEdgent.h:185:22: error: 'results' was not declared in this scope

   if (irrecv.decode(&results)) {

                      ^

BlynkEdgent.h:188:26: error: 'RelayPin1' was not declared in this scope

             digitalWrite(RelayPin1, toggleState_1);

                          ^

BlynkEdgent.h:188:37: error: 'toggleState_1' was not declared in this scope

             digitalWrite(RelayPin1, toggleState_1);

                                     ^

BlynkEdgent.h:190:32: error: 'VPIN_BUTTON_1' was not declared in this scope

             Blynk.virtualWrite(VPIN_BUTTON_1, toggleState_1);

                                ^

BlynkEdgent.h:194:26: error: 'RelayPin2' was not declared in this scope

             digitalWrite(RelayPin2, toggleState_2);

                          ^

BlynkEdgent.h:194:37: error: 'toggleState_2' was not declared in this scope

             digitalWrite(RelayPin2, toggleState_2);

                                     ^

BlynkEdgent.h:196:32: error: 'VPIN_BUTTON_2' was not declared in this scope

             Blynk.virtualWrite(VPIN_BUTTON_2, toggleState_2);

                                ^

BlynkEdgent.h:200:26: error: 'RelayPin3' was not declared in this scope

             digitalWrite(RelayPin3, toggleState_3);

                          ^

BlynkEdgent.h:200:37: error: 'toggleState_3' was not declared in this scope

             digitalWrite(RelayPin3, toggleState_3);

                                     ^

BlynkEdgent.h:202:32: error: 'VPIN_BUTTON_3' was not declared in this scope

             Blynk.virtualWrite(VPIN_BUTTON_3, toggleState_3);

                                ^

BlynkEdgent.h:206:26: error: 'RelayPin4' was not declared in this scope

             digitalWrite(RelayPin4, toggleState_4);

                          ^

BlynkEdgent.h:206:37: error: 'toggleState_4' was not declared in this scope

             digitalWrite(RelayPin4, toggleState_4);

                                     ^

BlynkEdgent.h:208:32: error: 'VPIN_BUTTON_4' was not declared in this scope

             Blynk.virtualWrite(VPIN_BUTTON_4, toggleState_4);

                                ^

Multiple libraries were found for "IRremote.h"
 Used: C:\Users\jamsa\OneDrive\Documents\Arduino\libraries\IRremote
 Not used: C:\Users\jamsa\OneDrive\Documents\Arduino\libraries\Arduino-IRremote-master
Multiple libraries were found for "BlynkSimpleEsp32_SSL.h"
 Used: C:\Users\jamsa\OneDrive\Documents\Arduino\libraries\Blynk
 Not used: C:\Program Files (x86)\Arduino\libraries\Blynk
Multiple libraries were found for "WiFi.h"
 Used: C:\Users\jamsa\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.3\libraries\WiFi
 Not used: C:\Users\jamsa\OneDrive\Documents\Arduino\libraries\WiFiNINA
 Not used: C:\Program Files (x86)\Arduino\libraries\WiFi
exit status 1
'SwitchPin1' was not declared in this scope

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

Hey there.
I modified the sketch now it should work. I will upload it to mega and send you the link.

1 Like

Can you send me the link

Or project file

jamsyogendra@gmail.com

I’m so sorry buddy, I forgot to send it.

https://mega.nz/file/1cdSjRAA#KSH5kW9FPPpJDv7DtzoooGYXc9ewJGBl0Sf2teDv5oI

Try it, if you face any issue just let me know please.

Greetings.

1 Like

Hey codes working perfectly :relaxed: :heart:

Thankyou thankyou so much

#John93

1 Like

Problem solve

I’m so glad it worked.