# How to detect when a Modbus value becomes stale?

**URL:** <https://discourse.nodered.org/t/how-to-detect-when-a-modbus-value-becomes-stale/65375>\
**Category:** Industrial\
**Created:** [20 July 2022 15:25 UTC](https://discourse.nodered.org/t/how-to-detect-when-a-modbus-value-becomes-stale/65375 "2022-07-20T15:25:07Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![grant1](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/grant1/32/49890_2.png) [@grant1](https://discourse.nodered.org/u/grant1)\
**Post date:** [20 July 2022 15:25 UTC](https://discourse.nodered.org/t/how-to-detect-when-a-modbus-value-becomes-stale/65375/1 "2022-07-20T15:25:07Z")

</div>

I have a simple flow (pasted below, screenshot as well) that grabs Modbus data for a variable frequency drive (VFD) every 30 seconds via Modbus-TCP. Works great, however...

Yesterday we saw this in Influx:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/d/ddc467041f45ff1fffda5d9adfc3f2893086379b.png)

We have since confirmed via our electrical usage data that the VFD was OFF (for reasons that are unknown at the moment). The problem is that Node-RED seems to have retained the last known value (62.93, taken about 15:52) and kept sending that value to InfluxDB until the VFD came back online about 21:20. This appears as a flat line at 62.93, but we really expected to see 0.

Is there a clever way for me to prevent this "stale" value from being sent to InfluxDB? I do not have Node-RED logs for this period shown.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/b/5b4e1966df64ec9bfdaaad9ec01efa63c1baf4a4.png)

```auto
[{"id":"8a7d4c278f437686","type":"modbus-read","z":"9cb29d33.c5004","name":"Read Data on 30 Quench Pump VFD","topic":"","showStatusActivities":false,"logIOActivities":false,"showErrors":false,"unitid":"255","dataType":"HoldingRegister","adr":"200","quantity":"3","rate":"30","rateUnit":"s","delayOnStart":false,"startDelayTime":"","server":"d99cd9271877f6fc","useIOFile":false,"ioFile":"","useIOForPayload":false,"emptyMsgOnFail":false,"x":230,"y":1460,"wires":[["f480dd6ce0645ebe"],[]]},{"id":"f480dd6ce0645ebe","type":"function","z":"9cb29d33.c5004","name":"","func":"msg.payload = [\n [{\n RotationalSpeed: msg.payload[0]/100,\n },\n {\n MeasType:\"setpoint\",\n EquipElement:\"quenchpump\",\n EquipNumber:\"30\"\n }],\n [{\n ElectricalCurrent: msg.payload[1]/100,\n },\n {\n MeasType:\"actual\",\n EquipElement:\"quenchpump\",\n EquipNumber:\"30\"\n }],\n [{\n ElectricalVoltage: msg.payload[2]/10,\n },\n {\n MeasType:\"actual\",\n EquipElement:\"quenchpump\",\n EquipNumber:\"30\"\n }]\n];\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":620,"y":1460,"wires":[["25a2db017b2ae3ed"]]},{"id":"25a2db017b2ae3ed","type":"influxdb out","z":"9cb29d33.c5004","influxdb":"a5483d9bc0c8a1db","name":"Influx","measurement":"DoubleRotaryFurnaceElementData","precision":"","retentionPolicy":"","database":"database","precisionV18FluxV20":"ms","retentionPolicyV18Flux":"","org":"heattreat","bucket":"AMPdata","x":850,"y":1460,"wires":[]},{"id":"d99cd9271877f6fc","type":"modbus-client","name":"Mitsubishi 30HP VFD for #30 Quench Pump","clienttype":"tcp","bufferCommands":true,"stateLogEnabled":false,"queueLogEnabled":false,"tcpHost":"192.168.10.51","tcpPort":"502","tcpType":"DEFAULT","serialPort":"/dev/ttyUSB","serialType":"RTU-BUFFERD","serialBaudrate":"9600","serialDatabits":"8","serialStopbits":"1","serialParity":"none","serialConnectionDelay":"100","unit_id":"1","commandDelay":"1","clientTimeout":"1000","reconnectOnTimeout":true,"reconnectTimeout":"2000","parallelUnitIdsAllowed":true},{"id":"a5483d9bc0c8a1db","type":"influxdb","hostname":"127.0.0.1","port":"8086","protocol":"http","database":"database","name":"","usetls":false,"tls":"","influxdbVersion":"2.0","url":"http://192.168.10.25:8086","rejectUnauthorized":false}]

```

---

<div class="post-metadata">

**Author:** ![ghayne](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ghayne/32/39_2.png) [@ghayne](https://discourse.nodered.org/u/ghayne)\
**Post date:** [20 July 2022 15:41 UTC](https://discourse.nodered.org/t/how-to-detect-when-a-modbus-value-becomes-stale/65375/2 "2022-07-20T15:41:06Z")

</div>

No, InfluxDB just connects the valid data points.  
If you look at the raw data you will understand. It's not node-red sending the value repeatedly.

---

<div class="post-metadata">

**Author:** ![grant1](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/grant1/32/49890_2.png) [@grant1](https://discourse.nodered.org/u/grant1)\
**Post date:** [20 July 2022 16:01 UTC](https://discourse.nodered.org/t/how-to-detect-when-a-modbus-value-becomes-stale/65375/3 "2022-07-20T16:01:24Z")

</div>

Thanks @ghayne . Looking at my raw data in InfluxDB (excerpt below) indicates the stale value (62.93) was being populated every 30 sec., beginning about 19:48:54.21. Given my simple flow, I have to believe InfluxDB was getting this value from Node-RED repeatedly.

| \_time | \_value |
| --- | --- |
| 2022-07-19T19:45:24.21Z | 63.14 |
| 2022-07-19T19:45:54.212Z | 63.03 |
| 2022-07-19T19:46:24.209Z | 63.01 |
| 2022-07-19T19:46:54.213Z | 62.93 |
| 2022-07-19T19:47:24.21Z | 63.01 |
| 2022-07-19T19:47:54.211Z | 62.95 |
| 2022-07-19T19:48:24.209Z | 62.88 |
| 2022-07-19T19:48:54.21Z | 62.93 |
| 2022-07-19T19:49:24.212Z | 62.93 |
| 2022-07-19T19:49:54.209Z | 62.93 |
| 2022-07-19T19:50:24.209Z | 62.93 |
| 2022-07-19T19:50:54.212Z | 62.93 |
| 2022-07-19T19:51:24.211Z | 62.93 |
| 2022-07-19T19:51:54.209Z | 62.93 |
| 2022-07-19T19:52:24.21Z | 62.93 |
| 2022-07-19T19:52:54.212Z | 62.93 |

---

<div class="post-metadata">

**Author:** ![ghayne](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ghayne/32/39_2.png) [@ghayne](https://discourse.nodered.org/u/ghayne)\
**Post date:** [20 July 2022 16:09 UTC](https://discourse.nodered.org/t/how-to-detect-when-a-modbus-value-becomes-stale/65375/4 "2022-07-20T16:09:25Z")

</div>

Looks like you will have to find a way of detecting "stale" values then. The graph would however, still look the same 🙂

---

<div class="post-metadata">

**Author:** ![ghayne](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ghayne/32/39_2.png) [@ghayne](https://discourse.nodered.org/u/ghayne)\
**Post date:** [20 July 2022 16:16 UTC](https://discourse.nodered.org/t/how-to-detect-when-a-modbus-value-becomes-stale/65375/5 "2022-07-20T16:16:22Z")

</div>

Is there no way to check for valid data within the Modbus node?

---

<div class="post-metadata">

**Author:** ![grant1](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/grant1/32/49890_2.png) [@grant1](https://discourse.nodered.org/u/grant1)\
**Post date:** [20 July 2022 16:27 UTC](https://discourse.nodered.org/t/how-to-detect-when-a-modbus-value-becomes-stale/65375/6 "2022-07-20T16:27:41Z")

</div>

I can set up an alert / alarm in Influx or Grafana to detect this sort of "value cannot repeat more than n times" situation. But I prefer to do it in Node-RED. For the [modbus-read node](https://flows.nodered.org/node/node-red-contrib-modbus) that I am using, I do not see any way for the node to check for valid data. It just seems to keep sending the value that was reported as soon as the VFD shut down. I was thinking some sort of additional node to check for a repeating value of say, 5 times (or 2.5 minutes of the same value, which should never happen). I could then send out an alert or something, or send a null value to Influx (which would then be detectable in Grafana).

---

<div class="post-metadata">

**Author:** ![ghayne](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ghayne/32/39_2.png) [@ghayne](https://discourse.nodered.org/u/ghayne)\
**Post date:** [20 July 2022 16:59 UTC](https://discourse.nodered.org/t/how-to-detect-when-a-modbus-value-becomes-stale/65375/7 "2022-07-20T16:59:14Z")

</div>

Have a look at the filter node!

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [20 July 2022 19:21 UTC](https://discourse.nodered.org/t/how-to-detect-when-a-modbus-value-becomes-stale/65375/8 "2022-07-20T19:21:38Z")

</div>

Do you mean that the VFD was powered down, but the modbus node kept providing data?  
You said that you were not sure what was going on at that time, are you sure it was actually powered down rather than not driving the connected system (hence no power usage) but in some fault mode where it was still saying, via modbus, that it was going? If you want to check it then power the drive down and see what happens. The modbus node should go into a fail state when the device is powered down.

**[Edit]** Or could it be something like the thing being driven had no power, but the VFD was still powered and thought that the drive was still going?

---

<div class="post-metadata">

**Author:** ![grant1](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/grant1/32/49890_2.png) [@grant1](https://discourse.nodered.org/u/grant1)\
**Post date:** [20 July 2022 20:04 UTC](https://discourse.nodered.org/t/how-to-detect-when-a-modbus-value-becomes-stale/65375/9 "2022-07-20T20:04:46Z")

</div>

@Colin So at this point, the details are still a bit sketchy, but acc. to one of the few people working when this happened, he saw a code on [the VFD](https://dl.mitsubishielectric.com/dl/fa/document/manual/inv/ib0600547eng/ib0600547engf.pdf) that said began with "E", but that could be a lot of things....

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/7/4751d9a542d5953ff4adcd04095c4a0af1f378b8.png)

We are fairly certain that:

1. The VFD was never powered down during any part of the time window where it appears flat-lined
2. The motor (which turns a pump) was almost certainly not running during this time window, because our plant-wide electricity dropped by nearly the exact amount of kwH that the VFD/motor uses.

We also noticed that the voltage increased from ~185V to ~188V about 2 hours before the unit went off. The temperature in the plant was hot at that time (about like London yesterday, although we are nowhere near there).

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/b/0b6d5e8aa01147961bfc71a1a26b2ecc4f9751fd.png)

We will do as you suggest, i.e. power down the drive and see what the Modbus node transmits. At this point, I believe the VFD was powered up, but not driving the connected system (hence no power usage) and in some fault mode where it was still saying, via modbus, that it was going. Maybe we can use the Modbus register to detect this condition in the future.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [20 July 2022 20:38 UTC](https://discourse.nodered.org/t/how-to-detect-when-a-modbus-value-becomes-stale/65375/10 "2022-07-20T20:38:01Z")

</div>

If the VFD keeps reporting a good value via modbus there is not much you can do in node-red, unless, for example, you could use the fact that it is absolutely constant for a while as a fault indicator.

Possibly one of the modbus registers indicates the health of the system in some way that you could use to know that a fault has occurred.

Otherwise, if it is important that you know whether the pump was actually turning or not, then connect a sensor of some sort that tells you that. A pressure sensor measuring what is being pumped, or a current sensor checking the power being drawn, or an electromechanical device of some sort that indicates rotation, for example.

---

<div class="post-metadata">

**Author:** ![grant1](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/grant1/32/49890_2.png) [@grant1](https://discourse.nodered.org/u/grant1)\
**Post date:** [20 July 2022 20:56 UTC](https://discourse.nodered.org/t/how-to-detect-when-a-modbus-value-becomes-stale/65375/11 "2022-07-20T20:56:55Z")

</div>

Thank you, those are all very good paths to follow. I am going to try to alarm if/when the electrical current value flatlines (probably using an Influx query in Grafana's new alerting system), or use the RBE node, or both. We do not have any digital pressure sensors or flow meters, but am sure getting something simple installed would not break the bank.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [18 September 2022 20:57 UTC](https://discourse.nodered.org/t/how-to-detect-when-a-modbus-value-becomes-stale/65375/12 "2022-09-18T20:57:09Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
