Display output message

Hi everyone. I'm trying to show the output from two inputs (facial expressions). These two inputs will have different values from 0-100. Thus, I use the switch node to differentiate if it is larger than 80 or not and then use the change node to display the message. The two change nodes will be joined together using the join node. I'm trying to write a function to have a more specific output message because I'll get the two messages displayed at the same time and this is not the result that I wish to be.

[{"id":"46664e94.9cfaa","type":"function","z":"73f9235a.d2b04c","name":"Yes - Threshold 1","func":"var spoken = context.get('spoken') || false;\nvar threshold = 1;\nvar outString = \"yes\";\nvar outMsg = {payload: \"\", text : outString};\n\nif (!spoken) {\n    if (msg.payload >= threshold) {\n        outMsg.payload = outString;\n        spoken = true;\n    }\n}\n\nif (msg.payload < threshold) {\n    spoken = false;\n    outMsg.text = \"\";\n}\n\nconsole.log(outMsg);\n\ncontext.set('spoken', spoken);\nreturn outMsg;","outputs":1,"noerr":0,"x":1110,"y":320,"wires":[["415b7191.b59c7","90c71e.1b52b8e"]]}]

However, nothing is displayed in the debug message. Can anyone tell me where is my error? Thank you.

Do you mean no debug message is displayed, or the debug message is displayed but the contents are not as you expect?

If the latter then you can use node.warn() to show what is happening in your function. For example you can put code like

node.warn("spoken is " + spoken);

after your context.get line in order to check what it is. The warn message will be displayed in the debug pane. Similarly you can put warns inside the if statements to show where it is going. That way you should be able to home in on what is going wrong.

Sorry, is my fault. What my mean is no any debug message is display.

In that case I think you are not triggering it with anything. Check that you are actually sending it a message.

I've tried to connect the outputs of the facial expressions to two debug outputs separately. It displayed something so I think it should not be a problem.


Is my coding looks fine?

if (msg.payload.clench = 0) {
    msg.payload = "clench signal";
}
else if (msg.payload.frown = 0) {
    msg.payload = "frown signal";
}
else {
    return null;
}
return msg;

Put a debug showing the input to the function node and check that.

I've put a debug in front of the function node and there are no displayed message for the two debugs.
Or should I add a change node after the switch node?

Post the flow of the join node so we can see how it is configured.

[{"id":"dca53734.67db58","type":"join","z":"8c77fcbd.3d439","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":1370,"y":360,"wires":[["2bc7253e.f0811a","fa81abe6.1c95d8"]]}]

Have you checked what the nodes before the join are passing on?
Also have you set different topics on the two input messages?
I don't know whether you mean it but as you have it the join node will not pass on anything until it has messages from both paths (assuming you have set topics) and then will not send another till it gets another message from each path. If you want it to wait till one from each has been received but then send whenever either of them comes in then select the box 'and every subsequent message'.

Still trying to fully understand what you are trying to do. I don't understand why you need the Join node at all. The purpose of the Join node is to combine messages on different paths into one message containing the data from both paths at the same time. If you only care about the last message from either path then you don't need the Join node at all.

This is because someone suggest me to use the join node before and I thought it can used for the separate message. Another reason is I realised when there is two paths in the flow, it will only run the second path when I run the flow, the first path is always be ignored. The two paths will be run when I put the join node. (I need to run the both paths so I know which facial expressions is being made)

Then can I just directly connect the change node with the function node?

If you need the data from both paths combined then you need the Join node, but you have to give the messages topics (if they don't already) so you can distinguish the data from the two paths.

I don't need the data from both paths combined. I just want to know which path is running and the message in the respective path will be displayed in the debug. i just afraid the first path of the flow will not be run when I didn't use the join node.

Do you just need the latest message to come out of either path? If so then just feed them both into a function node.

Just connect the change node with the function node right?

Yes. I don't know whether you need the Change nodes, I don't think you have posted them.

Okay, I'll try it and see whether I need the change node or not.

I assume you are doing something to identify the different paths, in which case yes you do need them.

Yes, i need to identify the path and display the message.

[{"id":"8c77fcbd.3d439","type":"tab","label":"Flow 6","disabled":false,"info":""},{"id":"b4f62510.3688e8","type":"EMOTIV","z":"8c77fcbd.3d439","name":"EMOTIV","x":400,"y":340,"wires":[["78519482.28511c"]]},{"id":"78519482.28511c","type":"Profile-Name","z":"8c77fcbd.3d439","name":"Profile Name","profileName":"new","x":590,"y":340,"wires":[["686c6c7e.3f1bc4","2eeb385e.ad4418"]]},{"id":"7854bb6a.6e8494","type":"debug","z":"8c77fcbd.3d439","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":1730,"y":320,"wires":[]},{"id":"2eeb385e.ad4418","type":"Facial-Expression","z":"8c77fcbd.3d439","name":"Facial Expressions","action":"clench","sens":"800","x":900,"y":280,"wires":[["f5cafe90.b61bf"]]},{"id":"686c6c7e.3f1bc4","type":"Facial-Expression","z":"8c77fcbd.3d439","name":"Facial Expressions","action":"frown","sens":"800","x":890,"y":460,"wires":[["e9fe3385.89298"]]},{"id":"2bc7253e.f0811a","type":"function","z":"8c77fcbd.3d439","name":"","func":"if (msg.payload.clench = 0 ) {\n    msg.payload = \"clench signal\";\n}\nelse if (msg.payload.frown = 0) {\n    msg.payload = \"frown signal\";\n}\nelse {\n    return null;\n}\nreturn msg;","outputs":1,"noerr":0,"x":1490,"y":380,"wires":[["7854bb6a.6e8494"]]},{"id":"f5cafe90.b61bf","type":"switch","z":"8c77fcbd.3d439","name":"clench","property":"payload","propertyType":"msg","rules":[{"t":"gt","v":"80","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":1090,"y":260,"wires":[["38ae06c3.245fda"]]},{"id":"e9fe3385.89298","type":"switch","z":"8c77fcbd.3d439","name":"frown","property":"payload","propertyType":"msg","rules":[{"t":"gt","v":"80","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":1070,"y":460,"wires":[["f8a80587.a04d38"]]},{"id":"f8a80587.a04d38","type":"change","z":"8c77fcbd.3d439","name":">80 (frown)","rules":[{"t":"set","p":"topic","pt":"msg","to":"frown signal","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1250,"y":460,"wires":[["2bc7253e.f0811a"]]},{"id":"38ae06c3.245fda","type":"change","z":"8c77fcbd.3d439","name":">80 (clench)","rules":[{"t":"set","p":"topic","pt":"msg","to":"clench signal","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1250,"y":260,"wires":[["2bc7253e.f0811a"]]}]


I've added the change node. Is the change needed to be added like this? I'm not sure whether it is correct or not and there is still no any message displayed.