[SOLVED] Timer widget fails to trigger every so often with ESP32

I see you have a lot of 1 second delays in many of your BLYNK_WRITE() loops… that WILL cause many issues with disconnections and reliability, etc. (even on an ESP32, which I believe has less picky WiFi timing issues then the 8266… but Blynk still has it’s own timing requirements).

Avoid using delays for more than a few ms in critical needs (like Ultrasonic sensors, etc)… use BlynkTimer routines instead. A bit more coding and fancy placement of functions, but it is NON-Blocking.

http://docs.blynk.cc/#blynk-firmware-blynktimer

@taitrt here is what you need - http://docs.blynk.cc/#blynk-main-operations-state-syncing

@Dmitriy While you are bringing that method up… is there a way to have Blynk.syncAll() do so with small (adjustable?) delays in between each vPin? I have tried that command as is, but since I have so much to sync, it instantly floods the system.

Nope.

How is that? HArdware drops connection?

Essentially… massive Buffer Overflow errors and system never recovers until physical reset.

Since I switched to ESP from USB, I have had random disconnections (possibly WiFi congestion at home :wink: ). I have managed to code recovery routines that work quite nicely… but I can only manually synchronise a few key vPins at a time, since syncAll just makes it worse.

1 Like

I see… I’ll check what we can do here.

2 Likes

Thank you.

1 Like

@taitrt Here is a blocking-free timer example for one of your BLYNK_WRITE() routines

//Blynk Writes
BLYNK_WRITE(V20)
{
  int pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable
  if (pinValue == 1)
  {
    if (! client.publish("Commands", "Pool_Light"))
    {
      Blynk.virtualWrite(V25, "Command Failed");
      timer.setTimeout(1000L, ClearMsg);  // Run Clear Message routine in 1 second
    }
    else
    {
      Blynk.virtualWrite(V25, "Pool Light Sent");
      timer.setTimeout(1000L, ClearMsg);  // Run Clear Message routine in 1 second
    }
  }
}

void ClearMsg()
{
  Blynk.virtualWrite(V25, " ");
}

For some reason, that actually doesn’t correct the problem for me. My project actually has a Blynk.syncAll() button for testing purposes. Whenever I press it after one of my timers doesn’t trigger it syncs, but it doesn’t sync the correct state. For instance, lets say my timer is 6pm HIGH 10pm LOW, at 8pm if I use Blynk.syncAll() after missing a timer trigger it will send LOW again, instead of sending HIGH as it should. Does this indicate that the problem is actually between my phone and the blynk server, rather than my ESP?

Yeah, I know about blynktimer. The only reason those delays are there is because they actually shouldn’t ever be called. Those only happen if for some reason the publish to my MQTT server fails, which should basically never occur.

Thanks for the non-blocking example though. I’ll probably just change it out because it’s good practice.

No. Timers are handled on the server. Seems like you did SYNC after 10PM. Is that correct?

No I did the sync at 8pm, meaning that it was in the time that the trigger should have sent HIGH, but it sent LOW instead.

I will make sure to document it better next time it happens and do more testing.

@Dmitriy It appears that Blynk.syncAll() does not sync timers at all. When I run the command all of my buttons that are configured as switches sync, but my timers do not.

Today the “Bedtime” timer failed to turn off:

BLYNK_WRITE(V19)
{
  int pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable
  if (pinValue == 1)
  {
    scarlettAlarm = 1;
    bedtimeLED.on();
  }
  if (pinValue == 0)
  {
    scarlettAlarm = 0;
    bedtimeLED.off();
  }
} 

This timer should have turned off the bedtimeLED at 4am, but it did not and using syncAll() doesn’t result in any change in the LED even though the rest of the switches will update.

More testing:

I have a button set up like this:

BLYNK_WRITE(V11)
{
  int pinValue = param.asInt();
  if (pinValue == 1)
  {
    Blynk.syncAll();
    Blynk.syncVirtual(V19);
    terminal.println("Updated");
    terminal.flush();
  }
}

Pressing it does not update the timer vpin, is this expected functionality?

@Dmitriy is there a chance of getting timer vpins added to the sync functions in the future?

@taitrt timers already support syncs.

Mine do not respond to Blynk.syncvirtual or Blynk.syncall

What does debug shows?

@Dmitriy

Debug shows no vw on vpin5 (the timer) when using sync:

[18] Connecting to RobsTV
[2652] Connected to WiFi
[2652] IP: 192.168.1.93
[2652] 
    ___  __          __
   / _ )/ /_ _____  / /__
  / _  / / // / _ \/  '_/
 /____/_/\_, /_//_/_/\_\
        /___/ v0.4.8 on Arduino

[5001] Connecting to blynk-cloud.com:8442
[5061] <[02|00|01|00] 5417eefaa3204b3e814d6edde7d9a6fd
[5112] >[00|00|01|00|C8]
[5112] Ready (ping: 50ms).
[5112] <[11|00|02|00]Hver[00]0.4.8[00]h-beat[00]10[00]buff-in[00]1024[00]dev[00]Arduino[00]build[00]Jul 28 2017 13:38:59[00]
[5178] >[00|00|02|00|C8]
[15118] <[06|00|03|00|00]
[15169] >[00|00|03|00|C8]
[15401] >[14]k[FD|00|06]
[15402] >vw[00]2[00]1
[15402] <[10]k[FD|00|00]
[15446] >[14]k[FD|00|06]
[15447] >vw[00]0[00]0
[15448] >[14]k[FD|00|06]
[15448] >vw[00]1[00]0
[15449] >[14]k[FD|00|06]
[15450] >vw[00]2[00]1
[15450] <[10]k[FD|00|00]
[15451] >[14]k[FD|00|01]
[15452] >1
[15454] >[14]k[FD|00|06]
[15456] >vw[00]4[00]0
[15458] >[14]k[FD|00|06]
[15460] >vw[00]3[00]0
[15462] <[14]k[FD|00|06]vw[00]4[00]0
[15506] >[14]k[FD|00|06]
[15507] >vw[00]0[00]0
[15507] >[14]k[FD|00|06]
[15508] >vw[00]1[00]0
[15509] >[14]k[FD|00|06]
[15510] >vw[00]2[00]1
[15510] <[10]k[FD|00|00]
[15511] >[14]k[FD|00|01]
[15512] >1
[15514] >[14]k[FD|00|06]
[15516] >vw[00]4[00]0
[15518] >[14]k[FD|00|06]
[15520] >vw[00]3[00]0
[15522] <[14]k[FD|00|06]vw[00]4[00]0
[15526] >[14]R[BC|00|06]
[15528] >vw[00]2[00]0
[15638] >[14]k[FD|00|06]
[15639] >vw[00]0[00]0
[15640] >[14]k[FD|00|06]
[15640] >vw[00]1[00]0
[15641] >[14]k[FD|00|06]
[15642] >vw[00]2[00]0
[15642] >[14]k[FD|00|01]
[15643] >1
[15644] >[14]k[FD|00|06]
[15646] >vw[00]4[00]0
[15648] >[14]k[FD|00|06]
[15650] >vw[00]3[00]0
[15652] <[14]k[FD|00|06]vw[00]4[00]0
[25652] <[06|00|04|00|00]
[25716] >[00|00|04|00|C8]
[35653] <[06|00|05|00|00]
[35716] >[00|00|05|00|C8]

This is the code I’ve got setup for the test:

#define BLYNK_DEBUG
#define BLYNK_PRINT Serial


#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "xx";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "xx";
char pass[] = "xx";

WidgetLED testLED(V4);

BLYNK_WRITE(V2)  //sync
{
  int pinValue = param.asInt(); 
  if (pinValue == 1)
  {
    Blynk.syncAll();
  }
}
BLYNK_WRITE(V3) //LED toggle
{
  int pinValue = param.asInt(); 
  if (pinValue == 1)
  {
    testLED.on();
  }
  if (pinValue == 0)
  {
    testLED.off();
  }
}
BLYNK_WRITE(V5) //timer
{
  int pinValue = param.asInt(); 
  if (pinValue == 1)
  {
    testLED.on();
    Blynk.virtualWrite(V3, 1);
  }
  if (pinValue == 0)
  {
    testLED.off();
    Blynk.virtualWrite(V3, 0);
  }
}

void setup()
{
  // Debug console
  Serial.begin(115200);

  Blynk.begin(auth, ssid, pass);
  
}

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

When changing from Blynk.syncAll() to Blynk.syncVirtual(V5) it spits out this in the debug:

[204945] >[14],[F5|00|06]
[204946] >vw[00]2[00]1
[204946] <[10],[F5|00|04]vr[00]5
[205006] >[14],[F5|00|01]
[205006] >1
[205054] >[14|0D]@[00|06]
[205055] >vw[00]2[00]0

Which is interesting. I assume vr[00]5 means it is reading the vpin and it knows it’s a 1, how do I capitalize on that to make my BLYNK_WRITE(V5) trigger?

@Gunner @Costas

Since this thread is really not about the timer failing to trigger anymore, and more about using Blynk.sync() functions with the timer, should I make a new thread? I’d really love to get this resolved.