# Best method to detect when RS-485 Modbus/RTU devices is offline

**URL:** <https://discourse.nodered.org/t/best-method-to-detect-when-rs-485-modbus-rtu-devices-is-offline/64615>\
**Category:** General\
**Tags:** modbus\
**Created:** [2 July 2022 19:12 UTC](https://discourse.nodered.org/t/best-method-to-detect-when-rs-485-modbus-rtu-devices-is-offline/64615 "2022-07-02T19:12:05Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![hobbes1069](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hobbes1069/32/39892_2.png) [@hobbes1069](https://discourse.nodered.org/u/hobbes1069)\
**Post date:** [2 July 2022 19:12 UTC](https://discourse.nodered.org/t/best-method-to-detect-when-rs-485-modbus-rtu-devices-is-offline/64615/1 "2022-07-02T19:12:05Z")

</div>

I have a Tulip Edge IO device connected to a Yokogawa oven controller via RS-485 and Node-RED.

As long as the oven is turned on I'm having very good success polling the controller. As the lab turns the oven off at the end of the day I need a way to reliably detect when the controller is off.

I can try using the states but that cycles through as reconnect attempts are made.

Anyone have a better idea?

---

<div class="post-metadata">

**Author:** ![craigcurtin](https://avatars.discourse-cdn.com/v4/letter/c/94ad74/32.png) [@craigcurtin](https://discourse.nodered.org/u/craigcurtin)\
**Post date:** [3 July 2022 05:29 UTC](https://discourse.nodered.org/t/best-method-to-detect-when-rs-485-modbus-rtu-devices-is-offline/64615/2 "2022-07-03T05:29:19Z")

</div>

Could you not hook something into the power circuit to tell you when the oven was energized ?

Or a CT clamp on the circuit that feeds the oven ?

Failing that there would be a time differential i would imagine between a successful read and a failed read/timeout because the device is offline - would be worth doing some testing

So

1. Start time tracker
2. perform read
3. End time tracker

Compare the times for a succesful read as against a failed read and see if there is a noticeable and reproducible difference

Craig

---

<div class="post-metadata">

**Author:** ![hobbes1069](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hobbes1069/32/39892_2.png) [@hobbes1069](https://discourse.nodered.org/u/hobbes1069)\
**Post date:** [3 July 2022 13:15 UTC](https://discourse.nodered.org/t/best-method-to-detect-when-rs-485-modbus-rtu-devices-is-offline/64615/3 "2022-07-03T13:15:35Z")

</div>

Yeah, I was just seeing if there was a slick way to handle this using the Modbus/RTU handling.

The controller has outputs so there's a good chance there's one for monitoring whether it's up or not, but that would require removing it from the oven to access the terminals whereas I can toy with the NodeRED remotely 🙂

---

<div class="post-metadata">

**Author:** ![craigcurtin](https://avatars.discourse-cdn.com/v4/letter/c/94ad74/32.png) [@craigcurtin](https://discourse.nodered.org/u/craigcurtin)\
**Post date:** [4 July 2022 00:22 UTC](https://discourse.nodered.org/t/best-method-to-detect-when-rs-485-modbus-rtu-devices-is-offline/64615/4 "2022-07-04T00:22:06Z")

</div>

Yep so try measuring the timeout on the query and see if that is a repeatable/measureable number with the unit on and off

Craig

---

<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:** [4 July 2022 06:33 UTC](https://discourse.nodered.org/t/best-method-to-detect-when-rs-485-modbus-rtu-devices-is-offline/64615/5 "2022-07-04T06:33:17Z")

</div>

What status values does the node provide when the device is off?

---

<div class="post-metadata">

**Author:** ![hobbes1069](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hobbes1069/32/39892_2.png) [@hobbes1069](https://discourse.nodered.org/u/hobbes1069)\
**Post date:** [4 July 2022 13:26 UTC](https://discourse.nodered.org/t/best-method-to-detect-when-rs-485-modbus-rtu-devices-is-offline/64615/6 "2022-07-04T13:26:32Z")

</div>

This seems to be the general flow of the connection attempts:

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

---

<div class="post-metadata">

**Author:** ![hobbes1069](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hobbes1069/32/39892_2.png) [@hobbes1069](https://discourse.nodered.org/u/hobbes1069)\
**Post date:** [4 July 2022 13:37 UTC](https://discourse.nodered.org/t/best-method-to-detect-when-rs-485-modbus-rtu-devices-is-offline/64615/7 "2022-07-04T13:37:26Z")

</div>

I added picking up `msg.status.text = failure` which seems to work. Now I just need to wait until someone turns the oven on tomorrow to see what text is sent for success!

---

<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:** [4 July 2022 15:32 UTC](https://discourse.nodered.org/t/best-method-to-detect-when-rs-485-modbus-rtu-devices-is-offline/64615/8 "2022-07-04T15:32:18Z")

</div>

Assuming you are using the Getter node then, for me at least, it is `"reading done"`

---

<div class="post-metadata">

**Author:** ![UnborN](https://avatars.discourse-cdn.com/v4/letter/u/4491bb/32.png) [@UnborN](https://discourse.nodered.org/u/UnborN)\
**Post date:** [4 July 2022 21:50 UTC](https://discourse.nodered.org/t/best-method-to-detect-when-rs-485-modbus-rtu-devices-is-offline/64615/9 "2022-07-04T21:50:17Z")

</div>

Hello Richard .. instead of the **states** i used in my modbus project the option in the Modbus nodes  
to send an empty msg on fail. (fail in this case would be the device being switched off and not replying to requests)

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

With this option checked i still get a msg from the mod. nodes that i later handle with a Function node after it.

```auto
if (msg.payload == "" || msg.hasOwnProperty('error')) {
// handle error
}

```

---

<div class="post-metadata">

**Author:** ![hobbes1069](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hobbes1069/32/39892_2.png) [@hobbes1069](https://discourse.nodered.org/u/hobbes1069)\
**Post date:** [5 July 2022 12:45 UTC](https://discourse.nodered.org/t/best-method-to-detect-when-rs-485-modbus-rtu-devices-is-offline/64615/10 "2022-07-05T12:45:59Z")

</div>

That's an interesting method. I may convert to that, and I can even use a switch node instead.

Because this is for work I tend to use the simplest method that works because you never know who's coming behind you.

---

<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:** [5 July 2022 12:59 UTC](https://discourse.nodered.org/t/best-method-to-detect-when-rs-485-modbus-rtu-devices-is-offline/64615/11 "2022-07-05T12:59:43Z")

</div>

Is not it simpler to use the status node?

---

<div class="post-metadata">

**Author:** ![hobbes1069](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hobbes1069/32/39892_2.png) [@hobbes1069](https://discourse.nodered.org/u/hobbes1069)\
**Post date:** [5 July 2022 13:53 UTC](https://discourse.nodered.org/t/best-method-to-detect-when-rs-485-modbus-rtu-devices-is-offline/64615/12 "2022-07-05T13:53:34Z")

</div>

If you're an expert user then probably, because you understand what it does. For a more novice user the fact there's no connection to the Modbus getter node it could be confusing.

---

<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:** [5 July 2022 14:01 UTC](https://discourse.nodered.org/t/best-method-to-detect-when-rs-485-modbus-rtu-devices-is-offline/64615/13 "2022-07-05T14:01:18Z")

</div>

Why would there be no connection to the modbus node? Presumably when it is working you send the output somewhere. If you position the modbus and status nodes immediately one above the other then when there is good data it comes out of the modbus node, and when it fails the error comes out from a switch node following the status node. Give the status node a name such as Modbus Status and it should be clear what is going on. However if using the blank payload to split the flow into good data and failure fits your needs better then that is fine.

---

<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:** [3 September 2022 14:01 UTC](https://discourse.nodered.org/t/best-method-to-detect-when-rs-485-modbus-rtu-devices-is-offline/64615/14 "2022-09-03T14:01:49Z")

</div>

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