Can't do Blynk.syncAll();

Hello all… im working with Arduino Uno and Ethernet for my Iot Projects…
i have problem with state sync after the arduino loss power source
i do Blynk.syncAll( )but it didn’t work
This is my skecth

bool isFirstConnect = true;

BLYNK_CONNECTED() {
  if (isFirstConnect) {
    // Request Blynk server to re-send latest values for all pins
    Blynk.syncAll();

    // You can also update individual virtual pins like this:
    //Blynk.syncVirtual(V0, V1, V4);

    isFirstConnect = false;
  }
}

Can someone help me ? :grin:

how can you know it “didn’t work”?

i have turned on a led from blynk… and then when the arduino turned off and on again the led turned off but my button widget state is on…

can you post ALL of your sketch?

#define BLYNK_PRINT Serial

#include <SPI.h>
#include <Ethernet.h>
#include <BlynkSimpleEthernet.h>
#include <SimpleTimer.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "58d599d309e349b49e70349f5ab23e85";
SimpleTimer timer;

const int in1 = 2;
const int in2 = 3;

const int ls = 6;

const int re7 = 7;

const int led1 = 22;
const int led2 = 24;
const int led3 = 26;
const int led4 = 28;
const int led5 = 30;
const int led6 = 32;
const int led7 = 34;
const int led8 = 36;
const int led9 = 38;
const int led10 = 40;

const int led1in = 23;
const int led2in = 25;
const int led3in = 27;
const int led4in = 29;
const int led5in = 31;
const int led6in = 33;
const int led7in = 35;
const int led8in = 37;
const int led9in = 39;
const int led10in = 41;

int v1update = 0;
int lastv1update = 0;

int lsState = 0;
int lastlsState = 0;

int lastled1State = 0;
int lastled2State = 0;
int lastled3State = 0;
int lastled4State = 0;
int lastled5State = 0;
int lastled6State = 0;
int lastled7State = 0;
int lastled8State = 0;
int lastled9State = 0;
int lastled10State = 0;

int led1State = 0;
int led2State = 0;
int led3State = 0;
int led4State = 0;
int led5State = 0;
int led6State = 0;
int led7State = 0;
int led8State = 0;
int led9State = 0;
int led10State = 0;

int gatetimer = 0;
int counter = 0;
int notifgerbang = 0;
bool isFirstConnect = true;

BLYNK_CONNECTED() {
  if (isFirstConnect) {
    // Request Blynk server to re-send latest values for all pins
    Blynk.syncAll();

    // You can also update individual virtual pins like this:
    //Blynk.syncVirtual(V0, V1, V4);

    isFirstConnect = false;
  }
}

void setup()
{
  // Debug console
  pinMode(in1, OUTPUT);
  pinMode(in2, OUTPUT);
  pinMode(ls, INPUT);
  pinMode(re7, OUTPUT);
  
  pinMode(led1, OUTPUT);
  pinMode(led2, OUTPUT);
  pinMode(led3, OUTPUT);
  pinMode(led4, OUTPUT);
  pinMode(led5, OUTPUT);
  pinMode(led6, OUTPUT);
  pinMode(led7, OUTPUT);
  pinMode(led8, OUTPUT);
  pinMode(led9, OUTPUT);
  pinMode(led10, OUTPUT);
  
  pinMode(led1in, INPUT);
  pinMode(led2in, INPUT);
  pinMode(led3in, INPUT);
  pinMode(led4in, INPUT);
  pinMode(led5in, INPUT);
  pinMode(led6in, INPUT);
  pinMode(led7in, INPUT);
  pinMode(led8in, INPUT);
  pinMode(led9in, INPUT);
  pinMode(led10in, INPUT);
  
  digitalWrite(re7, HIGH);
  
  Serial.begin(9600);

  Blynk.begin(auth);
  
  timer.setInterval(100L, sendls);
  timer.setInterval(500L, button);
  timer.setInterval(1000L, gerbang);
}

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

needs to go in setup - because setup runs ONCE at the startup…

bool isFirstConnect = true;

void setup()
{
    if (isFirstConnect) {
    Blynk.syncAll();
    isFirstConnect = false;
  }

still didn’t work

have you posted your ENTIRE sketch?

/*************************************************************
  Blynk is a platform with iOS and Android apps to control
  Arduino, Raspberry Pi and the likes over the Internet.
  You can easily build graphic interfaces for all your
  projects by simply dragging and dropping widgets.

    Downloads, docs, tutorials: http://www.blynk.cc
    Blynk community:            http://community.blynk.cc
    Social networks:            http://www.fb.com/blynkapp
                                http://twitter.com/blynk_app

  Blynk library is licensed under MIT license
  This example code is in public domain.

 *************************************************************
  You can use this sketch as a debug tool that prints all incoming values
  sent by a widget connected to a Virtual Pin 1 in the Blynk App.

  App project setup:
    Slider widget (0...100) on V1
 *************************************************************/

/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial

#include <SPI.h>
#include <Ethernet.h>
#include <BlynkSimpleEthernet.h>
#include <SimpleTimer.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "58d599d309e349b49e70349f5ab23e85";
SimpleTimer timer;

const int in1 = 2;
const int in2 = 3;

const int ls = 6;

const int re7 = 7;

const int led1 = 22;
const int led2 = 24;
const int led3 = 26;
const int led4 = 28;
const int led5 = 30;
const int led6 = 32;
const int led7 = 34;
const int led8 = 36;
const int led9 = 38;
const int led10 = 40;

const int led1in = 23;
const int led2in = 25;
const int led3in = 27;
const int led4in = 29;
const int led5in = 31;
const int led6in = 33;
const int led7in = 35;
const int led8in = 37;
const int led9in = 39;
const int led10in = 41;

int v1update = 0;
int lastv1update = 0;

int lsState = 0;
int lastlsState = 0;

int lastled1State = 0;
int lastled2State = 0;
int lastled3State = 0;
int lastled4State = 0;
int lastled5State = 0;
int lastled6State = 0;
int lastled7State = 0;
int lastled8State = 0;
int lastled9State = 0;
int lastled10State = 0;

int led1State = 0;
int led2State = 0;
int led3State = 0;
int led4State = 0;
int led5State = 0;
int led6State = 0;
int led7State = 0;
int led8State = 0;
int led9State = 0;
int led10State = 0;

int gatetimer = 0;
int counter = 0;
int notifgerbang = 0;
bool isFirstConnect = true;

void setup()
{
    if (isFirstConnect) {
    Blynk.syncAll();
    isFirstConnect = false;
  }
  // Debug console
  pinMode(in1, OUTPUT);
  pinMode(in2, OUTPUT);
  pinMode(ls, INPUT);
  pinMode(re7, OUTPUT);
  
  pinMode(led1, OUTPUT);
  pinMode(led2, OUTPUT);
  pinMode(led3, OUTPUT);
  pinMode(led4, OUTPUT);
  pinMode(led5, OUTPUT);
  pinMode(led6, OUTPUT);
  pinMode(led7, OUTPUT);
  pinMode(led8, OUTPUT);
  pinMode(led9, OUTPUT);
  pinMode(led10, OUTPUT);
  
  pinMode(led1in, INPUT);
  pinMode(led2in, INPUT);
  pinMode(led3in, INPUT);
  pinMode(led4in, INPUT);
  pinMode(led5in, INPUT);
  pinMode(led6in, INPUT);
  pinMode(led7in, INPUT);
  pinMode(led8in, INPUT);
  pinMode(led9in, INPUT);
  pinMode(led10in, INPUT);
  
  digitalWrite(re7, HIGH);
  
  Serial.begin(9600);

  Blynk.begin(auth);
  
  timer.setInterval(100L, sendls);
  timer.setInterval(500L, button);
  timer.setInterval(1000L, gerbang);
}

void loop()
{
  Blynk.run();
  timer.run();
}
BLYNK_WRITE(V1)
{
  int pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable
  // You can also use:
  // String i = param.asStr();
  // double d = param.asDouble();
  if (pinValue == 1) { 
    v1update = 1;
  }
  if (pinValue == 0) {
    v1update = 0;
  }
  
  if (v1update != lastv1update) {
    counter = 0;
    if (v1update == 1) {
    digitalWrite(in1, HIGH);
    digitalWrite(in2, LOW);
  }
  if (v1update == 0) {
    digitalWrite(in1, LOW);
    digitalWrite(in2, HIGH);
    gatetimer = 0;
    notifgerbang = 0;
  }
}

lastv1update = v1update;

}

BLYNK_WRITE(V3) 
{
  int pinValue3 = param.asInt();
  if (pinValue3 == HIGH) {
      digitalWrite (led1, HIGH);
  }else{
    digitalWrite (led1, LOW);
  }
}

BLYNK_WRITE(V4)
{
  int pinValue4 = param.asInt();
   if (pinValue4 == HIGH) {
      digitalWrite (led2, HIGH);
  }else{
    digitalWrite (led2, LOW);
  }
}

BLYNK_WRITE(V5)
{
  int pinValue5 = param.asInt();
  if (pinValue5 == HIGH) {
      digitalWrite (led3, HIGH);
  }else{
    digitalWrite (led3, LOW);
  }
}

BLYNK_WRITE(V6)
{
  int pinValue6 = param.asInt();
  if (pinValue6 == HIGH) {
      digitalWrite (led4, HIGH);
  }else{
    digitalWrite (led4, LOW);
  }
}

BLYNK_WRITE(V7)
{
  int pinValue7 = param.asInt();
  if (pinValue7 == HIGH) {
      digitalWrite (led5, HIGH);
  }else{
    digitalWrite (led5, LOW);
  }
}

BLYNK_WRITE(V8)
{
  int pinValue8 = param.asInt();
  if (pinValue8 == HIGH) {
      digitalWrite (led6, HIGH);
  }else{
    digitalWrite (led6, LOW);
  }
}

BLYNK_WRITE(V9)
{
  int pinValue9 = param.asInt();
  if (pinValue9 == HIGH) {
      digitalWrite (led7, HIGH);
  }else{
    digitalWrite (led7, LOW);
  }
}

BLYNK_WRITE(V10)
{
  int pinValue10 = param.asInt();
  if (pinValue10 == HIGH) {
      digitalWrite (led8, HIGH);
  }else{
    digitalWrite (led8, LOW);
  }
}

BLYNK_WRITE(V11)
{
  int pinValue11 = param.asInt();
  if (pinValue11 == HIGH) {
      digitalWrite (led9, HIGH);
  }else{
    digitalWrite (led9, LOW);
  }
}

BLYNK_WRITE(V12)
{
  int pinValue12 = param.asInt();
  if (pinValue12 == HIGH) {
      digitalWrite (led10, HIGH);
  }else{
    digitalWrite (led10, LOW);
  }
}

BLYNK_WRITE(V14)
{
  int pinValue14 = param.asInt();
  if (pinValue14 == HIGH) {
  Blynk.virtualWrite(V3, LOW);
  Blynk.virtualWrite(V4, LOW);
  Blynk.virtualWrite(V5, LOW);
  Blynk.virtualWrite(V6, LOW);
  Blynk.virtualWrite(V7, LOW);
  Blynk.virtualWrite(V8, LOW);
  Blynk.virtualWrite(V9, LOW);
  Blynk.virtualWrite(V10, LOW);
  Blynk.virtualWrite(V11, LOW);
  Blynk.virtualWrite(V12, LOW);
  
  digitalWrite(led1, LOW);
  digitalWrite(led2, LOW);
  digitalWrite(led3, LOW);
  digitalWrite(led4, LOW);
  digitalWrite(led5, LOW);
  digitalWrite(led6, LOW);
  digitalWrite(led7, LOW);
  digitalWrite(led8, LOW);
  digitalWrite(led9, LOW);
  digitalWrite(led10, LOW);
  }
}
void sendls ()
{
 lsState = digitalRead(ls);
  if (lsState != lastlsState) {
  if (lsState == HIGH) {
    counter++;
  }
  }
    
if (counter >= 1) {  
    digitalWrite(re7, LOW);
  }else{
    digitalWrite(re7, HIGH);
  }
  
  lastlsState = lsState;
  
}

where do you do that in the sketch?

void button()
{
  led1State = digitalRead(led1in);
  led2State = digitalRead(led2in);
  led3State = digitalRead(led3in);
  led4State = digitalRead(led4in);
  led5State = digitalRead(led5in);
  led6State = digitalRead(led6in);
  led7State = digitalRead(led7in);
  led8State = digitalRead(led8in);
  led9State = digitalRead(led9in);
  led10State = digitalRead(led10in);
  
  if (led1State != lastled1State) {
    
  if (led1State == HIGH) {
  Blynk.virtualWrite(V3, HIGH);
  }else{
     Blynk.virtualWrite(V3, LOW);
  }
  }
  
  lastled1State = led1State;
  
  if (led2State != lastled2State) {
  
if (led2State == HIGH){
     Blynk.virtualWrite(V4, HIGH);
}else{
  Blynk.virtualWrite(V4, LOW);
  }
  }
  
  lastled2State = led2State;

if (led3State != lastled3State) {
if (led3State == HIGH){
     Blynk.virtualWrite(V5, HIGH);
}else{
  Blynk.virtualWrite(V5, LOW);
}
}

lastled3State = led3State;

if (led4State != lastled4State) {
if (led4State == HIGH){
     Blynk.virtualWrite(V6, HIGH);
}else{
  Blynk.virtualWrite(V6, LOW);
}
}
lastled4State = led4State;

if (led5State != lastled5State) {
if (led5State == HIGH){
     Blynk.virtualWrite(V7, HIGH);
}else{
  Blynk.virtualWrite(V7, LOW);
}
}

lastled5State = led5State;

if (led6State != lastled6State) {
if (led6State == HIGH){
     Blynk.virtualWrite(V8, HIGH);
}else{
  Blynk.virtualWrite(V8, LOW);
}
}

lastled6State = led6State;

if (led7State != lastled7State) {
if (led7State == HIGH){
     Blynk.virtualWrite(V9, HIGH);
}else{
  Blynk.virtualWrite(V9, LOW);
}
}

lastled7State = led7State;

if (led8State != lastled8State) {
if (led8State == HIGH){
     Blynk.virtualWrite(V10, HIGH);
}else{
  Blynk.virtualWrite(V10, LOW);
}
}

lastled8State = led8State;

if (led9State != lastled9State) {
if (led9State == HIGH){
     Blynk.virtualWrite(V11, HIGH);
}else{
  Blynk.virtualWrite(V11, LOW);
}
}

lastled9State  = led9State;

if (led10State != lastled10State) {
if (led10State == HIGH){
     Blynk.virtualWrite(V12, HIGH);
}else{
  Blynk.virtualWrite(V12, LOW);
}
}

lastled10State = led10State;

}
void gerbang()
{
  if ((gatetimer <= 16) && (v1update == 1) && (counter >=  1)) {
    gatetimer = gatetimer + 1;
    Serial.println(gatetimer);
  }
  
  if ((gatetimer == 15) && (v1update == 1)) {
  Serial.println ("gerbang telah terbuka selama 10detik");
  Blynk.notify("gerbang telah terbuka selama 10detik");
  notifgerbang = 1;
  }
}

yeah, sorry, I’m 5 beers in, I have to tap out for this one… sorry…

good luck :slight_smile:

:smile:
one minute of silence for my projects
:smile:

you’ll get there… don’t stress :wink:

You need to have corresponding widgets. Or change state via Virtual pins in that case it will work. Otherwise server don’t know that you changed any state.

it finaly work… after first connect it do “the last state” of the led… but reset rapidly after it… what’s wrong

i do it all from virtual pin