When phone enters screensaver, PHP program calling Blynk Server API stops updating

hi All,

my first day and first time in blynk community.
because I met similar issue like as mentioned by DreaMinder.

Hopefully guys give me advices for improving pending issues.

I am using Arduino-like board so-called D1 and trying to fetch electricity data from smart plug.
The blynk app shows correct information as well. Meanwhile we use php program to call blynk server API to get electricity data and displays on our website includes voltage, current, power, etc.

When phone screen goes into screensaver, we met similar issue that displayed flowed stuck in the last value.

Any advice to make corresponding adjustment to avoid such issue?
Because the electricity information on website is important in any minutes for reviewing.

Kindly share your idea if possible, thanks ahead.

Hi. Do you use Frequency Reading in widget?

Unless you are also NOT using virtual pins (as switching to vPins was solution in other topic) then your situation may have differing issues. To keep topics cleaner, I have moved your post into your own topic.

Thanks Gunner.

in Blynk app, I am using vPins as you mentioned. Supposely it is ok because the display on app is absolutely right.

hi Dmitriy,

I am not getting your point. Kindly give me more hints for this topic.
You are talking about the widget in blynk app?

Please advice.

I mean - how exactly do you send value from your hardware? Do you use Blynk.virtualWrite in your code?

Yes, you can refer to following Arduino code

void loop()
{
  Blynk.run();
}
BLYNK_READ(V0) {
  float v = pzem.voltage(ip);
  if (v < 0.0) v = 0.0;
  Blynk.virtualWrite(V0,v);
  }

BLYNK_READ(V1) {
  float i = pzem.current(ip);
  if (i < 0.0) i = 0.0;
  Blynk.virtualWrite(V1,i);
  }

BLYNK_READ(V2) {
  float p = pzem.power(ip);
  if (p < 0.0) p = 0.0;
  Blynk.virtualWrite(V2,p);
  }

BLYNK_READ(V3) {
  float e = pzem.energy(ip);
  if (e < 0.0) e = 0.0;
  Blynk.virtualWrite(V3,e/1000);
  }

The data shown on Blynk app is absolutely correct. see attachment.
And from Blynk app, the information is reflecting instantly withoout error and it did not keep in last value.

@danchiou109 that’s correct. Current BLYNK_READ works only when app is open. You need to use timers to make it work even app is offline. Here is basic example for timer.

hi Dmitriy,

This is a helpful reply and let me reserve time to modify Arduino code to check it’s avaiability.
Thanks a lot.

1 Like

@danchiou109 what we do with our Pzem is run all the v, i and p data requests on a single 2 second timer.

Then e = e + (p * 2.000 / 3600.000) rather than calling it from the Pzem.

The 2s timer has virtualWrite’s for v, i, p and e and works when the app is sleeping.

I guess this should work for your PHP script.

I had this problem too. I thought it was a problem with the blynk REST API itself, it never occurred to me that it was the way that I had coded the app that caused the problem, but now it makes total sense.
Thanks Dimitri for the example! now my api refreshes even when the app is offline.