I now have 5 nodeMCUs in production and wanted a better way to know they are working. I reverted to an old school heartbeat.
First I created an input on each node and that created a HS3 device. I set them for value and string. They are device 5 in my case.
Then I added the following code to the sketches for each node.
The HS3 device changes the timestamp every 5 minutes if the node is working properly. I can test against that timestamp in events as well as report the status of each node on my HSTouch application.
First I created an input on each node and that created a HS3 device. I set them for value and string. They are device 5 in my case.
Then I added the following code to the sketches for each node.
The HS3 device changes the timestamp every 5 minutes if the node is working properly. I can test against that timestamp in events as well as report the status of each node on my HSTouch application.
Code:
int Heartbeat = 5; // virtual device for heartbeat logging. Set it to the PI Board device or zero if not used // Heartbeat Variables unsigned long HeartbeatCurrentMillis = 0; unsigned long HeartbeatPreviousMillis = 0; // ************** Start Heartbeat **************** // ***** Updates a virtual heartbeat device **** // ***** timestamp in HS3 once every 5 minutes **** if (Heartbeat) { if (HeartbeatCurrentMillis == 0) { // first time since startup SendToHS(Heartbeat,0); // toggle device to get timestamp to update SendToHS(Heartbeat,100); HeartbeatPreviousMillis = millis(); } HeartbeatCurrentMillis = millis(); if ((HeartbeatCurrentMillis - HeartbeatPreviousMillis) > (5 * 60 * 1000)) { // update every 5minutes SendToHS(Heartbeat,0); // toggle device to get timestamp to update SendToHS(Heartbeat,100); HeartbeatPreviousMillis = millis(); } } // ************** End Heartbeat ****************
Comment