# Problem to display state from device

**URL:** <https://discourse.nodered.org/t/problem-to-display-state-from-device/22484>\
**Category:** General\
**Created:** [2 March 2020 08:48 UTC](https://discourse.nodered.org/t/problem-to-display-state-from-device/22484 "2020-03-02T08:48:32Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![jan-k](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jan-k/32/17738_2.png) [@jan-k](https://discourse.nodered.org/u/jan-k)\
**Post date:** [2 March 2020 08:48 UTC](https://discourse.nodered.org/t/problem-to-display-state-from-device/22484/1 "2020-03-02T08:48:32Z")

</div>

Greetings,

I am still fresh to the Node Red, seeking for some help for displaying the status of my S7-1200 PLC with the node-red-contrib-ui-state-trail.  
It can be display when the S7 is sending value, so I am able to use a change node to change the integer value to boolean for display On.  
But I wonder how to display for the S7 off status, because when I tried to disconnect my S7, I can't get any value from it, only the debug message showing msg : string[20] "Failure (Bad values)".  
So, I would like get any solution or method for me to achieve my objective.  
Thank you in advance.

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

Best Regards.

---

<div class="post-metadata">

**Author:** ![unixneo](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/unixneo/32/17441_2.png) [@unixneo](https://discourse.nodered.org/u/unixneo)\
**Post date:** [2 March 2020 12:14 UTC](https://discourse.nodered.org/t/problem-to-display-state-from-device/22484/2 "2020-03-02T12:14:28Z")

</div>

> [@jan-k](#):
>
> "Failure (Bad values)".

You can use a CHANGE node with a REGEX to match this string (above) and change it to `false`, if that is the message you getting, for example.

---

<div class="post-metadata">

**Author:** ![jan-k](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jan-k/32/17738_2.png) [@jan-k](https://discourse.nodered.org/u/jan-k)\
**Post date:** [3 March 2020 01:23 UTC](https://discourse.nodered.org/t/problem-to-display-state-from-device/22484/3 "2020-03-03T01:23:05Z")

</div>

Hi unixneo,

Thanks for your suggestion, I would like to try with your method. But the error message on debug message not come from any node. (I try to put debug node on every node, but didn't get any output.) So, I wonder which type of the input for REGEX match in a switch node in order to get for the error string, such as msg.payload/flow.payload/global.payload etc 🤐

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

Best Regards.

---

<div class="post-metadata">

**Author:** ![unixneo](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/unixneo/32/17441_2.png) [@unixneo](https://discourse.nodered.org/u/unixneo)\
**Post date:** [3 March 2020 03:29 UTC](https://discourse.nodered.org/t/problem-to-display-state-from-device/22484/4 "2020-03-03T03:29:05Z")

</div>

Honestly, netsuko93 ... it is hard to understand what you are debugging, where and when and how.

It's best to work in a simple, step-by-step manner when debugging (not put debug nodes on every node, as you said).

In your diagram, your first node is labeled "`S7-1200 Read`" and that node nodes "`failure`".

So, you should turn off all the other debug nodes (for now) and only put one debug node at the output of that single "`S7-1200 Read`" node, and make sure the debug node is for the entire message object (not just the payload).

Then, you can easily see the entire msg object and what are the strings and stats the "`S7-1200 Read`" node fails (and of course, when it succeeds). Then, post that output clearly (not just a screenshot) between "code tags" so we can easily read it, clearly and precisely.

Normally, as I am sure you realize, when we have an issue the best place to start is "at the beginning" in a step-by-step, logical manner. It often sounds strange, but usually the fastest way to solve a problem is to go in a slow, step-by-step way, starting with the first message object.

---

<div class="post-metadata">

**Author:** ![jan-k](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jan-k/32/17738_2.png) [@jan-k](https://discourse.nodered.org/u/jan-k)\
**Post date:** [3 March 2020 03:55 UTC](https://discourse.nodered.org/t/problem-to-display-state-from-device/22484/5 "2020-03-03T03:55:41Z")

</div>

Dear unixneo,

Thanks for your advise, actually my boss ask me to implement a dashboard to show the machine run time by using the Node Red and I tried to put the state ON when it receive value from the S7-1200 device, but I realized it didn't send any value when I tried to disconnect it for trying to display the state OFF.  
So, now I start from the beginning with only S7-1200 Read node and debug node. But I not sure which is the tag code, but I tried to expand it. Hopefully you can see clearly. 😣

1. Image below shows the "msg.payload" [success without failure]  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/4/d4ea0ec3625e3690a28cb21f85d72a24b3641aae.png)
2. Image below shows the "complete msg object" [success without failure]  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/3/137dada48051551b0b1bc4af030b3813ec5ccc67.png)
3. Image below shows the "`complete msg object`" [disconnected failure]  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/2/62d9827ab7560de179041e3f63f200cb6e03886d.png)  
I'm struggled with this problem. 😕

Best Regards.

---

<div class="post-metadata">

**Author:** ![unixneo](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/unixneo/32/17441_2.png) [@unixneo](https://discourse.nodered.org/u/unixneo)\
**Post date:** [3 March 2020 03:57 UTC](https://discourse.nodered.org/t/problem-to-display-state-from-device/22484/6 "2020-03-03T03:57:04Z")

</div>

You should change the debug node on `failure` to show the entire msg object, not only the `msg.payload`.

Generally, when debugging, it is best to show the entire msg object, especially when you want to build a `SWITCH` or `CHANGE` node; but in general, debug with the **entire msg object** (especially when you are "struggling" to find "causes" and potential solutions).

---

<div class="post-metadata">

**Author:** ![jan-k](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jan-k/32/17738_2.png) [@jan-k](https://discourse.nodered.org/u/jan-k)\
**Post date:** [3 March 2020 04:15 UTC](https://discourse.nodered.org/t/problem-to-display-state-from-device/22484/8 "2020-03-03T04:15:10Z")

</div>

> [@jan-k](#):
>
> Image below shows the " `msg.payload` " [disconnected failure]
> 
> ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/2/62d9827ab7560de179041e3f63f200cb6e03886d.png)

Hmmm...The output display I get for both of msg.payload and entire msg object is the same.  
Image below shows the " `entire msg object` " [disconnected failure]

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

---

<div class="post-metadata">

**Author:** ![unixneo](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/unixneo/32/17441_2.png) [@unixneo](https://discourse.nodered.org/u/unixneo)\
**Post date:** [3 March 2020 04:23 UTC](https://discourse.nodered.org/t/problem-to-display-state-from-device/22484/9 "2020-03-03T04:23:05Z")

</div>

Great.

So, you can easily add a `SWITCH` node to switch based on a number of ideas and add the `OTHERWISE` node for the exceptions.

If it was me, I would try to first `SWITCH` on `msg.payload` perhaps using `contains` or `has key` but the choice is yours (based on what you want to switch on) and `SWITCH` `OTHERWISE` and you are done, with a little bit of testing.

For example (but you should experiment on your own to learn, based on how you want to switch between true and false, etc):

![Screen Shot 2020-03-03 at 11.25.20 AM](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/0/f0eb9b2b74959d8d8539de52991cedddace1d0d0.jpeg)

You should be "good to go" with this information. Try first and enjoy Node-RED where:

`"Logic Transforms into Art and Beauty"` 🙂

(just made that up, but is sounds about right, LOL)

---

<div class="post-metadata">

**Author:** ![kuema](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/kuema/32/6542_2.png) [@kuema](https://discourse.nodered.org/u/kuema)\
**Post date:** [3 March 2020 07:38 UTC](https://discourse.nodered.org/t/problem-to-display-state-from-device/22484/10 "2020-03-03T07:38:52Z")

</div>

After looking at your screenshots and data, I don't think your `S7 Read` node does send anything at all because it likely throws an error. The `debug` won't get any messages in this case, and any `switch` based on that won't work either.

So, try adding a `catch` node, select the `S7` node as target and wire a `debug` node to that catch node in "complete msg" mode.

Here's more documentation on how to handle errors properly:

[https://nodered.org/docs/user-guide/handling-errors](https://nodered.org/docs/user-guide/handling-errors)

---

<div class="post-metadata">

**Author:** ![jan-k](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jan-k/32/17738_2.png) [@jan-k](https://discourse.nodered.org/u/jan-k)\
**Post date:** [3 March 2020 08:27 UTC](https://discourse.nodered.org/t/problem-to-display-state-from-device/22484/11 "2020-03-03T08:27:23Z")

</div>

Hi kuema, yes u're right!

S7 Read node doesn't send anything when its failure. I also tried to use the catch node for error, but also get nothing. Anyway, I had found a solution using a ping node to get the status for my device and it's work.  
🤣 Thank you for spending time wrote your suggestion here.  
Best Regards.

---

<div class="post-metadata">

**Author:** ![kuema](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/kuema/32/6542_2.png) [@kuema](https://discourse.nodered.org/u/kuema)\
**Post date:** [3 March 2020 08:31 UTC](https://discourse.nodered.org/t/problem-to-display-state-from-device/22484/12 "2020-03-03T08:31:59Z")

</div>

Then the S7 node is probably only setting it's node status to "failure" and doesn't send an error.

You could use a `status` node in this case and filter the `failure` events instead. Same procedure as with the catch node. 😅

But ping should work too.

OR... use a `trigger` node to act as a watchdog that sends a message if none has been received for x seconds. 🤔 Endless possibilities.

[https://cookbook.nodered.org/basic/trigger-timeout](https://cookbook.nodered.org/basic/trigger-timeout)

---

<div class="post-metadata">

**Author:** ![jan-k](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jan-k/32/17738_2.png) [@jan-k](https://discourse.nodered.org/u/jan-k)\
**Post date:** [3 March 2020 08:37 UTC](https://discourse.nodered.org/t/problem-to-display-state-from-device/22484/13 "2020-03-03T08:37:55Z")

</div>

Dear kuema,

I had tried the status node, but it displayed "undefined" when my device is online.  
Trigger node need to key in the input right? I never use the trigger node before, but I need the instant feedback, so changing state after few seconds I think it's not suitable for my objective. 🧐

Best Regards.

---

<div class="post-metadata">

**Author:** ![kuema](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/kuema/32/6542_2.png) [@kuema](https://discourse.nodered.org/u/kuema)\
**Post date:** [3 March 2020 08:42 UTC](https://discourse.nodered.org/t/problem-to-display-state-from-device/22484/14 "2020-03-03T08:42:45Z")

</div>

The status node uses `msg.status`, not payload. Just attach a debug with "complete message". I don't know what status events the S7 node is sending, so you would need to investigate that yourself. 🙂

> [@jan-k](#):
>
> but I need the instant feedback

Ah, okay. It was just an idea. I am using that timeout pattern for my sensors a lot. 😅

---

<div class="post-metadata">

**Author:** ![jan-k](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jan-k/32/17738_2.png) [@jan-k](https://discourse.nodered.org/u/jan-k)\
**Post date:** [3 March 2020 08:45 UTC](https://discourse.nodered.org/t/problem-to-display-state-from-device/22484/15 "2020-03-03T08:45:14Z")

</div>

> [@kuema](#):
>
> The status node uses `msg.status` , not payload. Just attach a debug with "complete message".

Okay thanks, I'll try for it.  
Anyway, do you guys know how to select any flow to run or to stop? 😕  
I just made a jumping flow after the device status is disconnected by using ui\_control node. But I found that it keep stuck at the flow unless it get connected back. 😣

---

<div class="post-metadata">

**Author:** ![kuema](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/kuema/32/6542_2.png) [@kuema](https://discourse.nodered.org/u/kuema)\
**Post date:** [3 March 2020 08:49 UTC](https://discourse.nodered.org/t/problem-to-display-state-from-device/22484/16 "2020-03-03T08:49:36Z")

</div>

You can disable the entire tab and/or individual nodes in the node property dialog (at the bottom).

---

<div class="post-metadata">

**Author:** ![unixneo](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/unixneo/32/17441_2.png) [@unixneo](https://discourse.nodered.org/u/unixneo)\
**Post date:** [3 March 2020 10:52 UTC](https://discourse.nodered.org/t/problem-to-display-state-from-device/22484/17 "2020-03-03T10:52:42Z")

</div>

It will work easily if you manage by exception as I have illustrated.

I do this all the time on other flows.

Managing by exception in a switch is very easy.

It's trivial to do if you follow what I have advised; which is to switch between when it has a "correct reading" to when does not have any correct reading.

Sorry to be repetitive but I have this exact same problem on.a number of nodes, and I handle all of them this way, and it works fine.!

FYI, these are messages:

[Screen Shot 2020-03-03 at 6.17.52 PM|176x183](https://discourse.nodered.org/uploads/short-url/hKsuOPff5ONRXx5VU8M1TfhZQj6.jpeg)

FYI: these are messages:

![Screen Shot 2020-03-03 at 6.19.35 PM](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/6/26b21513dcdee435d07bcc7443b6b0198f14ec8d.jpeg)

This is trivial to solve with a switch node. The switch node will switch on a message. If it has the right payload it will switch to the designated node. OTHERWISE is will switch to another node.

The failure is the exception and it can be done in a switch because, as mentioned, I do this in a number of nodes in my flows just like this with the same issue (but different device).

---

<div class="post-metadata">

**Author:** ![kuema](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/kuema/32/6542_2.png) [@kuema](https://discourse.nodered.org/u/kuema)\
**Post date:** [3 March 2020 14:21 UTC](https://discourse.nodered.org/t/problem-to-display-state-from-device/22484/18 "2020-03-03T14:21:54Z")

</div>

As I understood the OP, we confirmed that the S7 node seems to "misbehave" and does send neither a message that indicates a failure (to be used by `switch`), nor does it throw an error message that can be caught be the `catch` node. So there's no message to go on.

The one thing it _does_ is updating its status on failure. So that would be the only place to start an error handling flow.

However, I haven't used the S7, so these assumptions are based on the info that @jan-k provided. 😅

@jan-k: Are you using the [https://www.npmjs.com/package/node-red-contrib-s7](https://www.npmjs.com/package/node-red-contrib-s7) node?

---

<div class="post-metadata">

**Author:** ![kuema](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/kuema/32/6542_2.png) [@kuema](https://discourse.nodered.org/u/kuema)\
**Post date:** [3 March 2020 15:02 UTC](https://discourse.nodered.org/t/problem-to-display-state-from-device/22484/19 "2020-03-03T15:02:56Z")

</div>

I just had a brief look at the source code of the S7 node. They don't pass the input message to the error handler function `node.error()`, so catch nodes will never get triggered.

So in this state, there is no way to handle errors properly. You could raise an issue with the node's author to improve the code on that matter.

---

<div class="post-metadata">

**Author:** ![jan-k](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jan-k/32/17738_2.png) [@jan-k](https://discourse.nodered.org/u/jan-k)\
**Post date:** [4 March 2020 01:06 UTC](https://discourse.nodered.org/t/problem-to-display-state-from-device/22484/20 "2020-03-04T01:06:58Z")

</div>

> [@kuema](#):
>
> Are you using the [node-red-contrib-s7 - npm](https://www.npmjs.com/package/node-red-contrib-s7) node?

Yes yes, I'm using that node! 😆

---

<div class="post-metadata">

**Author:** ![jan-k](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jan-k/32/17738_2.png) [@jan-k](https://discourse.nodered.org/u/jan-k)\
**Post date:** [4 March 2020 01:08 UTC](https://discourse.nodered.org/t/problem-to-display-state-from-device/22484/21 "2020-03-04T01:08:39Z")

</div>

> [@kuema](#):
>
> I just had a brief look at the source code of the S7 node. They don't pass the input message to the error handler function `node.error()` , so catch nodes will never get triggered.

Exactly! 👍

[Next page](https://discourse.nodered.org/t/problem-to-display-state-from-device/22484.md?page=2)
