I have a garage door opener and monitor made from a Particle Photon board, the Blynk app and IFTTT. I use IFTTT to monitor status (open/closed), and Blynk to activate the opener.
Reports from IFTTT for open/close events are very reliable. The Blynk app, though, more often than not, indicates the board is offline. For example Blynk reports the device has been offline since 21:04 tonight, but IFTTT reported open/close events at 21:30 today. When monitoring today, Blynk sometimes reported online, sometimes offline, but I don’t find any way to track on/off-line status events, nor to force Blynk to reconnect.
When online, all functions work as intended/expected in Blynk.
Questions:
- Is there a way from the app to request a reconnection to the device?
- Is there a way in code to check connection status and/or reconnect?
- Is connection status logged somewhere that I can review?
- Am I doing something stupid in the code to cause frequent loss of connection?
See code below.
Thanks for any feedback.
#include <blynk.h>
#include "blynk/BlynkSimpleParticle.h"
char auth[] = "<some code>";
const int openSwitch = D2;
const int closeSwitch = D1;
const int relaySwitch1 = D0;
const int relaySwitch2 = D3;
const int eventDelay = 20000;
int openStatus = 0; // High when all the way open
int closeStatus = 0; // High when all the way closed
int oldStatus = 0;
int ledStatus = 0;
char *ledColor = 0;
int closeLedStatus = 0;
WidgetLED led1(V3);
void setup()
{
Serial.begin(9600);
Blynk.begin(auth);
pinMode(relaySwitch1, OUTPUT);
pinMode(relaySwitch2, OUTPUT);
pinMode(openSwitch, INPUT);
pinMode(closeSwitch, INPUT);
}
//add button in Blynk app corresponding to V0
BLYNK_WRITE (0){ //close garage
if (closeStatus == LOW) {
digitalWrite(relaySwitch1, HIGH);
delay(1000);
digitalWrite(relaySwitch1, LOW);
Particle.publish("buttonPush", "close");
}
}
//add button in Blynk app corresponding to V1
BLYNK_WRITE (1){ //open garage
if (closeStatus == HIGH) {
digitalWrite(relaySwitch1, HIGH);
delay(1000);
digitalWrite(relaySwitch1, LOW);
Particle.publish("buttonPush", "open");
}
}
//add LED in Blynk app corresponding to V3
BLYNK_READ(3) //report garage status
{
// Blynk.setProperty(V3, "color", "#FF0000");
// led1.setValue(255);
// Blynk.virtualWrite(3, ledStatus);
}
void loop()
{
Blynk.run();
// Initialize the LED
//constantly monitor the reed switch status (garage open or closed)
oldStatus = closeStatus;
openStatus = digitalRead(openSwitch);
closeStatus = digitalRead(closeSwitch);
if (openStatus == LOW) {
ledStatus=255;
ledColor="#0000FF";
led1.on();
Blynk.setProperty(V3, "color", "#0000FF");
// led1.setValue(64);
if (oldStatus == LOW) {
Particle.publish("doorStatus", "open");
delay(eventDelay);
}
}
else if (closeStatus == LOW) {
Blynk.setProperty(V3, "color", "#00FF00");
led1.on();
if (oldStatus == HIGH) {
Particle.publish("doorStatus", "closed");
delay(eventDelay);
}
}
else {
led1.on();
Blynk.setProperty(V3, "color","#FF0000");
if (oldStatus == LOW) {
Particle.publish("doorStatus", "open");
delay(eventDelay);
}
}
delay(1000);
}