All of my code is working correctly however I want to use eventor with notification widgets to alert me whenever my door is open or closed. The problem is I don’t know how I would make eventor do an equal to when the value reads back as text as seen in the code below seeing as I can only use a numerical value. Will i just have to change the text to a 1 or a 0? Thank you all for any help.
/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
bool current = 0;
bool previous = 1;
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "idrathernotsharethis";
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "lol";
char pass[] = "lol";
void setup()
{
// Debug console
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
pinMode(14, INPUT_PULLUP); //DOOR
}
void switchstate(){
current = digitalRead(14);
if (current != previous){
previous = current;
if (current == LOW)
{
Blynk.virtualWrite(2, "Your door is closed.");
}
else
{
Blynk.virtualWrite(2, "Your door is open!");
}
}
}
void loop()
{
Blynk.run();
switchstate();
}
Actually I think I answered my own question, will this cause any issues with it getting stuck in a loop or timing out?
{
Blynk.virtualWrite(2, "Your door is closed.");
Blynk.notify("Door Closed");
}
else
{
Blynk.virtualWrite(2, "Your door is open!");
} Blynk.notify("Door Opened");
}
If the state keeps switching, perhaps some flood error issues and missed notifications (notifications have limits to how many times a second they can be called… see link below) becasue you have that check loop running hundreds of times a second. Break the switchstate() function call out of the main void loop() and use those timers I mentioned in another topic.
BlynkTimer is the same as the widely used SimpleTimer library, in that it works more elegantly than manually manipulating millis() and it is NOT dependent on a connection to a Blynk Server, and also fixes some minor issues with the original library.
A typical Interval Timer layout includes a definition, timer setup (pointing to a function) and a timer call in the void loop():
BlynkTimer Mytimer; // Sets up a timer object named Mytimer (could be any name)
Mytimer.setInterval(1000L, MyFunction); // Goes in Setup() and will call the void MyFunction() every 1000 milis (one second - adjust to your needs). Blynk Timer allows up to 16 of these same object named timers pointing to differing functions
void MyFunction()
{
// Mytimer runs stuff here every 1000 millis (one second)
}
void loop()
{
Blynk.run();
Mytimer.run(); // Goes in the void loop() so the BlynkTimer library can run.
}