State Syncing

For hardware

If your hardware looses Internet connection or resets, you can restore all the values from Widgets in the Blynk app.
1
BLYNK_CONNECTED() {
2
Blynk.syncAll();
3
}
4
5
//here handlers for sync command
6
BLYNK_WRITE(V0) {
7
....
8
}
Copied!
The Blynk.syncAll() command restores all the Widget's values based on the last saved values on the server. All analog and digital pin states will be restored. Every Virtual Pin will perform BLYNK_WRITE event.
NOTE: if pin value is empty and wasn't initialized, hardware will not get any response for those pin during sync.
You can also update a single Virtual Pin value by calling Blynk.syncVirtual(V0) or you can update several pins with Blynk.syncVirtual(V0, V1, V2, ...).
You can also use server to store any value without widget. Just call Blynk.virtualWrite(V0, value).

For app

If you need to keep your hardware in sync with Widgets' state even if app is offline use Blynk.virtualWrite.
Imagine you have a LED Widget connected to the Virtual Pin V1 in the app, and a physical button attached to your hardware. When you press a physical button, you would expect to see updated state of the LED Widget in the app. To achieve that you need to send Blynk.virtualWrite(V1, 255) when a physical button gets pressed.
Last modified 4mo ago
Copy link