My revised Code (still doesn't work):
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
int current_hys_comparator_level = LOW;
int previous_hys_comparator_level = LOW;
const int hys_comparator_high_thresh = 210;
const int hys_comparator_low_thresh = 150;
////////////////////
// Blynk Settings //
////////////////////
char BlynkAuth[] = "XXXXXXX";
char WiFiNetwork[] = "XXXXX";
char WiFiPassword[] = "XXXX";
void read_photodiode_sensor()
{
previous_hys_comparator_level = current_hys_comparator_level;
int current_analog = analogRead(A0);
if( current_analog > hys_comparator_high_thresh ) current_hys_comparator_level = HIGH;
if( current_analog > hys_comparator_low_thresh ) current_hys_comparator_level = LOW;
}
void setup()
{
// Initialize hardware
Serial.begin(9600); // Serial
// Initialize Blynk
Blynk.begin(BlynkAuth, WiFiNetwork, WiFiPassword);
read_photodiode_sensor();
}
void loop()
{
read_photodiode_sensor();
Blynk.run();
if( current_hys_comparator_level==HIGH && previous_hys_comparator_level==LOW )
{
Blynk.email("XXXXX@gmail.com", "XXXXX", "XXXXX");
}
}
The serial Monitor says:
[292159] Login timeout
[295159] Connecting to blynk-cloud.com:8442
[297342] Login timeout
[300342] Connecting to blynk-cloud.com:8442
[302532] Login timeout
[305532] Connecting to blynk-cloud.com:8442
But if I remove everything from the void loop except "Blynk.run();" the Blynk board will stay connected to the server...