Timer widget will not sync - formerly: Some help with (reading vPin state if device was offline at state change)

I’m trying to use the timer widget. I was able to use it normally and trigger at the right time , but how can i sync a virtual pin on the microcontroller? (read the status of a virtual pin from the app to the miccrocontroller. How can I read a virtual pin on a specific moment?

I had a look on :

…and as far as i understand, the value is stored online from the hardware using:
Blynk.virtualWrite(V1, val);

But how can I store a value on the server from the app if the microcontroller was off at the time of a change of a virtual pin value from the app.
but

With Blynk.syncVirtual(vPin)

I’m using:
/*************************************************************

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


#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

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

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


BlynkTimer timer;
int timetoheat;

// This function will run every time Blynk connection is established
BLYNK_CONNECTED() {
  //get data stored in virtual pin V0 from server
  Blynk.syncVirtual(V12);
}

// restoring counter from server


BLYNK_WRITE(V12)
{
  //restoring int value
  timetoheat = param.asInt();
  Serial.print("sync value=");
  Serial.println(timetoheat);
  Serial.println();
  
}

void valuefromserver() {
  Serial.print("valuefromserver=");
  Serial.println(timetoheat);
  Serial.println();   
  
  //storing int in V0 pin on server
  //Blynk.virtualWrite(V12, rea);
}

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

  Blynk.begin(auth, ssid, pass);
  // You can also specify server:
  //Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 8442);
  //Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8442);

  timer.setInterval(4000L, valuefromserver);
}

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

timetoheat gets the value from the server if its online when the start event is triggered.

but, after it gets the value and i restart the mcu, tempset gets back to 0 again.

Hello!
I’m working on a thermostat and I’m looking into designing a timer feature using the start/stop timer widget. By now, I could not manage to make it store the value on the server for this widget. I made it for other values but not for the timer.

Then I found this topic:

As far as I can understand, the value is stored on to the server only if its sent by the mcu using Blynk.virtualWrite(Vx, data),.

The thing is that the timer is sending the message for start / stop only once, at the programmed time, that’s it. If the mcu is of on that time, that’s it, the event it’s not triggered on the mcu. Maybe some potential danger for ending the timer. The task might never end.

Also, if i set the timer to start before the actual time and end in the future, it wont be triggered before the next day.

If is there any way we can send a value to/of a virtual pin and keep it stored into the server even if the mcu was off at that time and it did not received, keep that value till the mcu is connected to the server and then get the value on the next successfull connection.

If it is not possible to keep that value on to the server before being received by the mcu, I think it would be usefull to be able to send the message periodically from the app/widget. Or until the value is successfully received by the mcu.

This is already a well documented feature, as well as already discussed throughout this forum :wink: Blynk.syncAll() & Blynk.syncVirtual(vPin)

i don’t think you even tried to understand what i wrote there. I am trying to push the data from the app to the server first. Refresh the data periodically from the app to the mcu.

i tried this:

It did not stored the data at all.

I did read your multi pronged post referencing a few issues it seems.

And AS PER your specific question that I answered, I am unsure if YOU understood the answer… the server stores EVERY vPin content that the App or MCU sends back and forth, and the App will read it as frequently as it is either set in the widget or send by the MCU.

If the MCU was offline, then as it boots, or as you place it in code, you can retrieve whatever current vPin data there is, via the commands I directed you to.

This has been a topic that has been discussed repeatedly throughout this forum… which is one reason the Welcome Topic clearly states reading the Documentation and Searching this forum before asking questions is highly recommended.

PS posting duplicate topics on similar issues is not recommended… so I am merging your topics.

NO, YOU did NOT read my messages CAREFULLY.

Any, or probably any button works fine and it gets stored on the server as expected, even if the mcu is off, but for the timer widget is NOT. It does not get stored into the server, not even with the mcu online at the time of change. Do some tests by yourself with a button in the app then with a timer widget, each connected to the same Vpin.(same code on mcu). You will finally see the problem. Otherwise there is a bug somewere and it needs to get into someone attention.

Also, there was one more feature/issue you ignored from my post. Now it only sends the message at the programmed time without getting memorised, if you set the time for the past but you are still in between the start and end time, it does not get triggered.

I really love the app and the whole ideea of the app and I bought the biggest package just to help development a bit, even if i only use few widgets.Then i tried to bring some ideas wich you classified all of them as “some help with” straight away and ignored.

Thank you for your help.I’m ending this. You are just stubborn in classifing the topics rather than just helping people and building a better app.

You need the Time Input widget and search for our code EziScheduler.

At risk of taking all my personal time to dissect your every word :wink: … I have determined that despite your (initial) title and majority of questions… you are not really asking “how to”… but apparently, and without real clarification, reporting the tested?? results of a bug.

So I will do all that for you :stuck_out_tongue: (PS, I just volunteer here… not obligated)

@Dmitriy

I have tested and concluded that while using the Timer Widget, It will activate (HIGH) and deactivate (LOW) a virtual pin, on time.

However, if while in-between activation / deactivation, the MCU is rebooted and a sync command for that vPin is called… DEBUG shows the call, but the associated function on the MCU is not actually called.

I even added in a “manual” sync command (triggered by a button) and it also shows as sent in debug, but still no function call.

I previously did this testing in my larger testbench project, with other sync commands present, and determined that they DID work as expected… just not the Timer one.

Here is a dedicated test with three Widgets… Timer on V0, Display on V1 and Button on V2

/*  Three Widgets... Timer on V0, Display on V1 and Button on V2  */

#define BLYNK_DEBUG   // Advanced diagnostic data... also drasticly slows entire sketch
#define BLYNK_PRINT Serial // This prints to Serial Monitor
#include <ESP8266_Lib.h>  // ESP-01 Link
#include <BlynkSimpleShieldEsp8266.h>  // ESP-01 Link
ESP8266 wifi(&Serial1);  // Pins 18 & 19 on MEGA - For ESP-01 link
char auth[] = "e49d1adeb5xxxxx12f964c3532";  // Blynk App Authorization Code.
char ssid[] = "GunnersZone";
char pass[] = "xxxxx";
char server[] = "xxxxx";

void setup() {
  pinMode(6, OUTPUT);  // For LED to test timer
  Serial.begin(115200);  // BLYNK_PRINT data - For Serial Monitor
  Serial1.begin(115200);  // Set baud rate - For ESP-01 link

  Blynk.begin(auth, wifi, ssid, pass, server, 8442);  // Connect to Blynk - ESP-01 to Local Server.

  Serial.println("Boot Triggering V64 Sync (Timer test)");  // Should have read as V0... remnant vPin from prior test ;)
  Blynk.syncVirtual(V0);  // Boot Sync of Timer Function
}

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

BLYNK_WRITE(V0) { // Timer Function
  Blynk.virtualWrite(V1, param.asInt());
  Serial.print("Timer vPin State is: ");
  Serial.println(param.asInt());
  digitalWrite(6, param.asInt());

}

BLYNK_WRITE(V2) { // Manual Sync of Timer Function
  if (param.asInt() == 1) {
    Serial.println("Manualy Triggering V0 Sync (Timer Test)");
    Blynk.syncVirtual(V0);
  }
}

Serial Monitor output.

[0] 
    ___  __          __
   / _ )/ /_ _____  / /__
  / _  / / // / _ \/  '_/
 /____/_/\_, /_//_/_/\_\
        /___/ v0.5.0 on Arduino Mega

[505] Connecting to GunnersZone
[3566] AT version:1.2.0.0(Jul  1 2016 20:04:45)
SDK version:1.5.4.1(39cb9a32)
Ai-Thinker Technology Co., Ltd.
Integrated AiCloud 2.0 v0.0.0.3
Build:1.5.4.1 Jan 10 2017 18:32:04
OK
[8624] +CIFSR:STAIP,"xxxxx"
+CIFSR:STAMAC,"xxxxx"
[8625] Connected to WiFi
[18675] <[02|00|01|00] e49d1adebxxxxx2f964c3532
[18733] >[00|00|01|00|C8]
[18733] Ready (ping: 20ms).
[18734] Free RAM: 7156
[18804] <[11|00|02|00]hver[00]0.5.0[00]h-beat[00]10[00]buff-in[00]1024[00]de
[18870] <v[00]Arduino Mega[00]cpu[00]ATmega2560[00]con[00]ESP826
[18904] <6[00]build[00]Jan 25 2018 18:08:36[00]
[18946] >[00|00|02|00|C8]
Boot Triggering V64 Sync (Timer test)  <--- Should read as V0... remnant vPin from prior test ;)
[19017] <[10|00|03|00|04]vr[00]0
[28953] <[06|00|04|00|00]
[29002] >[00|00|04|00|C8]
[39000] <[06|00|05|00|00]
[39042] >[00|00|05|00|C8]
[49032] <[06|00|06|00|00]
[49072] >[00|00|06|00|C8]
[59071] <[06|00|07|00|00]
[59110] >[00|00|07|00|C8]
[59170] >[14|1E]a[00|06]
[59170] >vw[00]0[00]1                    <--- Timer Function started here. V0 HIGH for 2 min
[59238] <[14|1E]a[00|06]vw[00]1[00]1     <--- Displaying V0 State in Display
Timer vPin State is: 1                   <--- Printing V0 State in Monitor
[69173] <[06|00|08|00|00]
[69228] >[00|00|08|00|C8]
[0]                                      <--- Manual reboot
    ___  __          __
   / _ )/ /_ _____  / /__
  / _  / / // / _ \/  '_/
 /____/_/\_, /_//_/_/\_\
        /___/ v0.5.0 on Arduino Mega

[505] Connecting to GunnersZone
[3566] AT version:1.2.0.0(Jul  1 2016 20:04:45)
SDK version:1.5.4.1(39cb9a32)
Ai-Thinker Technology Co., Ltd.
Integrated AiCloud 2.0 v0.0.0.3
Build:1.5.4.1 Jan 10 2017 18:32:04
OK
[8624] +CIFSR:STAIP,"10.10.3.150"
+CIFSR:STAMAC,"5c:cf:7f:3c:b2:08"
[8625] Connected to WiFi
[18668] <[02|00|01|00] e49d1adeb5da462d948a512f964c3532
[18708] >[00|00|01|00|C8]
[18708] Ready (ping: 11ms).
[18709] Free RAM: 7156
[18779] <[11|00|02|00]hver[00]0.5.0[00]h-beat[00]10[00]buff-in[00]1024[00]de
[18848] <v[00]Arduino Mega[00]cpu[00]ATmega2560[00]con[00]ESP826
[18879] <6[00]build[00]Jan 25 2018 18:08:36[00]
[18922] >[00|00|02|00|C8]                    <--- Bootup sync here. 
Boot Triggering V64 Sync (Timer test)        <--- Serial print confirmation of sync (again, really was V0)
[18992] <[10|00|03|00|04]vr[00]0             <--- Appears to process... but function NOT called.
[19030] >[14|00|03|00|01]
[19030] >1
[29021] <[06|00|04|00|00]
[29061] >[00|00|04|00|C8]
[39050] <[06|00|05|00|00]
[39089] >[00|00|05|00|C8]
[49087] <[06|00|06|00|00]
[49128] >[00|00|06|00|C8]
[59126] <[06|00|07|00|00]
[59165] >[00|00|07|00|C8]
[69163] <[06|00|08|00|00]
[69203] >[00|00|08|00|C8]
[69422] >[14|04|EB|00|06]
[69422] >vw[00]2[00]1                    <--- 1st manual sync.
Manualy Triggering V0 Sync (Timer Test)    
[69490] <[10|04|EB|00|04]vr[00]0         <--- Appears to process... but function NOT called.
[69531] >[14|04|EC|00|06]
[69531] >vw[00]2[00]0
[69542] >[14|04|EB|00|01]
[69542] >1
[79520] <[06|00|09|00|00]
[79560] >[00|00|09|00|C8]
[80799] >[14|04|ED|00|06]
[80799] >vw[00]2[00]1                   <--- 2nd manual sync.
Manualy Triggering V0 Sync (Timer Test)
[80867] <[10|04|ED|00|04]vr[00]0        <--- Appears to process... but function NOT called.
[80909] >[14|04|EE|00|06]
[80909] >vw[00]2[00]0
[80920] >[14|04|ED|00|01]
[80920] >1
[90900] <[06|00|0A|00|00]
[90954] >[00|00|0A|00|C8]
[100952] <[06|00|0B|00|00]
[100989] >[00|00|0B|00|C8]
[106590] >[14|1E]a[00|06]
[106590] >vw[00]0[00]0                    <--- Timer ended, function called.
[106658] <[14|1E]a[00|06]vw[00]1[00]0     <--- Displaying V0 State in Display
Timer vPin State is: 0                    <--- Printing V0 State in Monitor
[116600] <[06|00|0C|00|00]
[116640] >[00|00|0C|00|C8]
[126630] <[06|00|0D|00|00]
[126671] >[00|00|0D|00|C8]
[136669] <[06|00|0E|00|00]
[136711] >[00|00|0E|00|C8]
[146710] <[06|00|0F|00|00]
[146759] >[00|00|0F|00|C8]

From my recollection of the Timer the ON and OFF times are stored on the server not the current status of HIGH / LOW 1 / 0.

Before Time Input widget was added by Blynk we parsed the entire project json file reading these times and built a scheduler around it. It was very cumbersome but doable until the super Time Input widget became available.

Quite a bit of coding is still required for Time Input but considerably less than parsing the whole project.

So I am pretty sure Timer is fine, it was written without sync availability as it’s not a simple HIGH / LOW it’s Unix time.

@Dmitriy I guess an improvement for Timer would be to add an extra flag in the app that asks the user if they want a status of 1 / 0 if trigger time (on or off) has passed for the day.

That all makes sense… Although I wouldn’t call it fine, as it seems to agitate some users :wink: and I do have a faint recollection of similar issues of it not working with a reboot midway… but you try searching for the keyword “timer”…all the BlynkTimer and SimpleTimer posts in the world :stuck_out_tongue:

And normally we are not worried about Timer Widget issues as Eventor’s timer and Time Input are better all around… but you got to admit, Timer Widget is dirt simple to use for the noobs.

Worst case… clearly document its lack of syncability in the Docs and call it done :stuck_out_tongue_winking_eye:

This is the json extract for a Timer

{"type":"TIMER","id":126677,"x":0,"y":0,"color":600084223,"width":3,"height":1,"tabId":0,"isDefaultColor":true,"deviceId":0,"pinType":"VIRTUAL","pin":1,"pwmMode":false,"rangeMappingOn":false,"min":0,"max":1,"startTime":72000,"startValue":"1","stopTime":75600,"stopValue":"0"}],

See 72000 and 75600, on at 10PM and off at 11PM.

Purdy… but over my head as to what to do with it :blush:

Any many more users, ergo Time Input was created.

I still find Time Input difficult… I mean I understand what it does… but to parse it all out into simple “do this function now” and “do this function later” code had me flustered… until I realised I have no reason to set a time to do anything, and gave up :rofl:

1 Like

@rotarucosminleonard could you please clarify. You are using Timer Widget or Time Input Widget? Timer widget has SYNC function so it should return value via virtualSync() call. Do you use DeviceSelector or Tags with it?

@Dmitriy Best as I could tell he was using the basic Timer Widget

I think I just conclusively showed that it doesn’t work… not to mention the OP’s crankiness when I didn’t acknowledge that in the first place :stuck_out_tongue_winking_eye:

@Dmitriy pretty sure the OP is using Timer widget. What should virtualSync() return?

Timer should return latest state from those pin.