Two inputs in one function

Hi

I need to have two inputs in one function, the two inputs look like this
Input 1 Buffer: {"0":28,"1":2,"2":154,"3":128,"4":255,"5":100,"6":255,"7":102}
Input 2 JSON: {"on":true,"brightness":40,"rgb":[255,178,76],"hex":"ffb24c","color":"orange","colorTemp":497,"updated":"2020-08-22T19:58:38+02:00"}

I need to combine this two inputs in a function and then send a message

[{"id":"2dacb3c.81f824c","type":"tcp in","z":"f1689f67.6fb5d","name":"Dynet","server":"client","host":"192.168.0.30","port":"8081","datamode":"stream","datatype":"buffer","newline":"","topic":"data","base64":false,"x":110,"y":180,"wires":[["f42971c8.af614","b6d335b0.151f78"]]}]

I did take a look at the Join, but I can't get it working since there is two different messages types, maybe there is a way to save the value in the function when the inputs comes in to the function

You can only send one msg at a time to a node. So the function node will process the first msg Ann send out a response, then process the second. You could use context storage to save data from the first msg but you I’ll have to figure out how to tell msg 1 from msg 2 and deal with a case where two of msg 1 or 2 arrive in a row

You should first join the msgs then send the combined msg to the function node

Use a change node to add the missing parts of msg1 to msg 2 and the missing parts of mzg2 to msg1 then join them

1 Like

Could you give an example, a cant get i working because i have two different message types.

If it makes any difference, @zenofmud is technically correct.in having to send a response but you can send a Null as a response too.

Let’s say msg1 has msg.payload.temp and msg2 Has msg.payload.humidity. Send msg1 to a change node and set msg.payload.humidity to nothing. Do the same for msg2 but set msg.payload.temp to nothing and then send them to the join.

You will also have to add the parts needed to do the join (read the help section of the join node)

I did try to make a simple setup, so maybe you could have a look at it.
I cant seem to get it trough the change and the join node

[{"id":"73bfb3e1.57f90c","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"6ecf26c0.da1d68","type":"debug","z":"73bfb3e1.57f90c","name":"Output","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":870,"y":360,"wires":[]},{"id":"ab92eab2.426c48","type":"join","z":"73bfb3e1.57f90c","name":"","mode":"custom","build":"object","property":"","propertyType":"full","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"num","reduceFixup":"","x":690,"y":420,"wires":[["6ecf26c0.da1d68"]]},{"id":"4db10712.8ba2b8","type":"change","z":"73bfb3e1.57f90c","name":"","rules":[{"t":"move","p":"payload","pt":"msg","to":"request","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":490,"y":360,"wires":[["6ecf26c0.da1d68","ab92eab2.426c48"]]},{"id":"aa5e4099.515e3","type":"inject","z":"73bfb3e1.57f90c","name":"Light Request (Buffer)","topic":"","payload":"[28,2,172,128,255,100,255,84]","payloadType":"bin","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":240,"y":360,"wires":[["4db10712.8ba2b8"]]},{"id":"ae8c5e93.18492","type":"inject","z":"73bfb3e1.57f90c","name":"Light Reply (JSON)","topic":"","payload":"{\"on\":true,\"brightness\":33,\"reachable\":true,\"rgb\":[255,178,76],\"hex\":\"ffb24c\",\"color\":\"orange\",\"colorTemp\":497,\"updated\":\"2020-08-22T20:56:26+02:00\"}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":230,"y":420,"wires":[["ab92eab2.426c48"]]}]

I'm late to this party but look at this flow to see the changes, not sure of where you are going with this.

[{"id":"c0055da0.cc8e9","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"49fc4925.abbdc","type":"debug","z":"c0055da0.cc8e9","name":"Output","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":870,"y":360,"wires":[]},{"id":"3b42092e.64a5be","type":"join","z":"c0055da0.cc8e9","name":"","mode":"custom","build":"object","property":"","propertyType":"full","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"num","reduceFixup":"","x":690,"y":420,"wires":[["49fc4925.abbdc"]]},{"id":"7e7e4537.6615b4","type":"change","z":"c0055da0.cc8e9","name":"","rules":[{"t":"move","p":"payload","pt":"msg","to":"request","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":490,"y":320,"wires":[["49fc4925.abbdc","3b42092e.64a5be"]]},{"id":"add87a6d.ce3028","type":"inject","z":"c0055da0.cc8e9","name":"Light Request (Buffer)","props":[{"p":"request","v":"[28,2,172,128,255,100,255,84]","vt":"bin"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"request","x":240,"y":360,"wires":[["3b42092e.64a5be"]]},{"id":"4b47eed0.5a2c78","type":"inject","z":"c0055da0.cc8e9","name":"Light Reply (JSON)","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"reply","payload":"{\"on\":true,\"brightness\":33,\"reachable\":true,\"rgb\":[255,178,76],\"hex\":\"ffb24c\",\"color\":\"orange\",\"colorTemp\":497,\"updated\":\"2020-08-22T20:56:26+02:00\"}","payloadType":"json","x":230,"y":420,"wires":[["3b42092e.64a5be"]]}]

Yes something like this, but i cant seem to get the request out from the join with the same value as came in.
The reply seams to work

What is different?

sorry my bad, I didn't see that the request payload data was deleted

It looks like it is no longer a buffer, how can I keep it in the same format ?

Sorry to bail on you but other duties call and I'm not going to be at a computer for several days. Sending from my phone now, best wishes

When you run that flow you should be seeing some error messages. What do they say? Make sure the answer is applied to both messages.

Then change the join's 'to create' to 'an Array'

Hi,

Could something like this work ?

[{"id":"111afeb8.45f369","type":"debug","z":"3a02b3c7.cc85b4","name":"Output","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":890,"y":380,"wires":[]},{"id":"fcc7efbe.ef3ce8","type":"join","z":"3a02b3c7.cc85b4","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":"num","reduceFixup":"","x":610,"y":380,"wires":[["111afeb8.45f369"]]},{"id":"85bc2b05.7e4f7","type":"inject","z":"3a02b3c7.cc85b4","name":"Light Request (Buffer)","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"buffer","payload":"[28,2,172,128,255,100,255,84]","payloadType":"bin","x":240,"y":360,"wires":[["fcc7efbe.ef3ce8"]]},{"id":"1079db44.24515d","type":"inject","z":"3a02b3c7.cc85b4","name":"Light Reply (JSON)","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"json","payload":"{\"on\":true,\"brightness\":33,\"reachable\":true,\"rgb\":[255,178,76],\"hex\":\"ffb24c\",\"color\":\"orange\",\"colorTemp\":497,\"updated\":\"2020-08-22T20:56:26+02:00\"}","payloadType":"json","x":230,"y":420,"wires":[["fcc7efbe.ef3ce8"]]}]

Note that i set a topic in your inject nodes in order for change node to merge the data

1 Like

Does the join node use the number of different topics to figure out the different parts?

Have you read the Help?
Screen Shot 2020-08-23 at 9.31.30 AM

What part of it is unclear?

Have you tried it with different topics? whatwas your result?

1 Like

Sorry. I did not see that the join node specifically was set up to use topics. I was quite sure it said automatic for some reason..

A more clear example would be like this :

[{"id":"943b12b4.005428","type":"debug","z":"1b7f56b2.40cf39","name":"Output","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":970,"y":340,"wires":[]},{"id":"21acea57.c848ee","type":"join","z":"1b7f56b2.40cf39","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":"num","reduceFixup":"","x":770,"y":340,"wires":[["943b12b4.005428"]]},{"id":"fa04ca07.305258","type":"inject","z":"1b7f56b2.40cf39","name":"Light Request (Buffer)","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[28,2,172,128,255,100,255,84]","payloadType":"bin","x":280,"y":320,"wires":[["643d6998.2d69b8"]]},{"id":"c4c0f3b0.0f7f5","type":"inject","z":"1b7f56b2.40cf39","name":"Light Reply (JSON)","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"on\":true,\"brightness\":33,\"reachable\":true,\"rgb\":[255,178,76],\"hex\":\"ffb24c\",\"color\":\"orange\",\"colorTemp\":497,\"updated\":\"2020-08-22T20:56:26+02:00\"}","payloadType":"json","x":270,"y":380,"wires":[["ef362bc7.593a28"]]},{"id":"643d6998.2d69b8","type":"change","z":"1b7f56b2.40cf39","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"buffer","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":510,"y":320,"wires":[["21acea57.c848ee"]]},{"id":"ef362bc7.593a28","type":"change","z":"1b7f56b2.40cf39","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"json","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":510,"y":380,"wires":[["21acea57.c848ee"]]}]

In case our orginal messages dont have a topic. we can use a Change node to set a topic. That topic we use in Change nodes will be used in Join node (with manual settings) to merge the messages.

@UnborN you don’t need the topics to match.

Hi Paul, but they are not matching .. one is set to 'buffer' and the other to 'json'
did i miss something ?