After change node not comparing on function node

Hi,
using change node to convert PLC address to some readable format so that i can use it on function node, i doing this because i dont know how to use ALLEB BRADLY PLC address to function node after that i am comparing the values , is there way to use PLC address directly to function without change node kindly let me know, kindly see pic for reference




AB Temp coperision

In your change node you are using flow , which is context storage. You should be using msg. You also need to set a topic for data 2 and 1, i.e. Set, msg.topic To, T1

is it ok, what else and where i nee to make changes

I don't think you need the change node there. You probably need to set topic's for each incoming data
e.g.

[{"id":"d226cbf4.abb8d8","type":"inject","z":"c791cbc0.84f648","name":"data 1","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":120,"y":820,"wires":[["bce83b3d.beb44"]]},{"id":"bce83b3d.beb44","type":"change","z":"c791cbc0.84f648","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"T1","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":290,"y":820,"wires":[["f2c701ba.5f7278"]]},{"id":"f2c701ba.5f7278","type":"join","z":"c791cbc0.84f648","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":true,"timeout":"","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":480,"y":840,"wires":[["c6d7484b.ad177"]]},{"id":"95cceaee.7c2fd","type":"change","z":"c791cbc0.84f648","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"T2","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":290,"y":900,"wires":[["f2c701ba.5f7278"]]},{"id":"c6d7484b.ad177","type":"debug","z":"c791cbc0.84f648","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":670,"y":840,"wires":[]},{"id":"13fa7762.ab25a9","type":"inject","z":"c791cbc0.84f648","name":"data 2","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":110,"y":900,"wires":[["95cceaee.7c2fd"]]}]

sorry, i am new in node red and json cant understand what you have sent

i can see output of function if add return msg at end but why it is not comparing
can i use address of plc directly to function node without using change node

That is a flow json i exported from my node-red.
To use copy it, then press ctrl i in the editor, paste the flow json in the import pop up and press import. You will see an example flow.
some good reading Working with messages : Node-RED

https://cookbook.nodered.org/basic/join-streams

Export your flow by highlighting all nodes and press ctrl e, add two inject nodes with examples of data coming out of the data(plc) nodes. you can copy values using a debug node, in the side panel next to the object names, when you hover mouse you will see two icons pop up one is copy value the other copy path, these are very usefull.

Actually code is working with inject node but not workig when i use pchange node with plc address

I will never understand why function nodes - are used. This makes the flow completely intransparent. I tried to simulate your output with inject nodes and realized your logic without writing code:

[{"id":"5340cfd658f6f6f6","type":"inject","z":"cb05e14b.326a9","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"ch0","payload":"142","payloadType":"num","x":330,"y":380,"wires":[["2f12098b5d79577b"]]},{"id":"a60c55afc6b15c70","type":"inject","z":"cb05e14b.326a9","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"ch1","payload":"396","payloadType":"num","x":330,"y":440,"wires":[["2f12098b5d79577b"]]},{"id":"2f12098b5d79577b","type":"join","z":"cb05e14b.326a9","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":true,"timeout":"","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":500,"y":400,"wires":[["675f9b230d46ed95"]]},{"id":"5d30c0bd802ccec2","type":"debug","z":"cb05e14b.326a9","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":990,"y":400,"wires":[]},{"id":"675f9b230d46ed95","type":"switch","z":"cb05e14b.326a9","name":"Difference < > 5","property":"payload.ch1 - payload.ch0","propertyType":"jsonata","rules":[{"t":"gt","v":"5","vt":"num"},{"t":"lt","v":"5","vt":"num"}],"checkall":"true","repair":false,"outputs":2,"x":660,"y":400,"wires":[["a00e3f8dc5d6738a"],["0e1560893c977356"]]},{"id":"a00e3f8dc5d6738a","type":"change","z":"cb05e14b.326a9","name":"= 1","rules":[{"t":"set","p":"payload","pt":"msg","to":"1","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":830,"y":380,"wires":[["5d30c0bd802ccec2"]]},{"id":"0e1560893c977356","type":"change","z":"cb05e14b.326a9","name":"= 0","rules":[{"t":"set","p":"payload","pt":"msg","to":"0","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":830,"y":420,"wires":[["5d30c0bd802ccec2"]]}]

The code above (JSON) can be copied in the clipboard and imported in your NodeRed using the import function. :wink:

my code or node red flow is working with inject node too but when i replace inject node with plc address then it is not giving me output according to conditional, if i use return msg at end of all bracket then i am also getting value coming from my plc address but it is not getting in to conditional if i use plc address instead of inject node

As stated you need to set topic's for the join

The you have to transform the output of the plc nodes - that it matches the format of the inject nodes. So best is to show your inject nodes and the output of the plc nodes using debug nodes.

Ok if the topics are missing then put a change Node after each plc node - setting a topic (different topics for each plc node)

image

if i use set instead of move and msg instead of flow then debug shows me unidentified value

I will modify my flow above - so you can add your plc Nodes directly instead - if the problem was only the missing topic.

So you can see the whole object and then the result which comes out when you subtract t0-t1

[{"id":"2f12098b5d79577b","type":"join","z":"cb05e14b.326a9","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":true,"timeout":"","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":530,"y":500,"wires":[["675f9b230d46ed95","4955a3635ee96cdd"]]},{"id":"5d30c0bd802ccec2","type":"debug","z":"cb05e14b.326a9","name":"result","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1000,"y":500,"wires":[]},{"id":"675f9b230d46ed95","type":"switch","z":"cb05e14b.326a9","name":"Difference < > 5","property":"payload.t1 - payload.t0","propertyType":"jsonata","rules":[{"t":"gt","v":"5","vt":"num"},{"t":"lt","v":"5","vt":"num"}],"checkall":"true","repair":false,"outputs":2,"x":690,"y":500,"wires":[["a00e3f8dc5d6738a"],["0e1560893c977356"]]},{"id":"a00e3f8dc5d6738a","type":"change","z":"cb05e14b.326a9","name":"= 1","rules":[{"t":"set","p":"payload","pt":"msg","to":"1","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":860,"y":480,"wires":[["5d30c0bd802ccec2"]]},{"id":"0e1560893c977356","type":"change","z":"cb05e14b.326a9","name":"= 0","rules":[{"t":"set","p":"payload","pt":"msg","to":"0","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":860,"y":520,"wires":[["5d30c0bd802ccec2"]]},{"id":"f2386f5cae401760","type":"inject","z":"cb05e14b.326a9","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"142","payloadType":"num","x":190,"y":460,"wires":[["2a8b0803c56f0b58"]]},{"id":"57a19d7cabaee9a5","type":"inject","z":"cb05e14b.326a9","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"396","payloadType":"num","x":190,"y":520,"wires":[["9e7dd48c8a33fbff"]]},{"id":"2a8b0803c56f0b58","type":"change","z":"cb05e14b.326a9","name":"topic = t0","rules":[{"t":"set","p":"topic","pt":"msg","to":"t0","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":360,"y":460,"wires":[["2f12098b5d79577b"]]},{"id":"9e7dd48c8a33fbff","type":"change","z":"cb05e14b.326a9","name":"topic = t1","rules":[{"t":"set","p":"topic","pt":"msg","to":"t1","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":360,"y":520,"wires":[["2f12098b5d79577b"]]},{"id":"4955a3635ee96cdd","type":"debug","z":"cb05e14b.326a9","name":"object","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":710,"y":420,"wires":[]}]

If the output of the PLC Nodes are strings instead of numbers the use the change node to convert the payload in a number:

image

add the conversion to both change nodes if necessary.

Thanks a lot, problem was on i have not selected the topic