So I have added some VU meters to show how much fluid is left in a bottle. Some fluid gets used from a timer and I want it to keep track of how much is being used, and eventually send me a notification when it gets low.
However when the unit is reset, it is not getting the last known values back from the server. It is almost certainly something I’ve done wrong but I cannot see it.
When the pump gets turned on and back off again after dosing liquid, I have this:
Serial.println("DOSE 1 OFF");
Blynk.virtualWrite(V19, 0); // LED Widget off
Blynk.virtualWrite(V31, 0); // BOOST button off
doser1left = doser1left - doser1amount; // Calculation to take away whats been used.
Blynk.virtualWrite(V43, doser1left); // VU Level meter
And this is another button that I use when I refill the bottle of liquid
Okay, I’m not sure that the Level H/V widgets are capable of reporting back their values via param.asInt function, which is what you’d need to do if you wanted to pull-back the latest stored value from the server on start-up.
If the Level widgets do actually return a value via param.asInt then you’d need your BLYNK_WRITE(V43) callback to capture this value and assign it to a variable in your sketch.
If it doesn’t work this way then, as you suggested, you could store the value in a widget such as V0 and force it to send the value to the hardware via Blynk.syncVirtual(V0) which will cause the BLYNK_WRITE(V0) callback to execute.
Shouldn’t the Blynk servers store the value of V43 though? I would have thought it stores the values and then just retrieves it and sends it to whatever widget you assign it to?
For example if I was to save doser1left as 1000 to V43, I would assume that 1000 would be saved to the server, then when I sync V43 it would pull back 1000 and resave it to doser1left via the sync code. Then as the Level widget is assigned to 43, it would then send it to the level. Or have I got it wrong?
It would seem that doser1left is not being saved to the server.
If it does allow you to pull it back then your “sync code” isn’t doing anything useful…
The value of doser1left will presumably be zeto, because you’ll have a line that says int doser1left; which will initialise the variable as zero on start-up and this is what you’re writing back to the V43 widget and to your serial monitor.
You’re not fetching the stored value of V43 back from the server, as you have no param.asInt statement in BLYNK_WRITE(V43)
Yes I do have the int doser1left;, so thats why it’s going back to 0. But then that would be the same with all of them, and yet all of the others still reload their values.
All of these are reloading, apart from the bottom four which are the ones in question. However, these are the only ‘outputs’, as in not buttons or toggles, or inputs, just pure simple outputs. Not sure if that has anything to do with it. But either way, the data is still being pulled back for the rest and not them.