Hello all, newbie here. I am building a remote temperature monitor for my parent’s house when they snowbird. I got a few hours in before I realized that the eventor widget was not available for iOS. Happy to try it with code but anytime I add anything to my code it has all kinds of timeout issues. I have been working with timers as suggested and still not much success. Even a simple if statement with a conditional that is never met and no code, inside a function that is never called gives me all kinds of timeouts. I am running Wemos D1 R2, programming it with Arduino 1.8.8. Am I just running into some hardware limitation? Thanks for any help.
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "***";
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "***";
char pass[] = "***";
//int alert=0;
float t;
BlynkTimer timer;
//BlynkTimer alertDelay;
void sendSensor()
{
//Serial.println("sendSensor");
t = (678*analogRead(0)/1000)-93.4; // or dht.readTemperature(true) for Fahrenheit
Serial.println(t);
// You can send any value at any time.
// Please don't send more that 10 values per second.
Blynk.virtualWrite(V5, t);
}
void lowTempAlert()
{
// Serial.print(alert);
// Serial.println("lowTempAlert");
if (t > 80) {
// if (alert == 0){
//// Blynk.email("Alert", "It's hot in here!");
//// Serial.println("Sent Warning Email!");
////// delay(60*1000);
// alert = 1;
// }
}
}
void setup()
{
// Debug console
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
// You can also specify server:
//Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 80);
//Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8080);
timer.setInterval(10000L, sendSensor);
//alertDelay.setInterval(10000L, lowTempAlert);
}
void loop()
{
Blynk.run();
timer.run();
}
Well, something must have worked… becasue If the condition was ever met, even once, this line in your function would disconnect Blynk
And if uncommented, having both times set to call their own functions at the exact same time could also cause issues.
Particularly running like this… as each can already call up to 16 instances.
I have always wondered if creating multiple named timers running simultaneous, can get in each other’s way more than one named timer with multiple simultaneous instances.
Sorry about the lack of info. Hit the wrong button and published before I wrote anything and subsequently got locked out. Have edited the original post.
So rather than putting a 60 second delay in your code after sending an alert, the better way would be to change your timer so that the test for too hot/cold is only done every 60 seconds.
However, if you do that, you’ll get an alert every minute until the temperature is back in range. This may be what you want, but I’d guess it would be rather annoying if it happened at 3am - especially if you couldn’t do anything about it immediately.
The way to overcome that is to set a flag (using a boolean variable) that starts off as false, then is set to true once an alert has been sent, and only gets set back to false again when the temperature comes back in range.
Your code to send alert should test to see if your flag is false before sending, the set it to true afterwards.
Thanks for taking the time to respond Pete and Gunner. As you can see from the code comments I have tried different things such as the delay you mention as well as having one function report the temperature and another check and send the alert. (Pete, if you look close you can see flag algorithm you describe in the commented out function).
Now, to your suggestions Gunner, I will start at the top. Recall that the code gives me all kinds of disconnects as it is above. Are you saying that the commented out delay line that is inside a function that is never called can have an effect on the program? That doesn’t seem possible to me but since I’m completely stumped I deleted the line completely and got the same disconnects. I don’t think that matters.
I hear you on the timers. I have tried checking the temperature in the sendSensor() function as well other things. I don’t think that is important at the moment because even when I’m not using another timer or another instance of the first timer (which I don’t totally understand yet, but one thing at a time) , I still get the disconnects. If I comment out the if statement I get measurably less timeouts and if I comment out the lowTempAlert function entirely I get virtually none. Ping times reported in initial connection seem to vary in the same way. If the initial ping time is low I can predict fewer disconnects.