I am building a thermostat project that consists of 2 nodemcu connected to blynk.
Both nodemcu work on the same project.
First nodemcu (Node1) is gathering temperature from a room and uploads it to cloud blynk server.
Second nodemcu (Node 2) opens a relay depending on temperature gathered from the first one.
My problem is that I would like to know in the code of “node 2” if “node 1” is online.
I do not want that “node 2” opens or closes the relay if “node 1” is not connected.
With s Bridge widget you can communicate between your devices. So, you can implement your own heartbeat mechanism (i.e. periodically send value from node1 to node2, node2 registers time last value received)
Thanks Eugene.
This is what I was thinking also.
I think that Node 1 would update a virtual pin periodically and node 2 would read it from time to time.
on device2 side,
if “device2” receive a new number, this means “device1” is working.
if the number does not change, this means “device1” is not working.
int Heartbeat = 0;
int HeartbeatV = 0;
bool HeartbeatHealt = true;
BLYNK_WRITE(V6) {
Heartbeat = param.asInt(); // pinData variable will store value that came via Bridge
Serial.println(Heartbeat);
}
void loop()
{
if (currentMillis - previousMillis2 >= interval2) { //every 2.5 seconds (in case of delay, this time value should bigger than device1's time value )
previousMillis2 = currentMillis;
if (Heartbeat != HeartbeatV) {
HeartbeatV = Heartbeat;
HeartbeatHealt = true;
Serial.println("Dont Stop");
} else {
HeartbeatHealt = false;
Serial.println("Stop");
}
if (HeartbeatHealt == false) {
Serial.println("Turn Off Relay");
}
If you check the docs you’ll see that they suggest to leave the main loop as clean as possible… so… it’s up to you if you want to follow the specs or do it your way.
Oh, my post was meant if you want to use Blynk, otherwise it’s OK if you do it your way.
Aside from responding to a year old topic Please watch the time date stamps before posting, any answers over a couple of months is likely no longer relevant.
Not for bog standard Arduino coding. But because Blynk is an IoT App, and thus needs constant communication access… hogging the void loop() with code tends to lead to server disconnections, and with ESP8266, possible WDT issues. The solution is to split up your code into separate and quickly timed jobs, leaving the void loop() and subsequent background tasks in the Blynk library and ESP8266 WiFi control, free to maintain connection.