Hello there, i am using the esp 8266 and working great but i have a problem : when the internet wifi signal is lost for seconds my indicators led widget will also get lost .how can i refresh these virtual pins every 5 minutes any help please.
Using Blynk.syncAll() should restore last settings after disconnect.
http://docs.blynk.cc/#blynk-firmware-virtual-pins-control-blynksyncall
@Malek_Alam_Edine Also, please do NOT spam multiple threads with same question… as you did in a another (unrelated) thread. Doing so is good way to get all your questions ignored.
hello fellows,
im using wemos d1 wifi shield to controlling 3 outputs , but the real case problem is that i have 6 led widgets set them up as virtual pins.
i used them as indicators to ensure and the outputs are either on or off(1st & 2nd widgets (on/off) ,(3th &4th widgets (on/off) ,(5th & 6th widgets (on/off) ,
So when the network resets(goes offline then gets back online) the shield will reconnect successfully but the indicators will get lost . however , i used reconnectblynk &sync.all function but not working . or will i use physical buttom example:
Here’s my code:
#define BLYNK_PRINT Serial // Comment this out to disable prints and save space
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SPI.h>
#include <SimpleTimer.h>
char auth[] = "XXXXXXXXXXXXXXX";
char ssid[] = "FFDFFDl";
char pass[] = "";
const int btnPin = D6;
const int btnPin1 = D7;
const int btnPin2 = D3;
WidgetLED led5(V5);
WidgetLED led3(V3);
WidgetLED led4(V4);
WidgetLED led6(V6);
WidgetLED led7(V7);
WidgetLED led8(V8);
SimpleTimer timer;
boolean btnState = false;
boolean btnState1 = false;
boolean btnState2 = false;
bool isFirstConnect = true;
BLYNK_CONNECTED() {
if (isFirstConnect) {
// Request Blynk server to re-send latest values for all pins
Blynk.syncVirtual(V3,V4,V5,V6,V7,V8);
isFirstConnect = false;
}
int value = millis() / 1000;
Blynk.virtualWrite(V3, value);
int kousa = millis() / 1000;
Blynk.virtualWrite(V6, kousa);
int lahme = millis() / 1000;
Blynk.virtualWrite(V4, lahme);
int bayd = millis() / 1000;
Blynk.virtualWrite(V7, bayd);
int snawbar = millis() / 1000;
Blynk.virtualWrite(V5, snawbar);
int KOUSA1 = millis() / 1000;
Blynk.virtualWrite(V8, KOUSA1);}
void buttonLedWidget()
{
// Read button
boolean isPressed = (digitalRead(btnPin) == LOW);
Serial.begin(9600);
// If state has changed...
if (isPressed != btnState) {
if (isPressed) {
led3.on();
led6.off();
} else {
led6.on();
led3.off();
}
btnState = isPressed;
}
}
void buttonLedWidget1()
{
// Read button
boolean isPressed = (digitalRead(btnPin1) == LOW);
Serial.begin(9600);
if (isPressed != btnState1) {
if (isPressed) {
led4.on();
led7.off();
} else {
led7.on();
led4.off();
}
btnState1 = isPressed;
}
}
void buttonLedWidget2()
{
boolean isPressed = (digitalRead(btnPin2) == HIGH);
Serial.begin(9600);
if (isPressed != btnState2) {
if (isPressed) {
led5.on();
led8.off();
} else {
led8.on();
led5.off();
}
btnState2 = isPressed;
}
}
void setup()
{
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
pinMode(btnPin, INPUT_PULLUP);
pinMode(btnPin1, INPUT_PULLUP);
pinMode(btnPin2, INPUT_PULLUP);
timer.setInterval(500L, buttonLedWidget);
timer.setInterval(500L, buttonLedWidget1);
timer.setInterval(500L, buttonLedWidget2);
}
void loop(){
timer.run();
Blynk.run();
}
As I asked before re: spamming with questions in multiple posts… the same goes for creating multiples topics for same issue.
I have merged both topics together and edited your title to closer reflect your issue.
I also edited your code format in your post to make it a bit more readable. Please look back at it to see how it is done for future posting.
I don’t have any ESP devices, so haven’t really needed to use sync, but have you tried without the isFirstConnect…
BLYNK_CONNECTED() {
// Request Blynk server to re-send latest values for these pins
Blynk.syncVirtual(V3,V4,V5,V6,V7,V8);
}