I am using a virtual pin V8 to store the water level by counting the motor ON time.
Initial value of V8 = 1000 (i.e. max water level)
when I turn on motor for 3 sec, V8 will be 997
when I turn on motor for 5 sec, V8 will be 992, etc.
However, in reality, the device may be disconnected from the wifi for a while, the value of V8 will be backed to 1000, is any method that I can keep the value of V8 even disconnect from wifi?
Below is my coding
// LIBRARY
//====================================================
#define BLYNK_PRINT Serial
#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>
//====================================================
// DEKLARASI AWAL
//====================================================
char auth[] = "";
char ssid[] = "";
char pass[] = "";
#define EspSerial Serial3
#define ESP8266_BAUD 115200
ESP8266 wifi(&EspSerial);
//====================================================
//BLYNK_WRITE(V0)
//{
// drink = param.asInt();
//}
BlynkTimer timer;
int pump_on;
int interval;
int interval1;
int timer_no;
int drink_level1 = 1000;
BLYNK_WRITE(V6)
{
pump_on = param.asInt();
if (pump_on == 1)
{
digitalWrite(52, HIGH);
timer_no = timer.setTimeout(interval1, []()
{
digitalWrite(52, LOW);
Blynk.virtualWrite(V6, 0);
drink_level1 = drink_level1 - interval;
});
}
else {digitalWrite(52,LOW);
timer.deleteTimer(timer_no);
}
}
BLYNK_READ(V8)
{
Blynk.virtualWrite(V8, drink_level1);
}
BLYNK_WRITE(V7)
{
interval = param.asInt();
interval1 = interval * 1000.0;
}
//====================================================
void setup()
{
pinMode(52, OUTPUT);
Serial.begin(115200);
Serial3.begin(115200);
delay(10);
EspSerial.begin(ESP8266_BAUD);
delay(10);
Blynk.begin(auth, wifi, ssid, pass); //Reguler server
//Blynk.begin(auth, wifi, ssid, pass, "192.168.43.120", 8080); //Local server
}
void loop()
{
Blynk.run();
timer.run();
if ( Serial3.available() ) {
Serial.write( Serial3.read() );
}
if ( Serial.available() ) {
Serial3.write( Serial.read() );
}
}