#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
BlynkTimer timer;
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "Auth Token : ***********************************";
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "*********";
char pass[] = "**************";
int flag1 = 0;
int flag2 = 0;
void notifyOnButtonPress1()
{
int isButtonPressed1 = digitalRead(0);
if (isButtonPressed1 == 1 && flag1 == 0) {
// We allow 1 notification per 15 seconds for now.
Blynk.notify("Dad's alarm is now set and he has gone to bed");
flag1 = 1;
}
else if (isButtonPressed1 == 0)
{
flag1 = 0;
}
}
void notifyOnButtonPress2()
{
int isButtonPressed2 = digitalRead(2);
if (isButtonPressed2 == 1 && flag2 == 0) {
// We allow 1 notification per 15 seconds for now.
Blynk.notify("Dad's alarm is now unset");
flag2 = 1;
}
else if (isButtonPressed2 == 0)
{
flag2 = 0;
}
}
void setup()
{
// Debug console
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
// Setup notification button on pin 0
pinMode(0, INPUT_PULLUP);
// Setup notification button on pin 2
pinMode(2, INPUT_PULLUP);
timer.setInterval(16000L, notifyOnButtonPress1);
timer.setInterval(16000L, notifyOnButtonPress2);
}
void loop()
{
Blynk.run();
timer.run(); // Initiates BlynkTimer
}
Alistair