This a a great example of why you should lay-out your overall plan at the beginning, as it may influence how the code is structured.
Currently, using the code from post #33 the value that you wnat to push to Blynk every 10 minutes is adjusted_reading
.
This variable is local to the take_a_reading()
function, as that is where it is declared…
We need to move this to become a global variable by declaring it near the top of your sketch…
int adjusted_reading;
and not re-declare it in take_a_reading()
, so we need to remove the int
there…
adjusted_reading = (reading - adjustment);
You already have timer.run();
in your void loop, which is good, but you need to remove Blynk.run();
as you don’t want the Blynk library to talk to the server all the time.
You now need another timer event to be added to your void setup, like this:
timer.setInterval(1000L,take_a_reading); // Existing timer
timer.setInterval(600000L,send_to_blynk); // send data to Blynk every 10 minutes (60,000 m/s)
Your send_to_blynk()
function might look something like this…
send_to_blynk()
{
Blynk.connect();
Blynk.run();
Blynk.virtualWrite(V0, adjusted_reading); // To Display Widget
Blynk.run();
Blynk.disconnect();
}
The only potential problem with this approach is that the data might not arrive at the Blynk server, because the Blynk.disconnect()
is actioned before the virtualWrite has completed. I’ve added an additional Blynk.run()
before the disconnect, but you’ll have to see if the data is reliably written to Blynk using this approach.
If not, we may need to move the code into a BLYNK_CONNECTED()
callback.
Pete.