Everytime device reconnect to Blynk server after droped, need to restart status form begin?

Hi

When device lost connect to Blynk server (ex: lost wifi or lost power or something…), when it reconnect again to server, I want to re status of all pin like device run setup() first time and sync all status to app

I press button to OFF, and device’s led OFF, device disconnect to Blynk server, after reconnected again, all led return default status ON, but button on app still OFF, app’s led OFF

Here my sketch

#define BLYNK_PRINT Serial // Enables Serial Monitor
#include <SPI.h>
#include <Ethernet.h>
#include <BlynkSimpleEthernet.h> // This part is for Ethernet stuff

char auth[] = "xxxxxx";
int wifiPin = 2;
int modemPin = 3;
int cameraPin = 4;
int pcPin = 5;
int Mo = LOW;
int Tat = HIGH;
int wifiDefaultState = Mo    //   Mặc định điện wifi là mở
WidgetLED ledWifi(V12);
WidgetLED ledModem(V13);
WidgetLED ledCamera(V14);
WidgetLED ledPc(V15);

void setup()
{
  pinMode(wifiPin, OUTPUT);
  pinMode(modemPin, OUTPUT);
  pinMode(cameraPin, OUTPUT);
  pinMode(pcPin, OUTPUT);
  digitalWrite(wifiPin, Mo);
  digitalWrite(modemPin, Mo);
  digitalWrite(cameraPin, Mo);
  digitalWrite(pcPin, Tat);
  Serial.begin(9600);
  Blynk.begin(auth);
}

BLYNK_CONNECTED()
{
  digitalWrite(wifiPin, Mo);
  digitalWrite(modemPin, Mo);
  digitalWrite(cameraPin, Mo);
  digitalWrite(pcPin, Tat);
  Blynk.syncAll();
}

BLYNK_WRITE(V2) // Virtualpin Button cho Wifi
{
  int valueV2 = param.asInt();
  if (valueV2 == 1) {
      digitalWrite(wifiPin,Mo);
      ledWifi.on();
  }
  else{
      digitalWrite(wifiPin,Tat);
      ledWifi.off();
  }
}

BLYNK_WRITE(V22) // Virtualpin timer cho Wifi
{
  int valueV22 = param.asInt();
  if (valueV22 == 1) {
      digitalWrite(wifiPin,Tat);
      ledWifi.off();
  }
  else{
      digitalWrite(wifiPin,Mo);
      ledWifi.on();
  }
}

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

Thks

sorry, I upload my sketch

Please read http://docs.blynk.cc/#blynk-main-operations-state-syncing it describes what you need to do in both cases.

I already read carefully before ask here, I tried many time, many way but still didn’t work, I know that’s all my bad, because I new with code arduino and Blynk, so I post my sketch here, hope someone take a time to look in my sketch, find some wrong and help me fix wrong code

thks

Could you please describe in more details what “doesn’t work”? I didn’t understand from your first comment.

Thks Dmitriy for your reply, I fixed by my way, but my way not best way, anyway, I fixed my problem
My English is not good, sorry if I make you confused with my problem.

No problems. SImple rule - better description - higher chance for help. Glad you resolved issue by yourself :wink: