VU meter not getting data last reading from cloud

Hi, need help again please.

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.

This is the level widget part:

   {
     Blynk.virtualWrite(V43, doser1left);
     Serial.print("doser1left - ");Serial.println(doser1left);
   }

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

{
  doser1refillamount = param.asInt();
  doser1left = doser1refillamount;
  Blynk.virtualWrite(V43, doser1left);
  Serial.println("doser1refillamounttemp called");
  Serial.print("doser1left - ");Serial.println(doser1left);
}

I have only V43 syncing at the beginning of the sketch but assumed that it should still pull the data saved under V43 to the VU meter. But its not.

As soon as I activate V23 by pushing the button, the VU kicks into life, but not after resetting the device.

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?

Thanks, Steve

Hi Steve, You’ve stopped using triple backticks for your code and used block quotes instead - this doesn’t work!

Pete.

Sorry I thought that was how you did it if its not full code and just little bits to make them stand out. Sorry.

I’ve changed it. is that right?

No, there are no triple backticks, and you still have the blockquites.

Pete.

Got it. I see the difference now. Didn’t realise it did that. Thank you Pete.

This is the serial output I am getting…

   ___  __          __
   / _ )/ /_ _____  / /__
  / _  / / // / _ \/  '_/
 /____/_/\_, /_//_/_/\_\
        /___/ v0.4.7 on NodeMCU

[5001] Connecting to blynk-cloud.com:8442
[5093] Ready (ping: 39ms).
BLYNK CONNECTED
[5168] Time sync: OK
Doser 1 active = 0
Doser 2 active = 1
Doser 3 active = 0
Doser 4 active = 1
doser1timeH - 23:44
doser2timeH - 1:35
doser3timeH - 1:37
doser4timeH - 1:39
Doser 1 amount = 10
Doser 2 amount = 10
Doser 3 amount = 5
Doser 4 amount = 5
dose1calibrationinput = 57
dose1calibration = 0.95
dose2calibrationinput = 65
dose2calibration = 1.08
dose3calibrationinput = 80
dose3calibration = 1.33
dose4calibrationinput = 76
dose4calibration = 1.27
doser1left - 0
doser2left - 0
doser3left - 0
doser4left - 0

See its getting the other data for the other pins, just not the doser1left (or 2, 3, 4) Of course it could be that its not saving it either.

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.

Pete.

V43 is VU Meter which I want to display doser1left.

BLYNK_WRITE(V43) 
{
  Blynk.virtualWrite(V43, doser1left);
  Serial.print("doser1left - ");Serial.println(doser1left);
}

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.

BLYNK_WRITE(V23) 
{
  doser1refillamount = param.asInt();
  doser1left = doser1refillamount;
  Blynk.virtualWrite(V43, doser1left);
  Serial.println("doser1refillamounttemp called");
  Serial.print("doser1left - ");Serial.println(doser1left);
}

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.

Pete.

Thats brill, i’ll give that a go thank you.

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.

Yes, it’s stored.

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)

Pete.

Pete.

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.

[5001] Connecting to blynk-cloud.com:8442
[5067] Ready (ping: 25ms).
BLYNK CONNECTED
[5132] Time sync: OK
Doser 1 active = 0
Doser 2 active = 1
Doser 3 active = 0
Doser 4 active = 1
doser1timeH - 23:44
doser2timeH - 1:35
doser3timeH - 1:37
doser4timeH - 1:39
Doser 1 amount = 10
Doser 2 amount = 10
Doser 3 amount = 5
Doser 4 amount = 5
dose1calibrationinput = 58
dose1calibration = 0.97
dose2calibrationinput = 65
dose2calibration = 1.08
dose3calibrationinput = 80
dose3calibration = 1.33
dose4calibrationinput = 76
dose4calibration = 1.27
doser1left - 0
doser2left - 0
doser3left - 0
doser4left - 0

I did try this as per your last paragraph but hasn’t done anything. Have I written it right?

BLYNK_WRITE(V43) 
{
  doser1left = param.asInt();
  Blynk.virtualWrite(V43, doser1left);
  Serial.print("doser1left - ");Serial.println(doser1left);
}

Yes, because…

a) You had the correct code to capture the value from the widget and store it as a variable and
b) You were using widgets that support this method.

So, you’ve now established that, as I suspected, these widgets don’t support that method…

so, you’ll need to…

Pete.