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:
{
digitalWrite(doser1, HIGH);
dosing1=0;
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
Do I need to save doser1left as a separate virtual value and recall it and resave it to doser1left on startup? and THEN send it to the VU meter on V43?
I can see from the documentation that you can save a value that doesnât have a widget as:
Blynk.virtualWrite(V0, value)
âŚbut how would I then call it back and reassign it to V43?
Okay, i6t would help if you explained which virtual pin the âVU meterâ is attached to, and what type/function the other widgets are that relevant to this, and which virtual pins they are connected to.
V23 is a numerical input that I will use when I refill the bottle with liquid. This should in turn push doser1left to the same value and write it on the VU meter, which it is doing.
When the pump gets turned on it will use some liquid and when it turns off, the following is run.
void doser1off()
{
digitalWrite(doser1, HIGH);
dosing1=0;
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
}
Again this works and calculates the new doser1left and displays it on the VU meter at V43.
HOWEVER⌠whenever I reset the program, or turn it off and back on, if the app is open it wipes the VU meter back to 0. And if the app is closed, when I open it the VU meter again is on 0.
The serial prints are showing that it is 0 right from startup and does not pull the data back from anyway.
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.