Hello All
As I said in the title I’m struggling trying to get my virtual pins to recall the last data point from the server. If I lose power, or if it disconnects from wifi, each time it reboots back to 0. What I am trying to do is recall the last value that was stored for V2 and V3, which are a totalizer and a resettable totalizer.
My project is for a flowmeter on my house, and its working fine, but the total flow resets each time I reboot the ESP32 I am using.
If you look at my code pasted below, I have tryed the Blynk.syncVirtual command in the setup and its not working. I also tried the Blynk.syncAll command as well and each time it reverts back to 0.
Thank you in advance!
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
BlynkTimer timer;
volatile int flow_frequency;
unsigned int flowrate;
unsigned char flowsensor = 5;
unsigned long currentTime;
unsigned long cloopTime;
float a;
int total;
void flow (){
flow_frequency++;
}
void sensor(){
{
currentTime = millis();
if(currentTime >= (cloopTime + 1000))
{
cloopTime = currentTime;
flowrate = (flow_frequency * 60 / 5.5);
flow_frequency = 0;
a = (flowrate*0.004402867539062501);
Blynk.virtualWrite(V1, a);
}}}
void flowmeter(){
total = total + a;
Blynk.virtualWrite(V2, (total*.016));
}
BLYNK_WRITE(V4)
{
if (param.asInt())
{
Blynk.virtualWrite(V3, 0);
}
else
{
Blynk.virtualWrite(V3, (total*.016));
}
}
void setup(){
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
Blynk.syncVirtual(V2, V3);
timer.setInterval(1000L, sensor);
timer.setInterval(1000L, flowmeter);
pinMode(flowsensor, INPUT);
digitalWrite(flowsensor, HIGH);
attachInterrupt(5, flow, RISING);
sei();
currentTime = millis();
cloopTime = currentTime;
}
void loop(){
Blynk.run();
timer.run();
}