Proactive (non-BLYNK_WRITE-triggered) Datastream reading

Hi Blynkers.
How can I read an existing Datastream value without waiting for BLYNK_WRITE ( VPIN ) to get called?

Use case: I have Master and Slave devices. The Master device writes to the Slave device’s Datastream using a Blynk API HTTP update. When that Blynk API update occurs the Slave’s BLYNK_WRITE ( VPIN ) executes. All is Right with The World.

However, if the Slave device reboots, when it comes online there’s nothing to trigger the BLYNK_WRITE ( VPIN ) routine on the Slave device. The Slave device does not know the current Datastream values. Moreover, if the Master device has changed the Slave’s Datastream value while the Slave device is offline, the Master device still sees a successful Blynk API update return-code – as it should, and the Slave device doesn’t know of the change.

I have not found a way for the Slave device to obtain its own Datastream value without something triggering BLYNK_WRITE ( VPIN ). I get around it by having the Slave device ‘check-in’ with the Master device using another Blynk API update to the Master device. When the Master device sees the update from the Slave device, it can then (re)send the correct data to the Slave device. But this creates unnecessary traffic.

I have tried Blynk.syncAll(), but it doesn’t fire the BLYNK_WRITE ( VPIN ) routine unless the Datastream has been updated recently.

Hope this is clear. All thoughts welcome. Thanks for any info.

Blynk.syncAll() is a bit of a “sledgehammer to crack a nut” and has a big impact on the Blynk server. To mitigate that Blunk IoT has limited the shope of the Blynk.syncAll() comms so that it now only synchronises the datastreams that have the rather weirdly named “Sync with latest server value every time device connects to the cloud” option enabled.

You’re far better calling individual Blynk.suyncVirtial(vPin) commands for each pin you want to retrieve the values for.

Pete.

Thanks @PeteKnight . Did not know about Blynk.syncVirtual ( VPIN ); Excellent.

Just tried it out and it’s exactly what I needed.

1 Like