structure7 / room1irrigation

MIT License
0 stars 0 forks source link

Blynk: Two devices, one auth. How to tell which is disconnecting #7

Open structure7 opened 7 years ago

structure7 commented 7 years ago

So there's three bad things that can happen:

  1. Overflow or some kind of error causes ESP reset.
  2. Network dropout causes Blynk disconnect.
  3. ESP error causes Blynk disconnect.

What I know:

The idea: Monitor each occurrence of Blynk disconnecting, for whatever the reason. Ideally, report this to a vPin like the uptime monitoring seconds are. THIS SHOULD HELP TROUBLESHOOT PROBLEMS.

Side notes:

structure7 commented 7 years ago

What I came up with:

bool blynkFlag;
int blynkDisconnectCount; 

void setup (){
   timer.setInterval(250L, disconnectWatcher);     // Watches for a disconnect event
   timer.setInterval(5000L, disconnectReporter);   // Reports disconnects to the app every 5 seconds
}

void disconnectWatcher() {
  if (Blynk.connected() == false && blynkFlag == false) {
    ++blynkDisconnectCount;
    blynkFlag = true;
  }
  else if (Blynk.connected() == true && blynkFlag == true) {
    blynkFlag = false;
  }
}

void disconnectReporter() {
  Blynk.virtualWrite(V10, blynkDisconnectCount);
}

\\ Optionally... in a run once type deal
Blynk.setProperty(V10, "label", String(hour()) + ":" + minute() + " " + month() + "/" + day());  // Or whatever prints current time/date
structure7 commented 7 years ago

I can see there's some value in being able to differentiate between a blynk or WiFi "event." Not sure how I can do that but worth looking into.