Problem of Switch/button state sync after power reset

i am using a ttgo t call 800 to control a light from blynk app by a switch/button. when ever power reset is done gprs conection gets established but the digital output of pin gives 0/low irrespective of the switch/buttton state in blynk. after i change the state of button in app then it is getting synced.

for example if the button state is ON/high before power reset after the power comes the digital out put of pin still 0/low . if i change the state from ON to OFF Then ON from app then the digital out put of pin goes 1/high.

so how to get it synced automatically after power reset.

here is the code

/*
    // TTGO T-Call pin definitions
#define MODEM_RST            5
#define MODEM_PWKEY          4
#define MODEM_POWER_ON       23
#define MODEM_TX             27
#define MODEM_RX             26
#define I2C_SDA              21
#define I2C_SCL              22
// Other define
#define BLYNK_PRINT Serial    
#define TINY_GSM_MODEM_SIM800

// Set serial for debug console (to the Serial Monitor, default speed 115200)
#define Serial Serial
// Hardware Serial on Mega, Leonardo, Micro
#define SerialAT Serial1

// Include
#include <TinyGsmClient.h>
#include <BlynkSimpleTinyGSM.h>
#include <Wire.h>
#include "utilities.h"

// Vars
const char apn[]  = "portalnmms";
const char user[] = "";
const char pass[] = "";
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
const char auth[] = "sw9gJoulOcFtkjKY5JsANxUF2WmOXKP_";

TinyGsm modem(SerialAT);
BlynkTimer timer;

// For testing purpose, remove if not needed
BLYNK_WRITE(V5) {
  modem.gprsDisconnect();
}


void checkGPRS()
{
  Serial.println("GPRS check running");

  if (!modem.isGprsConnected()) {
    if (!modem.gprsConnect(apn, user, pass)) {
      delay(10000);
      return;
    }
  }
}


void setup()
{
  // Set console baud rate
  Serial.begin(115200);
  delay(10);

  // Keep power when running from battery
  Wire.begin(I2C_SDA, I2C_SCL);
  bool   isOk = setPowerBoostKeepOn(1);
  Serial.println(String("IP5306 KeepOn ") + (isOk ? "OK" : "FAIL"));

  // Set-up modem reset, enable, power pins
  pinMode(MODEM_PWKEY, OUTPUT);
  pinMode(MODEM_RST, OUTPUT);
  pinMode(MODEM_POWER_ON, OUTPUT);

  digitalWrite(MODEM_PWKEY, LOW);
  digitalWrite(MODEM_RST, HIGH);
  digitalWrite(MODEM_POWER_ON, HIGH);

  // Set GSM module baud rate and UART pins
  SerialAT.begin(115200, SERIAL_8N1, MODEM_RX, MODEM_TX);
  delay(3000);

  Blynk.begin(auth, modem, apn, user, pass);
  
  // For GPRS reconnect
  timer.setInterval(10000L, checkGPRS);
  
}


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

*/

Blynk has a special callback function called BLYNK_CONNECTED which is automatically executed whenever the device connects or re-connects to the Blynk server.

There are two commands that can be called within the BLYNK_CONNECTED function to cause the device to receive updated widget state data from the server. These are:

Blynk.syncAll()

and

Blynk.syncVirtual(vPin)

As you aren’t using virtual pins (although I’d suggest that you should) the you’ll need to use the Blynk.syncAll() command which should do what you want (I say ‘should’ because I never use digital pins for widgets, so I don’t have first hand experience of this).

More details in this section of the documentation:

Pete.

Thanks problem solved.

1 Like