BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

Bridge Widget Offline Communication

Dear Blynkers,
Hope you all had a Merry Christmas.

I have a scenario which I am trying to figure out. Using a bridge widget between 2 devices
Device 1 - Master
Device 2 - Slave
Master Device sends a signal to Slave Device (0 or 1)
Slave Device turns on something if it receives a 1 signal and turns off something with a 0 signal.
If the Master Device then goes offline what signal if any does the Slave Device receive? Can the Slave Device do a check to see if Master Device is online?

Thanks, I think you had the same with your family, and the coming New Year as well.

About the Bridge Master/Slave,

  1. If the Master Device then goes offline what signal if any does the Slave Device receive?
  • All the communications between the Master and Slave will be made via the Blynk Server.
  • So if the Master already pushes the controlling commands out to the network, and supposing the network is still OK (to let the relating data going to the Blynk Server, which is still alive and well, sending commands back to Slave, …), the Slave will receive the correct and intended signal and behaves correctly.
  • If there is anything wrong along the chain, we have no control and certainly don’t know which way the Slave will behave.
  1. Can the Slave Device do a check to see if Master Device is online?
    Currently, I don’t see any ready-made way to do this. But you can improvise something such as
  • Master periodically writes an ONLINE value (HIGH, ON, etc.) to a Slave’s VPIN (such as LED, etc.), using something such as 1-minute BlynkTimer.
  • The Slave normally displays that ONLINE data received from Master. But slave will also has a, for example, 2-minute BlynkTimer to write a OFFLINE value (LOW, OFF, etc…) to the corresponding VPIN.
  • Therefore, if the Master is OFFLINE, the Slave will, within max 2 minutes, will know the Master status.

Ok so that understand correctly
Master switches on a led at the slave, slave switches off the led. If offline slave will switch off the led and next timing cycle because the led is off, slave will determine master is off line. Yes that would work I will try tomorrow

Because Master and Slave timers are not synchronized, in the worst case, the LED might wrongfully display OFFLINE in max 1 minute, even the Master is ONLINE, if you use 1 and 2-min timers.

To avoid this, when Master writes to the Slave’s VPIN, you can use the relating BLYNK_WRITE(BLYNK_VPIN_ONLINE_LED) function to reset the Slave’s timer, by using the BlynkTimer function

restartTimer(unsigned numTimer)
For example, code for Slave:


BlynkTimer timer;
unsigned int Master_online_timer;

// By the Master, Turn ON every 1 minute, and reset timer
BLYNK_WRITE(BLYNK_PIN_ONLINE_LED)
{
  if (param.asInt())
  {
    led.on();
    timer.restartTimer(Master_online_timer);
  }
}

// Offline timer
void turnOFFLINE()
{
  led.off();
}

void setup()
{
 ....
 // 2-minute Timer
 Master_online_timer = timer.setInterval(120000L, turnOFFLINE);
 ...
}

The logic is as follows:

  1. The ONLINE LED is turned ON or getting GREEN color by the Master using BlynkTimer and virtualWrite() or setProperty() via bridge.

  2. This will trigger the Slave’s corresponding BLYNK_WRITE(), which in turn also resets the Slave Timer and/or setProperty() of the LED.

  3. That ONLINE LED is turned OFF or getting RED color by the Slave using direct control led.off() or setProperty() via a timeout function. The timeout value is reset periodically by the Master via bridge, so that if the Master is still alive, there will never be timeout, therefore no OFFLINE status.

Gotcha I will try that tomorrow