This is an extension from a previous thread that was getting lengthy and off the original topic. I have the following code which monitors the state of a float switch (high or low). I upload the sketch, turn on the serial monitor and manually move the float switch up and down. The serial monitor output represents what I'm doing with the switch. The issue is that I get a constant loop of blynk notifications, every 15 seconds or so. Furthermore, if i move the switch to it's low position, the first blynk notification i get is correct reading "low", the following notifications are "high" thereafter. When the switch is moved to the high position, blynk just loops stating it's "high". I know it's weird and took quite a while to even establish what is going on here. but the biggest issue is the loop of notifications every 15 seconds.
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
BlynkTimer timer;
char auth[] = "710a4af9b1d82412fa477705bf642c634";
char ssid[] = "ssid";
char pass[] = "pwd";
int flag=0;
int floatSavedState = -1; // initial float low state indicates not yet known
void notifyOnButtonPress()
{
// pin D1 will be 1 if float has dropped due to low water level
// pin D1 will be 0 if water level is high enough
int floatLevelLow = digitalRead(D1); // read the float low indicator pin
if (floatLevelLow && floatLevelLow != floatSavedState) {
// send notification if this is first time or if the float level has
// changed since the last notification.
Serial.println("Resevoir Water is Low!");
Blynk.notify("Alert : Water Level low.");
floatSavedState = floatLevelLow;
} else if (floatLevelLow != floatSavedState)
// send notification if this is first time or if the float level has
// changed since the last notification.
Serial.println("Resevoir Water is High!");
Blynk.notify("Alert : Water level high");
floatSavedState = floatLevelLow;
}
void setup()
{
// Debug console
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
// Setup notification button on pin D1
pinMode(D1,INPUT_PULLUP);
timer.setInterval(16000L,notifyOnButtonPress);
}
void loop()
{
Blynk.run();
timer.run(); // Initiates BlynkTimer
}