The general idea is to store some device settings in virtual pins on Blynk server
So steps on device would be following:
get settings from Blynk server
if settings not present on server use default values and send these values to Blynk server
And im confused a little bit how I could do this
because if I force pin sync to get settings from server with
Blynk.syncVirtual(Args... pins)
It could be that BLYNK_WRITE_DEFAULT or BLYNK_WRITE would not be invoked if value is not stored on server and its not possible to understand is virtual pin value is not stored on server or we just waiting response
Is there some function which could get virtual pin value from Blynk server in sync way? like this:
Hello. You can set the default value to the virtual pin and when you do sync you can check for that default value, so you would know if pin is not yet initialized with your config.
But it will not solve the problem because if I set default values to virtual pins it will override values stored on server
In general, the question can be reduced to the following: how to update virtual pin on Blynk server ONLY if value for this pin is not stored on server ?
When you create a virtual pin, you set a default value to “0”.
When hardware initially connects to the server and does sync for that pin, pseudo code:
BLYNK_WRITE(Vx) {
String val = param.asStr();
if (val == "0") {
//here config is not set yet
//if you send here update to the server
//this branch will never be executed again, unless you set the "0" manually
}
}
In other words - you can use the initial default value of the pin as a flag or indicator that this pin hasn’t a value yet (while formally the value is there).
void setup() {
Blynk.run();
}
BLYNK_CONNECTED() {
Blynk.virtualWrite(Vx, defaultValue); // <-- I think it will override value on the server (in case if it exist)
Blynk.syncVirtual(Vx)
}
BLYNK_WRITE(Vx) {
value = param.asInt();
}
Well, your approach is always going to write the default value to the virtual pin.
Better to set your variable to the default value, call the Blynk.syncVirtual then write the result to the pin.