VirtualWrite, syncvirtual, reading widget, graph...I'm lost :-D

Hi Blynkers!

I’m using a Wemos d1 mini with a dht22 for my project.
I’ve checked the manual, but I’m still lost when it comes to have both a reading widget and an history graph fed at the same time. Maybe someone could point me in the right direction :wink:

Right now, I’m doing something like this:

BLYNK_READ(0)
{
Blynk.virtualWrite(0, h);
}

the result being a working reading widget, but a history graph that doesn’t update when app is not on (and to avoid this I’m using virtualWrite, righ?). Im also making a sync somewhere:

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

But hey, I’m probably missing a step…

Any suggestions?

Thanks!
O.

Hello. Reading Frequency widget works only when app is active and open. See http://docs.blynk.cc/#widgets-displays-history-graph for more details.

Hello @Dmitriy

I saw that you must have written this answer a million times and are slowly despairing inside… :smiley:
However, according to the docs:

or you can use Blynk.virtualWrite on hardware side.

Now, how am I supposed to combine blynk.read and blynk.virtualwrite to have something like this https://drive.google.com/open?id=0B9MKoh0XGwyDMDVoaXVUS1c1eFk working?
I mean, if the app is open, I can easily read the values with labeled value display. And for long term monitoring I have the history graph, right?

Always start with provided Getting Started Blynk examples.

Try this: https://github.com/blynkkk/blynk-library/blob/master/examples/GettingStarted/PushData/PushData.ino

See on line 49 it says

Blynk.virtualWrite(V5, millis() / 1000);

Want more widgets to update? Just dupe the line and change the Vpin.

Blynk.virtualWrite(V5, millis() / 1000); 
Blynk.virtualWrite(V6, analogRead(A0)); // analog sensor?
Blynk.virtualWrite(V7, dht.readTemp()); // dht (not a real function but could be)
Blynk.virtualWrite(V8, myCustomFunction()); 

you can change the timer on line 58

timer.setInterval(1000L, myTimerEvent);

1000L = 1000ms = 1 second. Dont go any faster than 1 seconds for this type of data. I sometimes push my hardware to every 100ms for some sensors but the aim of the game is to lower the over number of requests made.

So you could combine all of those 4 requests in to 1 or 2.

Blynk.virtualWrite(V5, (millis() / 1000) + String("sec | ") + analogRead(A0) + String("%"))); 
Blynk.virtualWrite(V6, (dht.readTemp() + String("c | ") + myCustomFunction() + String("%"))); 

for instance…

1 Like

Blynk.read is called only when app is opened. Please follow example provided by @Jamin.

1 Like

Hi Jamin!

Thanks for your answer! That’s actually the example I used to start (why does everyone seem to assume people don’t read docs or use examples?). But probably I’ve been doing too much instead of keeping it simple. :slight_smile:

Removed something like 10 lines of code, moved around things a little and it works nicely.

Sometimes you just cannot see the forest for the trees…

Thanks again!

1 Like