HELP No bridge connection and automatic slave device restart

Hi, I’m sending a reading on virtual pin from device (master) arduino nano + esp8266 to a device (slave) Nodemcu where an LCD1602 display is connected, everything works perfectly the value is shown on the display, but if I disconnect the master device on the slave the last parameter before switching off is displayed.
How can I check if the master device does not send the value and the slave automatically restarts until the connection is made ???

Thanks

I think the way that I’d do it would be to send the current millis() value from what you refer to as the master device to the slave device, on a separate virtual pin, each time the current data is sent.
On the receiving device (slave as you call it) I’d store the last millis() value received and have a timer to see if it had changed.
If you are sending data readings via Bridge every 5 seconds then the timer that checks if the millis() value has changed would run less frequently - maybe every 10 seconds.

The part of your question that I don’t understand is your desire to keep restarting the slave device until the master starts sending values again.
If the communication failure is down to the master device being offline, or not taking data readings from your sensor, then it’s the master device that you would want to restart.
What you would normally do is to update the LCD display to clear the last reading received, so that you aren’t displaying outdated readings.

Each device (both master and slave) should have code which regularly checks the Blynk connection and reconnects if necessary, which should remove the need to reboot either device.

Pete.

I will try something through timer and virtualpin in order to signal to the receiving device the status of a pin, like if the virtual pin 2 is LOW restart in the receiver.

in the receiver the value is stored in the variable “int Level”

 int Level;

BLYNK_WRITE (V0) {
  Level = param.asInt (); }

void myTimerEvent () {
  lcd.clear ();
  lcd.setCursor (0, 0);
  lcd.print ("Water Level");
  lcd.print (Level);
  lcd.print ("%");
}

as for the restart, if I turn off the main power or there is a communication problem, the value remains stored in the receiver, creating obsolete readings, instead I want that if it does not receive data the value on the display is deleted or the device restarts to signal the main is off or there is something wrong.

@seby please edit your post, using the pencil icon at the bottom, and add triple backticks at the beginning and end of your code so that it displays correctly.
Triple backticks look like this:
```

Pete.

Personally, I’d display something like “- - -“ to indicate an invalid value rather than displaying zero, 999 or something similar.

Pete.

Sure it is better to display “—” otherwise with 0 it is not very reliable, I’m trying this way but I still don’t get good results because when I send bridge1.digitalWrite (13, HIGH); the pin remains high even after the main device is turned off …

on the main:

void blynkAnotherDevice () {
  bridge1.virtualWrite (V0, Level);
  bridge1.digitalWrite (13, HIGH);}


on the receiver

BLYNK_WRITE (V0) {
  Level = param.asInt (); }

void myTimerEvent () {
 digitalWrite (D7, LOW);
  lcd.clear ();
  lcd.setCursor (0, 0);
  lcd.print ("Water Level");
  lcd.print (Level);
  lcd.print ("%");
}

void ping () {
   pingpin = digitalRead (D7);
   if (pingpin == LOW) {
   lcd.clear ();
   lcd.print "Offline"}
  }

You should use a virtual pin.

Pete.

I solved in this way, I still have to perfect something but so we are already here,

main board

void blynkAnotherDevice () {
  bridge1.digitalWrite (13, HIGH); //D7 pin Nodemcu
  }


secondary


 int count = 0;
   
  void test () {
  int value = 0;
  value = digitalRead (D7);
  Serial.println (value);
  if (digitalRead (D7) == HIGH) {
  Serial.println (count);
  count = 0;
  digitalWrite (D7, LOW);}
  if (digitalRead (D7) == LOW) {
  Serial.println (count);
  count ++;
  }
   
  if (count> = 10) {
  lcd.clear ();
  lcd.setCursor (0, 0);
  lcd.print ("CONTAINER WATER");
  lcd.setCursor (0, 1);
  lcd.print ("Level:");
  lcd.print ("ERROR");}
  while (count> = 20) {ESP.restart (); }
  }

Thanks .

Looks like a very messy solution to me.

How is void test being called in your secondary sketch?

Pete.

yes in fact I do not like it very much but it works perfectly. Through blynk timer, call void test.

in setup

timer.setInterval (2000L, test);