# When is a string not a string

**URL:** <https://discourse.nodered.org/t/when-is-a-string-not-a-string/42714>\
**Category:** General\
**Created:** [16 March 2021 13:06 UTC](https://discourse.nodered.org/t/when-is-a-string-not-a-string/42714 "2021-03-16T13:06:29Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![smithy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/smithy/32/37804_2.png) [@smithy](https://discourse.nodered.org/u/smithy)\
**Post date:** [16 March 2021 13:06 UTC](https://discourse.nodered.org/t/when-is-a-string-not-a-string/42714/1 "2021-03-16T13:06:29Z")

</div>

Hi

I have flow which reads the binary state(Active/InActive) of a sensor using a std tcp request, it reads an ASCI buffer to send an alarm message based on the buffer string, a message is then sent to pushover which works fine, at the same time I am trying to show the state of sensor on my dashboard using an LED node.

When I connect my LED node to the same 'buffer to string' function node output my LED fails to change state? but at the same time if I use a couple of inject nodes to send the same strings 'Active', 'InActive' to test the LED node they work!?

What am I missing? I thought I read somewhere on the forum there was a nuance about using buffer to string, so I added(inserted) the extra 'Fudge' function node to see if that fixed it but no...

Thanks

```auto
[{"id":"2a8d439.b7589bc","type":"tab","label":"Flow 2","disabled":false,"info":""},{"id":"8f3ec4af.8bff78","type":"change","z":"2a8d439.b7589bc","name":"conv message","rules":[{"t":"change","p":"payload","pt":"msg","from":"InActive","fromt":"str","to":"Granary Gate Beam Tripped","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":680,"y":380,"wires":[["dabf8294.cb2b"]]},{"id":"de1c0ea7.3695a","type":"ui_led","z":"2a8d439.b7589bc","order":3,"group":"43f72cbd.eb2dd4","width":0,"height":0,"label":"Granary IR Beam","labelPlacement":"left","labelAlignment":"left","colorForValue":[{"color":"#008000","value":"Active","valueType":"str"},{"color":"#ff0000","value":"InActive","valueType":"str"}],"allowColorForValueInMessage":false,"shape":"circle","showGlow":true,"name":"Granary IR Beam","x":690,"y":320,"wires":[]},{"id":"cdb04f39.57aad","type":"tcp request","z":"2a8d439.b7589bc","server":"192.168.1.122","port":"17123","out":"time","splitc":"0","name":"","x":310,"y":260,"wires":[["9bed70f6.5aa1a","9c037bd8.415368"]]},{"id":"157caa0e.8c4836","type":"pushover","z":"2a8d439.b7589bc","name":"","device":"","title":"Alarm System","priority":"1","sound":"","url":"","url_title":"","html":false,"x":920,"y":440,"wires":[]},{"id":"d0b88611.1765f8","type":"debug","z":"2a8d439.b7589bc","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":910,"y":520,"wires":[]},{"id":"31aec1e9.a36f7e","type":"inject","z":"2a8d439.b7589bc","name":"trip test","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"InActive","payloadType":"str","x":430,"y":440,"wires":[["5921cdcf.7e7174"]]},{"id":"9bed70f6.5aa1a","type":"debug","z":"2a8d439.b7589bc","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":570,"y":160,"wires":[]},{"id":"b9c6c427.5079a8","type":"inject","z":"2a8d439.b7589bc","name":"trip test bypass clock","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"Granary Gate Beam Tripped","payloadType":"str","x":470,"y":520,"wires":[["d0b88611.1765f8","157caa0e.8c4836"]]},{"id":"64c8208e.6242a","type":"function","z":"2a8d439.b7589bc","name":"buffer to string","func":"msg.payload = msg.payload.toString();\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":180,"y":380,"wires":[["64f5d9e8.e5b8e8","5921cdcf.7e7174","34b9aa30.d6a126"]]},{"id":"f418e652.38bfd8","type":"inject","z":"2a8d439.b7589bc","name":"ASCI di1 Read","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"1","crontab":"","once":true,"onceDelay":"1","topic":"","payload":"GI 1","payloadType":"str","x":200,"y":140,"wires":[["cdb04f39.57aad"]]},{"id":"64f5d9e8.e5b8e8","type":"debug","z":"2a8d439.b7589bc","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":170,"y":440,"wires":[]},{"id":"dabf8294.cb2b","type":"time-range-switch","z":"2a8d439.b7589bc","name":"","lat":"51.392568","lon":"-1.704475","startTime":"dusk","endTime":"06:00","startOffset":0,"endOffset":0,"x":670,"y":440,"wires":[["d0b88611.1765f8","157caa0e.8c4836"],[]]},{"id":"5921cdcf.7e7174","type":"switch","z":"2a8d439.b7589bc","name":"","property":"payload","propertyType":"msg","rules":[{"t":"cont","v":"InActive","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":410,"y":380,"wires":[["8f3ec4af.8bff78"]]},{"id":"92cab16.5c1e75","type":"inject","z":"2a8d439.b7589bc","name":"NO trip test","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"Active","payloadType":"str","x":450,"y":480,"wires":[["5921cdcf.7e7174"]]},{"id":"7ec1405e.195bc","type":"inject","z":"2a8d439.b7589bc","name":"ASCI di2 Read","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"GI 2","payloadType":"str","x":200,"y":180,"wires":[["cdb04f39.57aad"]]},{"id":"9c037bd8.415368","type":"rbe","z":"2a8d439.b7589bc","name":"","func":"rbe","gap":"","start":"","inout":"out","property":"payload","x":150,"y":320,"wires":[["64c8208e.6242a"]]},{"id":"4fcef35a.c9a42c","type":"comment","z":"2a8d439.b7589bc","name":"Granary IR Beam -------------------------------------------------------------------------------------------------------------------------","info":"","x":470,"y":100,"wires":[]},{"id":"32ebb3c3.19b9bc","type":"inject","z":"2a8d439.b7589bc","name":"Led Green","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"Active","payloadType":"str","x":680,"y":220,"wires":[["de1c0ea7.3695a"]]},{"id":"1e57a2c7.c761dd","type":"inject","z":"2a8d439.b7589bc","name":"Led Red","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"InActive","payloadType":"str","x":680,"y":260,"wires":[["de1c0ea7.3695a"]]},{"id":"34b9aa30.d6a126","type":"change","z":"2a8d439.b7589bc","name":"Fudge","rules":[{"t":"change","p":"payload","pt":"msg","from":"Active","fromt":"str","to":"Active","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":"InActive","fromt":"str","to":"InActive","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":410,"y":320,"wires":[["de1c0ea7.3695a"]]},{"id":"43f72cbd.eb2dd4","type":"ui_group","name":"Workshop","tab":"78d863c9.1da73c","order":3,"disp":true,"width":"6","collapse":false},{"id":"78d863c9.1da73c","type":"ui_tab","name":"Kingstones Alarm System","icon":"dashboard","disabled":false,"hidden":false}]

```

---

<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:** [16 March 2021 13:36 UTC](https://discourse.nodered.org/t/when-is-a-string-not-a-string/42714/2 "2021-03-16T13:36:23Z")

</div>

Add a debug node showing what is going into the led node and show us what you see for the failing state. Also show us the buffer contents in a debug node.

---

<div class="post-metadata">

**Author:** ![smithy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/smithy/32/37804_2.png) [@smithy](https://discourse.nodered.org/u/smithy)\
**Post date:** [16 March 2021 13:59 UTC](https://discourse.nodered.org/t/when-is-a-string-not-a-string/42714/3 "2021-03-16T13:59:31Z")

</div>

Here you go, update code to reflect the debug nodes you asked for and my debug panel output

```auto
[{"id":"2a8d439.b7589bc","type":"tab","label":"Flow 2","disabled":false,"info":""},{"id":"8f3ec4af.8bff78","type":"change","z":"2a8d439.b7589bc","name":"conv message","rules":[{"t":"change","p":"payload","pt":"msg","from":"InActive","fromt":"str","to":"Granary Gate Beam Tripped","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":680,"y":460,"wires":[["dabf8294.cb2b"]]},{"id":"de1c0ea7.3695a","type":"ui_led","z":"2a8d439.b7589bc","order":3,"group":"43f72cbd.eb2dd4","width":0,"height":0,"label":"Granary IR Beam","labelPlacement":"left","labelAlignment":"left","colorForValue":[{"color":"#008000","value":"Active","valueType":"str"},{"color":"#ff0000","value":"InActive","valueType":"str"}],"allowColorForValueInMessage":false,"shape":"circle","showGlow":true,"name":"Granary IR Beam","x":690,"y":320,"wires":[]},{"id":"cdb04f39.57aad","type":"tcp request","z":"2a8d439.b7589bc","server":"192.168.1.122","port":"17123","out":"time","splitc":"0","name":"","x":310,"y":260,"wires":[["9bed70f6.5aa1a","64c8208e.6242a"]]},{"id":"157caa0e.8c4836","type":"pushover","z":"2a8d439.b7589bc","name":"","device":"","title":"Alarm System","priority":"1","sound":"","url":"","url_title":"","html":false,"x":920,"y":520,"wires":[]},{"id":"d0b88611.1765f8","type":"debug","z":"2a8d439.b7589bc","name":"pushover message","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":930,"y":600,"wires":[]},{"id":"31aec1e9.a36f7e","type":"inject","z":"2a8d439.b7589bc","name":"trip test","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"InActive","payloadType":"str","x":430,"y":520,"wires":[["5921cdcf.7e7174"]]},{"id":"9bed70f6.5aa1a","type":"debug","z":"2a8d439.b7589bc","name":"raw sensor debug","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":690,"y":160,"wires":[]},{"id":"b9c6c427.5079a8","type":"inject","z":"2a8d439.b7589bc","name":"trip test bypass clock","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"Granary Gate Beam Tripped","payloadType":"str","x":470,"y":600,"wires":[["d0b88611.1765f8","157caa0e.8c4836"]]},{"id":"64c8208e.6242a","type":"function","z":"2a8d439.b7589bc","name":"buffer to string","func":"msg.payload = msg.payload.toString();\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":180,"y":380,"wires":[["64f5d9e8.e5b8e8","5921cdcf.7e7174","34b9aa30.d6a126"]]},{"id":"f418e652.38bfd8","type":"inject","z":"2a8d439.b7589bc","name":"ASCI di1 Read","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":true,"onceDelay":"1","topic":"","payload":"GI 1","payloadType":"str","x":200,"y":140,"wires":[["cdb04f39.57aad"]]},{"id":"64f5d9e8.e5b8e8","type":"debug","z":"2a8d439.b7589bc","name":"buffer to string debug","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":700,"y":400,"wires":[]},{"id":"dabf8294.cb2b","type":"time-range-switch","z":"2a8d439.b7589bc","name":"","lat":"51.392568","lon":"-1.704475","startTime":"13:00","endTime":"06:00","startOffset":0,"endOffset":0,"x":670,"y":520,"wires":[["d0b88611.1765f8","157caa0e.8c4836"],[]]},{"id":"5921cdcf.7e7174","type":"switch","z":"2a8d439.b7589bc","name":"","property":"payload","propertyType":"msg","rules":[{"t":"cont","v":"InActive","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":410,"y":460,"wires":[["8f3ec4af.8bff78"]]},{"id":"92cab16.5c1e75","type":"inject","z":"2a8d439.b7589bc","name":"NO trip test","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"Active","payloadType":"str","x":450,"y":560,"wires":[["5921cdcf.7e7174"]]},{"id":"7ec1405e.195bc","type":"inject","z":"2a8d439.b7589bc","name":"ASCI di2 Read","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"GI 2","payloadType":"str","x":200,"y":180,"wires":[["cdb04f39.57aad"]]},{"id":"9c037bd8.415368","type":"rbe","z":"2a8d439.b7589bc","name":"","func":"rbe","gap":"","start":"","inout":"out","property":"payload","x":90,"y":280,"wires":[[]]},{"id":"4fcef35a.c9a42c","type":"comment","z":"2a8d439.b7589bc","name":"Granary IR Beam -------------------------------------------------------------------------------------------------------------------------","info":"","x":470,"y":100,"wires":[]},{"id":"32ebb3c3.19b9bc","type":"inject","z":"2a8d439.b7589bc","name":"Led Green","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"Active","payloadType":"str","x":680,"y":220,"wires":[["de1c0ea7.3695a"]]},{"id":"1e57a2c7.c761dd","type":"inject","z":"2a8d439.b7589bc","name":"Led Red","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"InActive","payloadType":"str","x":680,"y":260,"wires":[["de1c0ea7.3695a"]]},{"id":"34b9aa30.d6a126","type":"change","z":"2a8d439.b7589bc","name":"Fudge","rules":[{"t":"change","p":"payload","pt":"msg","from":"Active","fromt":"str","to":"Active","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":"InActive","fromt":"str","to":"InActive","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":410,"y":320,"wires":[["de1c0ea7.3695a","24bf3428.00d38c"]]},{"id":"24bf3428.00d38c","type":"debug","z":"2a8d439.b7589bc","name":"string to led debug","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":690,"y":360,"wires":[]},{"id":"43f72cbd.eb2dd4","type":"ui_group","name":"Workshop","tab":"78d863c9.1da73c","order":3,"disp":true,"width":"6","collapse":false},{"id":"78d863c9.1da73c","type":"ui_tab","name":"Kingstones Alarm System","icon":"dashboard","disabled":false,"hidden":false}]

```

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

---

<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:** [16 March 2021 14:57 UTC](https://discourse.nodered.org/t/when-is-a-string-not-a-string/42714/4 "2021-03-16T14:57:04Z")

</div>

So does the string going into the LED node look _exactly_ the same as that coming from the Inject node?

---

<div class="post-metadata">

**Author:** ![smithy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/smithy/32/37804_2.png) [@smithy](https://discourse.nodered.org/u/smithy)\
**Post date:** [16 March 2021 15:09 UTC](https://discourse.nodered.org/t/when-is-a-string-not-a-string/42714/5 "2021-03-16T15:09:43Z")

</div>

Yes exactly the same

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [16 March 2021 15:22 UTC](https://discourse.nodered.org/t/when-is-a-string-not-a-string/42714/6 "2021-03-16T15:22:03Z")

</div>

It it just not that your string has a carriage return at the end? Try using a function node and a call to the strings trim() function to get rid of the whitespace before you send it to the UI.

---

<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:** [16 March 2021 15:32 UTC](https://discourse.nodered.org/t/when-is-a-string-not-a-string/42714/7 "2021-03-16T15:32:03Z")

</div>

> [@smithy](#):
>
> Yes exactly the same

No it isn't. As Steve says, there is a CR on the end of the string. With computers every detail has to be right.

---

<div class="post-metadata">

**Author:** ![smithy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/smithy/32/37804_2.png) [@smithy](https://discourse.nodered.org/u/smithy)\
**Post date:** [16 March 2021 16:44 UTC](https://discourse.nodered.org/t/when-is-a-string-not-a-string/42714/8 "2021-03-16T16:44:44Z")

</div>

Hi Steve

OK, I'll implement the trim as you advise. So, where does the CR come from? I had already observed it - but it always seems to be there and it seems some nodes ignore it based on my inconsistent experience - why is that please?

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [16 March 2021 16:49 UTC](https://discourse.nodered.org/t/when-is-a-string-not-a-string/42714/9 "2021-03-16T16:49:30Z")

</div>

> [@smithy](#):
>
> So, where does the CR come from?

From your data...  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/e/bef78d2f4f068fd8208f391437d0151fc930a75a.png)

---

<div class="post-metadata">

**Author:** ![smithy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/smithy/32/37804_2.png) [@smithy](https://discourse.nodered.org/u/smithy)\
**Post date:** [16 March 2021 17:05 UTC](https://discourse.nodered.org/t/when-is-a-string-not-a-string/42714/10 "2021-03-16T17:05:08Z")

</div>

OK, so as you can see, from my debug stream ALL messages end in CR, even the hand typed message 'Granary Gate Beam Tripped' entered in the std. Change Node, just to be sure I just checked the text field in the change node to see if there was a loose decimal 13(code) but I can confirm the text string entered ends in the character 'd'.

Of course I can't talk for the supplier of the board who is sending me the buffer with the CR, but why is the Change Node sending it?  
Cheers

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [16 March 2021 17:09 UTC](https://discourse.nodered.org/t/when-is-a-string-not-a-string/42714/11 "2021-03-16T17:09:44Z")

</div>

> [@smithy](#):
>
> but why is the Change Node sending it?

Because the change node is AFTER the TCP node. The data is coming from the TCP node with a CR LF at the end. Usually a product sends this so you know where to safely "split" data (where one message ends and another starts) - but not always - depends on the firmware writer / protocol.

> [@smithy](#):
>
> but I can confirm the text string entered ends in the character 'd'.

`13` == `d` in the hexadecimal numbering system.

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

---

<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:** [16 March 2021 17:22 UTC](https://discourse.nodered.org/t/when-is-a-string-not-a-string/42714/12 "2021-03-16T17:22:06Z")

</div>

> [@smithy](#):
>
> why is the Change Node sending it?

Your Change node is configured to look for Active and replace that string with the same string, so it has no effect at all. It doesn't search for Active and if found replace the whole payload, it just replaces the string it finds, so the CR is left on the end.

---

<div class="post-metadata">

**Author:** ![smithy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/smithy/32/37804_2.png) [@smithy](https://discourse.nodered.org/u/smithy)\
**Post date:** [16 March 2021 19:49 UTC](https://discourse.nodered.org/t/when-is-a-string-not-a-string/42714/13 "2021-03-16T19:49:09Z")

</div>

Gents, Steve's suggested Trim Function did the trick, thanks both for help 🙂

---

<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:** [30 March 2021 19:49 UTC](https://discourse.nodered.org/t/when-is-a-string-not-a-string/42714/14 "2021-03-30T19:49:53Z")

</div>

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