Need help migrating

void setup()
{
 Serial.begin(9600);

 pinMode(RelayPin1, OUTPUT);
 pinMode(RelayPin2, OUTPUT);
 pinMode(RelayPin3, OUTPUT);
 pinMode(RelayPin4, OUTPUT);
 pinMode(RelayPin5, OUTPUT);
 pinMode(RelayPin6, OUTPUT);
 pinMode(RelayPin7, OUTPUT);
 pinMode(RelayPin8, OUTPUT);

 pinMode(wifiLed, OUTPUT);

 pinMode(SwitchPin1, INPUT_PULLUP);
 pinMode(SwitchPin2, INPUT_PULLUP);
 pinMode(SwitchPin3, INPUT_PULLUP);
 pinMode(SwitchPin4, INPUT_PULLUP);
 pinMode(SwitchPin5, INPUT_PULLUP);
 pinMode(SwitchPin6, INPUT_PULLUP);
 pinMode(SwitchPin7, INPUT_PULLUP);
 pinMode(SwitchPin8, INPUT_PULLUP);

 //During Starting all Relays should TURN OFF
 digitalWrite(RelayPin1, !toggleState_1);
 digitalWrite(RelayPin2, !toggleState_2);
 digitalWrite(RelayPin3, !toggleState_3);
 digitalWrite(RelayPin4, !toggleState_4);
 digitalWrite(RelayPin5, !toggleState_5);
 digitalWrite(RelayPin6, !toggleState_6);
 digitalWrite(RelayPin7, !toggleState_7);
 digitalWrite(RelayPin8, !toggleState_8);

 digitalWrite(wifiLed, LOW);

 //Blynk.begin(auth, ssid, pass);
 WiFi.begin(ssid, pass);
 timer.setInterval(1000L, manual_control);
 timer.setInterval(2000L, checkBlynkStatus); // check if Blynk server is connected every 2 seconds
 Blynk.config(auth);
 delay(1000);
 
 if (!fetch_blynk_state){
   Blynk.virtualWrite(VPIN_BUTTON_1, toggleState_1);
   Blynk.virtualWrite(VPIN_BUTTON_2, toggleState_2);
   Blynk.virtualWrite(VPIN_BUTTON_3, toggleState_3);
   Blynk.virtualWrite(VPIN_BUTTON_4, toggleState_4);
   Blynk.virtualWrite(VPIN_BUTTON_5, toggleState_5);
   Blynk.virtualWrite(VPIN_BUTTON_6, toggleState_6);
   Blynk.virtualWrite(VPIN_BUTTON_7, toggleState_7);
   Blynk.virtualWrite(VPIN_BUTTON_8, toggleState_8);
 }
}
1 Like

thanks again

1 Like

in my esp32 , when wifi is connected the blue led is glow , on my esp32 , but i want to flash ( on and off ) it when it connected automatically

Try this

void checkBlynkStatus() { // called every 2 seconds by SimpleTimer

 bool isconnected = Blynk.connected();
 if (isconnected == false) {
   wifiFlag = 1;
   Serial.println("Blynk Not Connected");
   digitalWrite(wifiLed, LOW);
 }
 if (isconnected == true) {
   wifiFlag = 0;
   if (!fetch_blynk_state){
   Blynk.virtualWrite(VPIN_BUTTON_1, toggleState_1);
   Blynk.virtualWrite(VPIN_BUTTON_2, toggleState_2);
   Blynk.virtualWrite(VPIN_BUTTON_3, toggleState_3);
   Blynk.virtualWrite(VPIN_BUTTON_4, toggleState_4);
   Blynk.virtualWrite(VPIN_BUTTON_5, toggleState_5);
   Blynk.virtualWrite(VPIN_BUTTON_6, toggleState_6);
   Blynk.virtualWrite(VPIN_BUTTON_7, toggleState_7);
   Blynk.virtualWrite(VPIN_BUTTON_8, toggleState_8);
   }
   digitalWrite(wifiLed, HIGH);
   Serial.println("Blynk Connected");
   timer.setTimeout(1000, []() 
    {  
    digitalWrite(wifiLed, LOW);
 }
}

this error massage shows when i try to upload


Code_ESP32s_NEW_Blynk_8Relay_Switch:157:18: error: 'pumpPin' was not declared in this scope

     digitalWrite(pumpPin[0], LOW);

                  ^

C:\Users\kamal\Videos\1st\Code_ESP32s_NEW_Blynk_8Relay_Switch\Code_ESP32s_NEW_Blynk_8Relay_Switch.ino: In function 'void checkBlynkStatus()':

Code_ESP32s_NEW_Blynk_8Relay_Switch:159:1: error: expected ')' before '}' token

 }

 ^

Code_ESP32s_NEW_Blynk_8Relay_Switch:161:19: error: a function-definition is not allowed here before '{' token

 BLYNK_CONNECTED() {

                   ^

Code_ESP32s_NEW_Blynk_8Relay_Switch:365:1: error: expected '}' at end of input

 }

 ^

Multiple libraries were found for "WiFi.h"

 Used: C:\Users\kamal\Documents\ArduinoData\packages\esp32\hardware\esp32\1.0.6\libraries\WiFi

 Not used: C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.57.0_x86__mdqgnx93n4wtt\libraries\WiFi

Using library WiFi at version 1.0 in folder: C:\Users\kamal\Documents\ArduinoData\packages\esp32\hardware\esp32\1.0.6\libraries\WiFi 

Using library Blynk at version 1.0.1 in folder: C:\Users\kamal\Documents\Arduino\libraries\Blynk 

exit status 1

'pumpPin' was not declared in this scope

You have to change pumpPin[0]

i dont understand

I’m guessing that it’s wifiLed that he wants to flash.

Pete.

That’s Right.

digitalWrite(wifiLed, LOW);

is there any code for this

Go back to post number 24, I’ve modified it.

your massage is " You have to change pumpPin[0] " , i dont understand the meaning of pumpPin[0]

I’m using it in my sketch, it was a mistake :sweat_smile:.
Post number 24 is ready, you can give it a try.

can you please edit for me, i am not understand where to past your code .

#define BLYNK_DEVICE_NAME "testing"
#define BLYNK_AUTH_TOKEN "arvMO6TX9xYpouEi8ze6T1fpc7bRRcro"

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "ROUTER 1";
char pass[] = "9238855k@";

bool fetch_blynk_state = true;  //true or false

//#define BLYNK_PRINT Serial
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>

// define the GPIO connected with Relays and switches
#define RelayPin1 23  //D23
#define RelayPin2 22  //D22
#define RelayPin3 21  //D21
#define RelayPin4 19  //D19
#define RelayPin5 18  //D18
#define RelayPin6 5   //D5
#define RelayPin7 25  //D25
#define RelayPin8 26  //D26

#define SwitchPin1 13  //D13
#define SwitchPin2 12  //D12
#define SwitchPin3 14  //D14
#define SwitchPin4 27  //D27
#define SwitchPin5 33  //D33
#define SwitchPin6 32  //D32
#define SwitchPin7 15  //D15
#define SwitchPin8 4   //D4

#define wifiLed   2   //D2

//Change the virtual pins according the rooms
#define VPIN_BUTTON_1    V1
#define VPIN_BUTTON_2    V2
#define VPIN_BUTTON_3    V3 
#define VPIN_BUTTON_4    V4
#define VPIN_BUTTON_5    V5 
#define VPIN_BUTTON_6    V6
#define VPIN_BUTTON_7    V7 
#define VPIN_BUTTON_8    V8
#define VPIN_BUTTON_C    V9

// Relay State
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 toggleState_5 = LOW; //Define integer to remember the toggle state for relay 5
bool toggleState_6 = LOW; //Define integer to remember the toggle state for relay 6
bool toggleState_7 = LOW; //Define integer to remember the toggle state for relay 7
bool toggleState_8 = LOW; //Define integer to remember the toggle state for relay 8

// Switch State
bool SwitchState_1 = LOW;
bool SwitchState_2 = LOW;
bool SwitchState_3 = LOW;
bool SwitchState_4 = LOW;
bool SwitchState_5 = LOW;
bool SwitchState_6 = LOW;
bool SwitchState_7 = LOW;
bool SwitchState_8 = LOW;

int wifiFlag = 0;

char auth[] = BLYNK_AUTH_TOKEN;

BlynkTimer timer;

// When App button is pushed - switch the state

BLYNK_WRITE(VPIN_BUTTON_1) {
  toggleState_1 = param.asInt();
  digitalWrite(RelayPin1, !toggleState_1);
}

BLYNK_WRITE(VPIN_BUTTON_2) {
  toggleState_2 = param.asInt();
  digitalWrite(RelayPin2, !toggleState_2);
}

BLYNK_WRITE(VPIN_BUTTON_3) {
  toggleState_3 = param.asInt();
  digitalWrite(RelayPin3, !toggleState_3);
}

BLYNK_WRITE(VPIN_BUTTON_4) {
  toggleState_4 = param.asInt();
  digitalWrite(RelayPin4, !toggleState_4);
}

BLYNK_WRITE(VPIN_BUTTON_5) {
  toggleState_5 = param.asInt();
  digitalWrite(RelayPin5, !toggleState_5);
}

BLYNK_WRITE(VPIN_BUTTON_6) {
  toggleState_6 = param.asInt();
  digitalWrite(RelayPin6, !toggleState_6);
}

BLYNK_WRITE(VPIN_BUTTON_7) {
  toggleState_7 = param.asInt();
  digitalWrite(RelayPin7, !toggleState_7);
}

BLYNK_WRITE(VPIN_BUTTON_8) {
  toggleState_8 = param.asInt();
  digitalWrite(RelayPin8, !toggleState_8);
}

void checkBlynkStatus() { // called every 2 seconds by SimpleTimer

  bool isconnected = Blynk.connected();
  if (isconnected == false) {
    wifiFlag = 1;
    Serial.println("Blynk Not Connected");
    digitalWrite(wifiLed, LOW);
  }
  if (isconnected == true) {
    wifiFlag = 0;
    if (!fetch_blynk_state){
    Blynk.virtualWrite(VPIN_BUTTON_1, toggleState_1);
    Blynk.virtualWrite(VPIN_BUTTON_2, toggleState_2);
    Blynk.virtualWrite(VPIN_BUTTON_3, toggleState_3);
    Blynk.virtualWrite(VPIN_BUTTON_4, toggleState_4);
    Blynk.virtualWrite(VPIN_BUTTON_5, toggleState_5);
    Blynk.virtualWrite(VPIN_BUTTON_6, toggleState_6);
    Blynk.virtualWrite(VPIN_BUTTON_7, toggleState_7);
    Blynk.virtualWrite(VPIN_BUTTON_8, toggleState_8);
    }
    digitalWrite(wifiLed, HIGH);
    Serial.println("Blynk Connected");
  }
}

BLYNK_CONNECTED() {
  // Request the latest state from the server
  if (fetch_blynk_state){
    Blynk.syncVirtual(VPIN_BUTTON_1);
    Blynk.syncVirtual(VPIN_BUTTON_2);
    Blynk.syncVirtual(VPIN_BUTTON_3);
    Blynk.syncVirtual(VPIN_BUTTON_4);
    Blynk.syncVirtual(VPIN_BUTTON_5);
    Blynk.syncVirtual(VPIN_BUTTON_6);
    Blynk.syncVirtual(VPIN_BUTTON_7);
    Blynk.syncVirtual(VPIN_BUTTON_8);
  }
}

void manual_control()
{
  if (digitalRead(SwitchPin1) == LOW && SwitchState_1 == LOW) {
    digitalWrite(RelayPin1, LOW);
    toggleState_1 = 1;
    SwitchState_1 = HIGH;
    Blynk.virtualWrite(VPIN_BUTTON_1, toggleState_1);
    Serial.println("Switch-1 on");
  }
  if (digitalRead(SwitchPin1) == HIGH && SwitchState_1 == HIGH) {
    digitalWrite(RelayPin1, HIGH);
    toggleState_1 = 0;
    SwitchState_1 = LOW;
    Blynk.virtualWrite(VPIN_BUTTON_1, toggleState_1);
    Serial.println("Switch-1 off");
  }
  if (digitalRead(SwitchPin2) == LOW && SwitchState_2 == LOW) {
    digitalWrite(RelayPin2, LOW);
    toggleState_2 = 1;
    SwitchState_2 = HIGH;
    Blynk.virtualWrite(VPIN_BUTTON_2, toggleState_2);
    Serial.println("Switch-2 on");
  }
  if (digitalRead(SwitchPin2) == HIGH && SwitchState_2 == HIGH) {
    digitalWrite(RelayPin2, HIGH);
    toggleState_2 = 0;
    SwitchState_2 = LOW;
    Blynk.virtualWrite(VPIN_BUTTON_2, toggleState_2);
    Serial.println("Switch-2 off");
  }
  if (digitalRead(SwitchPin3) == LOW && SwitchState_3 == LOW) {
    digitalWrite(RelayPin3, LOW);
    toggleState_3 = 1;
    SwitchState_3 = HIGH;
    Blynk.virtualWrite(VPIN_BUTTON_3, toggleState_3);
    Serial.println("Switch-3 on");
  }
  if (digitalRead(SwitchPin3) == HIGH && SwitchState_3 == HIGH) {
    digitalWrite(RelayPin3, HIGH);
    toggleState_3 = 0;
    SwitchState_3 = LOW;
    Blynk.virtualWrite(VPIN_BUTTON_3, toggleState_3);
    Serial.println("Switch-3 off");
  }
  if (digitalRead(SwitchPin4) == LOW && SwitchState_4 == LOW) {
    digitalWrite(RelayPin4, LOW);
    toggleState_4 = 1;
    SwitchState_4 = HIGH;
    Blynk.virtualWrite(VPIN_BUTTON_4, toggleState_4);
    Serial.println("Switch-4 on");
  }
  if (digitalRead(SwitchPin4) == HIGH && SwitchState_4 == HIGH) {
    digitalWrite(RelayPin4, HIGH);
    toggleState_4 = 0;
    SwitchState_4 = LOW;
    Blynk.virtualWrite(VPIN_BUTTON_4, toggleState_4);
    Serial.println("Switch-4 off");
  }
  if (digitalRead(SwitchPin5) == LOW && SwitchState_5 == LOW) {
    digitalWrite(RelayPin5, LOW);
    toggleState_5 = 1;
    SwitchState_5 = HIGH;
    Blynk.virtualWrite(VPIN_BUTTON_5, toggleState_5);
    Serial.println("Switch-5 on");
  }
  if (digitalRead(SwitchPin5) == HIGH && SwitchState_5 == HIGH) {
    digitalWrite(RelayPin5, HIGH);
    toggleState_5 = 0;
    SwitchState_5 = LOW;
    Blynk.virtualWrite(VPIN_BUTTON_5, toggleState_5);
    Serial.println("Switch-5 off");
  }
  if (digitalRead(SwitchPin6) == LOW && SwitchState_6 == LOW) {
    digitalWrite(RelayPin6, LOW);
    toggleState_6 = 1;
    SwitchState_6 = HIGH;
    Blynk.virtualWrite(VPIN_BUTTON_6, toggleState_6);
    Serial.println("Switch-6 on");
  }
  if (digitalRead(SwitchPin6) == HIGH && SwitchState_6 == HIGH) {
    digitalWrite(RelayPin6, HIGH);
    toggleState_6 = 0;
    SwitchState_6 = LOW;
    Blynk.virtualWrite(VPIN_BUTTON_6, toggleState_6);
    Serial.println("Switch-6 off");
  }
  if (digitalRead(SwitchPin7) == LOW && SwitchState_7 == LOW) {
    digitalWrite(RelayPin7, LOW);
    toggleState_7 = 1;
    SwitchState_7 = HIGH;
    Blynk.virtualWrite(VPIN_BUTTON_7, toggleState_7);
    Serial.println("Switch-7 on");
  }
  if (digitalRead(SwitchPin7) == HIGH && SwitchState_7 == HIGH) {
    digitalWrite(RelayPin7, HIGH);
    toggleState_7 = 0;
    SwitchState_7 = LOW;
    Blynk.virtualWrite(VPIN_BUTTON_7, toggleState_7);
    Serial.println("Switch-7 off");
  }
  if (digitalRead(SwitchPin8) == LOW && SwitchState_8 == LOW) {
    digitalWrite(RelayPin8, LOW);
    toggleState_8 = 1;
    SwitchState_8 = HIGH;
    Blynk.virtualWrite(VPIN_BUTTON_8, toggleState_8);
    Serial.println("Switch-8 on");
  }
  if (digitalRead(SwitchPin8) == HIGH && SwitchState_8 == HIGH) {
    digitalWrite(RelayPin8, HIGH);
    toggleState_8 = 0;
    SwitchState_8 = LOW;
    Blynk.virtualWrite(VPIN_BUTTON_8, toggleState_8);
    Serial.println("Switch-8 off");
  }
}  

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_5 = 0; digitalWrite(RelayPin5, HIGH); Blynk.virtualWrite(VPIN_BUTTON_5, toggleState_5); delay(100);
  toggleState_6 = 0; digitalWrite(RelayPin6, HIGH); Blynk.virtualWrite(VPIN_BUTTON_6, toggleState_6); delay(100);
  toggleState_7 = 0; digitalWrite(RelayPin7, HIGH); Blynk.virtualWrite(VPIN_BUTTON_7, toggleState_7); delay(100);
  toggleState_8 = 0; digitalWrite(RelayPin8, HIGH); Blynk.virtualWrite(VPIN_BUTTON_8, toggleState_8); delay(100);
}

void setup()
{
  Serial.begin(9600);

  pinMode(RelayPin1, OUTPUT);
  pinMode(RelayPin2, OUTPUT);
  pinMode(RelayPin3, OUTPUT);
  pinMode(RelayPin4, OUTPUT);
  pinMode(RelayPin5, OUTPUT);
  pinMode(RelayPin6, OUTPUT);
  pinMode(RelayPin7, OUTPUT);
  pinMode(RelayPin8, OUTPUT);

  pinMode(wifiLed, OUTPUT);

  pinMode(SwitchPin1, INPUT_PULLUP);
  pinMode(SwitchPin2, INPUT_PULLUP);
  pinMode(SwitchPin3, INPUT_PULLUP);
  pinMode(SwitchPin4, INPUT_PULLUP);
  pinMode(SwitchPin5, INPUT_PULLUP);
  pinMode(SwitchPin6, INPUT_PULLUP);
  pinMode(SwitchPin7, INPUT_PULLUP);
  pinMode(SwitchPin8, INPUT_PULLUP);

  //During Starting all Relays should TURN OFF
  digitalWrite(RelayPin1, !toggleState_1);
  digitalWrite(RelayPin2, !toggleState_2);
  digitalWrite(RelayPin3, !toggleState_3);
  digitalWrite(RelayPin4, !toggleState_4);
  digitalWrite(RelayPin5, !toggleState_5);
  digitalWrite(RelayPin6, !toggleState_6);
  digitalWrite(RelayPin7, !toggleState_7);
  digitalWrite(RelayPin8, !toggleState_8);

  digitalWrite(wifiLed, LOW);

  //Blynk.begin(auth, ssid, pass);
  WiFi.begin(ssid, pass);
  timer.setInterval(1000L, manual_control);
  timer.setInterval(2000L, checkBlynkStatus); // check if Blynk server is connected every 2 seconds
  Blynk.config(auth);
  delay(1000);
  
  if (!fetch_blynk_state){
    Blynk.virtualWrite(VPIN_BUTTON_1, toggleState_1);
    Blynk.virtualWrite(VPIN_BUTTON_2, toggleState_2);
    Blynk.virtualWrite(VPIN_BUTTON_3, toggleState_3);
    Blynk.virtualWrite(VPIN_BUTTON_4, toggleState_4);
    Blynk.virtualWrite(VPIN_BUTTON_5, toggleState_5);
    Blynk.virtualWrite(VPIN_BUTTON_6, toggleState_6);
    Blynk.virtualWrite(VPIN_BUTTON_7, toggleState_7);
    Blynk.virtualWrite(VPIN_BUTTON_8, toggleState_8);
  }
}

void loop()
{
  Blynk.run();
  timer.run();
}```
#define BLYNK_DEVICE_NAME "testing"
#define BLYNK_AUTH_TOKEN "arvMO6TX9xYpouEi8ze6T1fpc7bRRcro"

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "ROUTER 1";
char pass[] = "9238855k@";

bool fetch_blynk_state = true;  //true or false

//#define BLYNK_PRINT Serial
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>

// define the GPIO connected with Relays and switches
#define RelayPin1 23  //D23
#define RelayPin2 22  //D22
#define RelayPin3 21  //D21
#define RelayPin4 19  //D19
#define RelayPin5 18  //D18
#define RelayPin6 5   //D5
#define RelayPin7 25  //D25
#define RelayPin8 26  //D26

#define SwitchPin1 13  //D13
#define SwitchPin2 12  //D12
#define SwitchPin3 14  //D14
#define SwitchPin4 27  //D27
#define SwitchPin5 33  //D33
#define SwitchPin6 32  //D32
#define SwitchPin7 15  //D15
#define SwitchPin8 4   //D4

#define wifiLed   2   //D2

//Change the virtual pins according the rooms
#define VPIN_BUTTON_1    V1
#define VPIN_BUTTON_2    V2
#define VPIN_BUTTON_3    V3 
#define VPIN_BUTTON_4    V4
#define VPIN_BUTTON_5    V5 
#define VPIN_BUTTON_6    V6
#define VPIN_BUTTON_7    V7 
#define VPIN_BUTTON_8    V8
#define VPIN_BUTTON_C    V9

// Relay State
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 toggleState_5 = LOW; //Define integer to remember the toggle state for relay 5
bool toggleState_6 = LOW; //Define integer to remember the toggle state for relay 6
bool toggleState_7 = LOW; //Define integer to remember the toggle state for relay 7
bool toggleState_8 = LOW; //Define integer to remember the toggle state for relay 8

// Switch State
bool SwitchState_1 = LOW;
bool SwitchState_2 = LOW;
bool SwitchState_3 = LOW;
bool SwitchState_4 = LOW;
bool SwitchState_5 = LOW;
bool SwitchState_6 = LOW;
bool SwitchState_7 = LOW;
bool SwitchState_8 = LOW;

int wifiFlag = 0;

char auth[] = BLYNK_AUTH_TOKEN;

BlynkTimer timer;

// When App button is pushed - switch the state

BLYNK_WRITE(VPIN_BUTTON_1) {
  toggleState_1 = param.asInt();
  digitalWrite(RelayPin1, !toggleState_1);
}

BLYNK_WRITE(VPIN_BUTTON_2) {
  toggleState_2 = param.asInt();
  digitalWrite(RelayPin2, !toggleState_2);
}

BLYNK_WRITE(VPIN_BUTTON_3) {
  toggleState_3 = param.asInt();
  digitalWrite(RelayPin3, !toggleState_3);
}

BLYNK_WRITE(VPIN_BUTTON_4) {
  toggleState_4 = param.asInt();
  digitalWrite(RelayPin4, !toggleState_4);
}

BLYNK_WRITE(VPIN_BUTTON_5) {
  toggleState_5 = param.asInt();
  digitalWrite(RelayPin5, !toggleState_5);
}

BLYNK_WRITE(VPIN_BUTTON_6) {
  toggleState_6 = param.asInt();
  digitalWrite(RelayPin6, !toggleState_6);
}

BLYNK_WRITE(VPIN_BUTTON_7) {
  toggleState_7 = param.asInt();
  digitalWrite(RelayPin7, !toggleState_7);
}

BLYNK_WRITE(VPIN_BUTTON_8) {
  toggleState_8 = param.asInt();
  digitalWrite(RelayPin8, !toggleState_8);
}

void checkBlynkStatus() { 

 bool isconnected = Blynk.connected();
 if (isconnected == false) {
   wifiFlag = 1;
   Serial.println("Blynk Not Connected");
   digitalWrite(wifiLed, LOW);
 }
 if (isconnected == true) {
   wifiFlag = 0;
   if (!fetch_blynk_state){
   Blynk.virtualWrite(VPIN_BUTTON_1, toggleState_1);
   Blynk.virtualWrite(VPIN_BUTTON_2, toggleState_2);
   Blynk.virtualWrite(VPIN_BUTTON_3, toggleState_3);
   Blynk.virtualWrite(VPIN_BUTTON_4, toggleState_4);
   Blynk.virtualWrite(VPIN_BUTTON_5, toggleState_5);
   Blynk.virtualWrite(VPIN_BUTTON_6, toggleState_6);
   Blynk.virtualWrite(VPIN_BUTTON_7, toggleState_7);
   Blynk.virtualWrite(VPIN_BUTTON_8, toggleState_8);
   }
   digitalWrite(wifiLed, HIGH);
   Serial.println("Blynk Connected");
   timer.setTimeout(1000, []() 
    {  
    digitalWrite(wifiLed, LOW);
    }
  }
}

BLYNK_CONNECTED() {
  // Request the latest state from the server
  if (fetch_blynk_state){
    Blynk.syncVirtual(VPIN_BUTTON_1);
    Blynk.syncVirtual(VPIN_BUTTON_2);
    Blynk.syncVirtual(VPIN_BUTTON_3);
    Blynk.syncVirtual(VPIN_BUTTON_4);
    Blynk.syncVirtual(VPIN_BUTTON_5);
    Blynk.syncVirtual(VPIN_BUTTON_6);
    Blynk.syncVirtual(VPIN_BUTTON_7);
    Blynk.syncVirtual(VPIN_BUTTON_8);
  }
}

void manual_control()
{
  if (digitalRead(SwitchPin1) == LOW && SwitchState_1 == LOW) {
    digitalWrite(RelayPin1, LOW);
    toggleState_1 = 1;
    SwitchState_1 = HIGH;
    Blynk.virtualWrite(VPIN_BUTTON_1, toggleState_1);
    Serial.println("Switch-1 on");
  }
  if (digitalRead(SwitchPin1) == HIGH && SwitchState_1 == HIGH) {
    digitalWrite(RelayPin1, HIGH);
    toggleState_1 = 0;
    SwitchState_1 = LOW;
    Blynk.virtualWrite(VPIN_BUTTON_1, toggleState_1);
    Serial.println("Switch-1 off");
  }
  if (digitalRead(SwitchPin2) == LOW && SwitchState_2 == LOW) {
    digitalWrite(RelayPin2, LOW);
    toggleState_2 = 1;
    SwitchState_2 = HIGH;
    Blynk.virtualWrite(VPIN_BUTTON_2, toggleState_2);
    Serial.println("Switch-2 on");
  }
  if (digitalRead(SwitchPin2) == HIGH && SwitchState_2 == HIGH) {
    digitalWrite(RelayPin2, HIGH);
    toggleState_2 = 0;
    SwitchState_2 = LOW;
    Blynk.virtualWrite(VPIN_BUTTON_2, toggleState_2);
    Serial.println("Switch-2 off");
  }
  if (digitalRead(SwitchPin3) == LOW && SwitchState_3 == LOW) {
    digitalWrite(RelayPin3, LOW);
    toggleState_3 = 1;
    SwitchState_3 = HIGH;
    Blynk.virtualWrite(VPIN_BUTTON_3, toggleState_3);
    Serial.println("Switch-3 on");
  }
  if (digitalRead(SwitchPin3) == HIGH && SwitchState_3 == HIGH) {
    digitalWrite(RelayPin3, HIGH);
    toggleState_3 = 0;
    SwitchState_3 = LOW;
    Blynk.virtualWrite(VPIN_BUTTON_3, toggleState_3);
    Serial.println("Switch-3 off");
  }
  if (digitalRead(SwitchPin4) == LOW && SwitchState_4 == LOW) {
    digitalWrite(RelayPin4, LOW);
    toggleState_4 = 1;
    SwitchState_4 = HIGH;
    Blynk.virtualWrite(VPIN_BUTTON_4, toggleState_4);
    Serial.println("Switch-4 on");
  }
  if (digitalRead(SwitchPin4) == HIGH && SwitchState_4 == HIGH) {
    digitalWrite(RelayPin4, HIGH);
    toggleState_4 = 0;
    SwitchState_4 = LOW;
    Blynk.virtualWrite(VPIN_BUTTON_4, toggleState_4);
    Serial.println("Switch-4 off");
  }
  if (digitalRead(SwitchPin5) == LOW && SwitchState_5 == LOW) {
    digitalWrite(RelayPin5, LOW);
    toggleState_5 = 1;
    SwitchState_5 = HIGH;
    Blynk.virtualWrite(VPIN_BUTTON_5, toggleState_5);
    Serial.println("Switch-5 on");
  }
  if (digitalRead(SwitchPin5) == HIGH && SwitchState_5 == HIGH) {
    digitalWrite(RelayPin5, HIGH);
    toggleState_5 = 0;
    SwitchState_5 = LOW;
    Blynk.virtualWrite(VPIN_BUTTON_5, toggleState_5);
    Serial.println("Switch-5 off");
  }
  if (digitalRead(SwitchPin6) == LOW && SwitchState_6 == LOW) {
    digitalWrite(RelayPin6, LOW);
    toggleState_6 = 1;
    SwitchState_6 = HIGH;
    Blynk.virtualWrite(VPIN_BUTTON_6, toggleState_6);
    Serial.println("Switch-6 on");
  }
  if (digitalRead(SwitchPin6) == HIGH && SwitchState_6 == HIGH) {
    digitalWrite(RelayPin6, HIGH);
    toggleState_6 = 0;
    SwitchState_6 = LOW;
    Blynk.virtualWrite(VPIN_BUTTON_6, toggleState_6);
    Serial.println("Switch-6 off");
  }
  if (digitalRead(SwitchPin7) == LOW && SwitchState_7 == LOW) {
    digitalWrite(RelayPin7, LOW);
    toggleState_7 = 1;
    SwitchState_7 = HIGH;
    Blynk.virtualWrite(VPIN_BUTTON_7, toggleState_7);
    Serial.println("Switch-7 on");
  }
  if (digitalRead(SwitchPin7) == HIGH && SwitchState_7 == HIGH) {
    digitalWrite(RelayPin7, HIGH);
    toggleState_7 = 0;
    SwitchState_7 = LOW;
    Blynk.virtualWrite(VPIN_BUTTON_7, toggleState_7);
    Serial.println("Switch-7 off");
  }
  if (digitalRead(SwitchPin8) == LOW && SwitchState_8 == LOW) {
    digitalWrite(RelayPin8, LOW);
    toggleState_8 = 1;
    SwitchState_8 = HIGH;
    Blynk.virtualWrite(VPIN_BUTTON_8, toggleState_8);
    Serial.println("Switch-8 on");
  }
  if (digitalRead(SwitchPin8) == HIGH && SwitchState_8 == HIGH) {
    digitalWrite(RelayPin8, HIGH);
    toggleState_8 = 0;
    SwitchState_8 = LOW;
    Blynk.virtualWrite(VPIN_BUTTON_8, toggleState_8);
    Serial.println("Switch-8 off");
  }
}  

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_5 = 0; digitalWrite(RelayPin5, HIGH); Blynk.virtualWrite(VPIN_BUTTON_5, toggleState_5); delay(100);
  toggleState_6 = 0; digitalWrite(RelayPin6, HIGH); Blynk.virtualWrite(VPIN_BUTTON_6, toggleState_6); delay(100);
  toggleState_7 = 0; digitalWrite(RelayPin7, HIGH); Blynk.virtualWrite(VPIN_BUTTON_7, toggleState_7); delay(100);
  toggleState_8 = 0; digitalWrite(RelayPin8, HIGH); Blynk.virtualWrite(VPIN_BUTTON_8, toggleState_8); delay(100);
}

void setup()
{
  Serial.begin(9600);

  pinMode(RelayPin1, OUTPUT);
  pinMode(RelayPin2, OUTPUT);
  pinMode(RelayPin3, OUTPUT);
  pinMode(RelayPin4, OUTPUT);
  pinMode(RelayPin5, OUTPUT);
  pinMode(RelayPin6, OUTPUT);
  pinMode(RelayPin7, OUTPUT);
  pinMode(RelayPin8, OUTPUT);

  pinMode(wifiLed, OUTPUT);

  pinMode(SwitchPin1, INPUT_PULLUP);
  pinMode(SwitchPin2, INPUT_PULLUP);
  pinMode(SwitchPin3, INPUT_PULLUP);
  pinMode(SwitchPin4, INPUT_PULLUP);
  pinMode(SwitchPin5, INPUT_PULLUP);
  pinMode(SwitchPin6, INPUT_PULLUP);
  pinMode(SwitchPin7, INPUT_PULLUP);
  pinMode(SwitchPin8, INPUT_PULLUP);

  //During Starting all Relays should TURN OFF
  digitalWrite(RelayPin1, !toggleState_1);
  digitalWrite(RelayPin2, !toggleState_2);
  digitalWrite(RelayPin3, !toggleState_3);
  digitalWrite(RelayPin4, !toggleState_4);
  digitalWrite(RelayPin5, !toggleState_5);
  digitalWrite(RelayPin6, !toggleState_6);
  digitalWrite(RelayPin7, !toggleState_7);
  digitalWrite(RelayPin8, !toggleState_8);

  digitalWrite(wifiLed, LOW);

  //Blynk.begin(auth, ssid, pass);
  WiFi.begin(ssid, pass);
  timer.setInterval(1000L, manual_control);
  timer.setInterval(2000L, checkBlynkStatus); // check if Blynk server is connected every 2 seconds
  Blynk.config(auth);
  delay(1000);
  
  if (!fetch_blynk_state){
    Blynk.virtualWrite(VPIN_BUTTON_1, toggleState_1);
    Blynk.virtualWrite(VPIN_BUTTON_2, toggleState_2);
    Blynk.virtualWrite(VPIN_BUTTON_3, toggleState_3);
    Blynk.virtualWrite(VPIN_BUTTON_4, toggleState_4);
    Blynk.virtualWrite(VPIN_BUTTON_5, toggleState_5);
    Blynk.virtualWrite(VPIN_BUTTON_6, toggleState_6);
    Blynk.virtualWrite(VPIN_BUTTON_7, toggleState_7);
    Blynk.virtualWrite(VPIN_BUTTON_8, toggleState_8);
  }
}

void loop()
{
  Blynk.run();
  timer.run();
}
Arduino: 1.8.19 (Windows Store 1.8.57.0) (Windows 10), Board: "DOIT ESP32 DEVKIT V1, 80MHz, 921600, None"





















C:\Users\kamal\Pictures\1st\Code_ESP32s_NEW_Blynk_8Relay_Switch\Code_ESP32s_NEW_Blynk_8Relay_Switch.ino: In function 'void checkBlynkStatus()':

Code_ESP32s_NEW_Blynk_8Relay_Switch:159:1: error: expected ')' before '}' token

 }

 ^

Code_ESP32s_NEW_Blynk_8Relay_Switch:161:19: error: a function-definition is not allowed here before '{' token

 BLYNK_CONNECTED() {

                   ^

Code_ESP32s_NEW_Blynk_8Relay_Switch:365:1: error: expected '}' at end of input

 }

 ^

Multiple libraries were found for "WiFi.h"

 Used: C:\Users\kamal\Documents\ArduinoData\packages\esp32\hardware\esp32\1.0.6\libraries\WiFi

 Not used: C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.57.0_x86__mdqgnx93n4wtt\libraries\WiFi

exit status 1

expected ')' before '}' token

fixed, try again.

use latest but same problem i think happen

Code_ESP32s_NEW_Blynk_8Relay_Switch:159:3: error: expected ')' before '}' token
   }
   ^
Multiple libraries were found for "WiFi.h"
 Used: C:\Users\kamal\Documents\ArduinoData\packages\esp32\hardware\esp32\1.0.6\libraries\WiFi
 Not used: C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.57.0_x86__mdqgnx93n4wtt\libraries\WiFi
Using library WiFi at version 1.0 in folder: C:\Users\kamal\Documents\ArduinoData\packages\esp32\hardware\esp32\1.0.6\libraries\WiFi 
Using library Blynk at version 1.1.0 in folder: C:\Users\kamal\Documents\Arduino\libraries\Blynk 
exit status 1
expected ')' before '}' token

I’m not home at the moment, I’m using my phone.
I will check it when I get back to home.