Properly zero-out mobile widgets upon Blynk disconnect

Hi, need help for best way to properly “close” or otherwise turn off widget indicators in my IOS (latest version) mobile app. Specifically, I have an LED widget which indicates GPS “locK” when lit. Works well to show GPS status when the app is running, but I cannot seem to find a way to turn it off upon Blynk disconnection. This is important since I don’t want to mislead a user that the GPS is active when there is no Blynk connection. Maybe a connection lifecycle issue or solution?
Here is the code I am attempting to use:

BLYNK_CONNECTED() {
...
 Blynk.virtualWrite(V69, 0); // Initially turn off GPS LOCK LED
}

...

BLYNK_DISCONNECTED() {
  Blynk.virtualWrite(V69, 0); // turn off GPS LOCK LED
}

Thanks!

If you think about it, your code will never work.
Your device has just detected that it is no longer connected to the Blynk server, and at that point you want it to write data to the Blynk server via the non-existent connection!

If you look at the Advanced settings for your V69 datastream you’ll see the Invalidate Data option. This allows you to set a value (zero in your case) if no updated data has been received within a certain amount of time.
Obviously, the issue with this approach is that you need to be regularly sending a non-zero value to V69 and depending on your type of Blynk subscription that could cause you to exceed your monthly message quota.

Pete.

Pete, thanks much for the insights!

1 Like