When is a string not a string

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

[{"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}]

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.

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

[{"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}]

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

Yes exactly the same

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.

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.

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?

From your data...
image

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

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.

13 == d in the hexadecimal numbering system.

image

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.

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

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