Reset Gauge

Hi,
I have 5 NodeMCU which sending sensorvalues to n Wemos D1 via Blynk-Bride to 5 Gaughs.
What i want to so, is reset the Gaugh to zero, if one of the NodeMcu´s went offline.

What i tried, but it only work, if Irestart the Wemos D1.

BLYNK_CONNECTED()
{
  Blynk.virtualWrite(V0, 0);
  Blynk.virtualWrite(V1, 0);
  Blynk.virtualWrite(V2, 0);
  Blynk.virtualWrite(V3, 0);
  Blynk.virtualWrite(V4, 0);
}

The BLYNK_CONNECTED callback function runs once, when the Wemos connects to Blynk, which is what happens after a reboot or a disconnection/reconnection to Blynk.

So, your code is working as expected.

Pete.

1 Like

Thanks, do you have n othert idea, maybe?

It depends on the type of sensor you’re using, what sort of error checking routine you’re doing when taking the readings, how you’re uploading them to Blynk etc.
Without info on your sensors ans seeing your full code, it’s impossible to say.

Pete.

1 Like

Detect IF the sensor is faulty/online, and THEN call the appropriate Blynk.virtualWrite(V0, 0);. But this is basically what @PeteKnight has already written, but with different words… :wink:

2 Likes

Maybe I explaned it wrong. The sensor isnt the problem, i want to reset the Gaugh if the NodeMcu went offline

As @marvin7 has said, you need to check what you are getting from your sensor and detect whether it is out of range, if it is then another device can detect it for you and set the gauge to 0.

As @PeteKnight has said also, without knowing what code you have and what sensors your are using, you know more than we do.

To answer your question if I understand, you want a default value of 0 to show when the device is offline - this isn’t an option that is available without coding it on your device(s).

Edit: after looking at your OP again, the Wemos needs to detect whether a new value has been sent to the device in the last x seconds/minutes/hours etc and if it doesn’t get a new value after your predetermined time, then just call a Blynk.virtualWrite(Vx, 0);

1 Like

Then I see no simple solution. The blynk server itself can’t change the value, but perhaps eventor could help?

2 Likes

But how do you expect us to tell you where within your code to put the required code unless you share your code with us?

Pete.

1 Like

@PeteKnight, the problem is (I guess) with changing the value to ZERO right after loosing the node. I think it is IMPOSSIBLE with just a simple client(hardware)-server-app config. It could be done, but with “extended” setup (for example with node red)

1 Like

Here is the code of one NodeMCU

float temperature = 0;
#define BLYNK_PRINT Serial
#define ONE_WIRE_BUS D4
#include <OneWire.h>
#include <DallasTemperature.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
WidgetBridge bridge1(V1);
BlynkTimer timer;

char auth[] = "Box1";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "Blubb";
char pass[] = "Blubb1";



  
BLYNK_CONNECTED() {
  bridge1.setAuthToken("Box5");
}
void blynkAnotherDevice() 
{
  sensors.requestTemperatures(); 
  temperature = sensors.getTempCByIndex(0);
  bridge1.virtualWrite(V0, temperature);
}
void setup()
{
  
  Serial.begin(9600);
  sensors.begin();
  timer.setInterval(1000L, blynkAnotherDevice);
  
  //Blynk.begin(auth, ssid, pass);
  Blynk.begin(auth, ssid, pass, IPAddress(xxx,xxx,xxx,xx), 8080);

  

  

}

void loop()
{
   
  if (Blynk.connected()){
  Blynk.run();}
  else
  {
  
  ESP.restart();

  }
  
  timer.run();
  
  {

And here the code of the Wemos



float temperature1 = 0;//Port V0
float temperature2 = 0;//Port V1
float temperature3 = 0;//Port V2
float temperature4 = 0;//Port V3
float temperature5 = 0;//Port V4

#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>


char auth[] = "Box5";
char ssid[] = "Blubb";
char pass[] = "Blubb1";
BlynkTimer timer;



//Thermometer--------------------------------------------------------------------------------------------------
BLYNK_WRITE(V0)
{
  temperature1 = param.asFloat();
}
BLYNK_WRITE(V1)
{
  temperature2 = param.asFloat();
}
BLYNK_WRITE(V2)
{
  temperature3 = param.asFloat();
}
BLYNK_WRITE(V3)
{
  temperature4 = param.asFloat();
}

BLYNK_WRITE(V4)
{
  temperature5 = param.asFloat();
}




void myTimerEvent()
{
  for (int i = 1; i <= 5; i++){
  int b = 0;
  b = (i);
Blynk.virtualWrite(V5, (i));
Serial.print("Sensor")
Serial.print(i);
Serial.print("--");


delay (1000);
if(b==1)
{
  if(temperature1 > 0)
  {
    Serial.println(temperature1);
  }
  
  else
  {
    Serial.println("Error");
  }
  
}  
else if(b==2)
{
  if(temperature2 > 0)
  {
    Serial.println(temperature2);
  }
  
  else
  {
    Serial.println("Error");
  }
  
}  
else if(b==3)
{
  if(temperature3 > 0)
  {
   Serial.println(temperature3);
  }
  
  else
  {
    Serial.println("Error");
  }
  
}  
else if(b==4)
{
  if(temperature4 > 0)
  {
    Serial.println(temperature4);
  }
  
  else
  {
    Serial.println("Error");
  }
  
}  
else if(b==5)
{
  if(temperature5 > 0)
  {
    Serial.println(temperature5);
  }
  
  
  else
  {
    Serial.println("Error");
  }
  
else
{}

}  

   
   
  delay(1000);
 }   
    
  
 
  


void setup()
{
  // Debug console
  Serial.begin(9600);
  //Blynk.begin(auth, ssid, pass);
  // You can also specify server:
  //Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 80);
  Blynk.begin(auth, ssid, pass, IPAddress(xxx,xxx,xxx,xx), 8080);
}


void loop()
{
  if (Blynk.connected()){
  Blynk.run();}
  else
  {
  
  ESP.restart();

  }
  
  timer.run();
  myTimerEvent();
}
 
  

That’s a novel approach to connection management!

So, your initial question was about what happens if a sensor stops working, which you later changed to say what happens if a NodeMCU stops working.
There are a variety of things that you could do, such as publishing a timestamp from each NodeMCU and reading these from the Wemos.

There was a topic some time ago about a failsafe system to monitor if/when a device goes offline. You might be able to find that if you do some searching.

Personally, with this many NodeMCUs I’d go for a Raspberry Pi running Node-Red and MQTT messaging to send the sensor readings to the Pi, then on to Blynk from there, you can then use Timeout nodes to ensure that regular readings are received from each NodeMCU and substitute zeros if any are missing (as well as sending notifications to alert you to the situation.

Pete.

1 Like

Device 1: (NodeMCU)

timer.setInterval(1000L, [](){
  static uint8_t heartbeat;
  heartbeat = !heartbeat;
  Blynk.virtualWrite(Vx, heartbeat);
});

Device 2: (Wemos?)

uint8_t heartbeat_device_1_error_counter;
uint8_t heartbeat_device_1;
uint8_t heartbeat_device_1_last;

BLYNK_WRITE(Vx)
{
  heartbeat_device_1 = param.asInt();
}

timer.setInterval(500L, [](){
  if (heartbeat_device_1 != heartbeat_deivce_1_last)
  {
    heartbeat_device_1_error_counter = 0;
    heartbeat_device_1_last = heartbeat_device_1;
  }
  if (heartbeat_device_1 == heartbeat_device_1_last) ++heartbeat_device_1_error_counter; // if last hearbeat doesn't match, increase counter
  if (heartbeat_device_1_error_counter >10) Blynk.virtualWrite(Vx, 0); // If device doesn't send a different heartbeat in approx. 5 seconds send a 0 to Vx pin
});

So on device 2, the error counter should stay around 2/3 most of the time because this device checks twice a second whereas the device sending the heartbeat only sends the heartbeat message once a second.

Side note: completely untested :crazy_face:

1 Like

That’s how I’m doing it :slight_smile:

2 Likes

EDIT VERSION 23.07.2019

It´s not that i thought about, but it works :rofl:

Blynk.virtualWrite(V5, (i));
Serial.print("Sensor")
Serial.print(i);
Serial.print("--");


delay (1000);
if(b==1)
{
  if(temperature1 > 0)
  {
    Serial.println(temperature1);
  }
  
  else if(temperature1 == 0)
  {
    Serial.println("Error");
  }
  else{}
}  
else if(b==2)
{
  if(temperature2 > 0)
  {
    Serial.println(temperature2);
  }
  
   else if(temperature2 == 0)
  {
    Serial.println("Error");
  }
  else{}
}  
else if(b==3)
{
  if(temperature3 > 0)
  {
   Serial.println(temperature3);
  }
  
   else if(temperature3 == 0)
  {
    Serial.println("Error");
  }
  else{}
}  
else if(b==4)
{
  if(temperature4 > 0)
  {
    Serial.println(temperature4);
  }
  
   else if(temperature4 == 0)
  {
    Serial.println("Error");
  }
  else{}
}  
else if(b==5)
{
  if(temperature5 > 0)
  {
    Serial.println(temperature5);
  }
  
  
   else if(temperature5 == 0)
  {
    Serial.println("Error");
  }
  else{}
else
{}

}  
  delay(500);
Blynk.virtualWrite(V0, temperature1 = 0);
Blynk.virtualWrite(V1, temperature2 = 0);
Blynk.virtualWrite(V2, temperature3 = 0);
Blynk.virtualWrite(V3, temperature4 = 0);
Blynk.virtualWrite(V4, temperature5 = 0); 
   
  delay(500);
 }   
1 Like

You still need to get rid of those delay()s though :wink:

1 Like