`change` node... not "working"? (And `switch` node)

I am trying to use the change node.

I usually/normally use a function node and do it that way, but I am trying to get used to using the change node.

This packet is coming in:
{"topic":"STATUS/ADSL_Link_Status","payload":{"Who":"TelePi","Modem":"Online","Uplink":"Online"},"qos":2,"retain":false,"_msgid":"7cc00bf.510a0f4"}
And this is going out:
{"topic":"TelePi","payload":{"Who":"TelePi","Modem":"Online","Uplink":"Online"},"qos":2,"retain":false,"_msgid":"7cc00bf.510a0f4","Modem":"Online","Uplink":"Online"}

And this is the node code:
[{"id":"4e10a2f6.ff28bc","type":"change","z":"15af81c5.64999e","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"payload.Who","tot":"msg"},{"t":"set","p":"Modem","pt":"msg","to":"payload.Modem","tot":"msg"},{"t":"set","p":"Uplink","pt":"msg","to":"payload.Uplink","tot":"msg"},{"t":"set","p":"who","pt":"msg","to":"payload.who","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":720,"y":4340,"wires":[["58a93b83.c6602c","21fb196.22199e6","983bb5dc.ae1ea8","6f170c9f.0a9d34"]]}]

Now, I can see that the msg.topic has been set.
And that msg.payload.Modem has become msg.Modem, and msg.payload.Uplink has become msg.Uplink

I am saying that I created those two: msg.Uplink and msg.Modem.

So why hasn't msg.who being created too?

(And as if that was all my problems.)

I then try to process this message through more switch nodes.
This is the flow part:

[{"id":"f4be63e.a8ced2","type":"json","z":"15af81c5.64999e","name":"","property":"payload","action":"","pretty":false,"x":540,"y":4340,"wires":[["fe3c0baf.e90bf8","4e10a2f6.ff28bc"]]},{"id":"4e10a2f6.ff28bc","type":"change","z":"15af81c5.64999e","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"payload.Who","tot":"msg"},{"t":"set","p":"Modem","pt":"msg","to":"payload.Modem","tot":"msg"},{"t":"set","p":"Uplink","pt":"msg","to":"payload.Uplink","tot":"msg"},{"t":"set","p":"who","pt":"msg","to":"payload.who","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":720,"y":4340,"wires":[["58a93b83.c6602c","21fb196.22199e6","983bb5dc.ae1ea8","6f170c9f.0a9d34"]]},{"id":"6f170c9f.0a9d34","type":"switch","z":"15af81c5.64999e","name":"Modem","property":"payload.Modem","propertyType":"msg","rules":[{"t":"cont","v":"Online","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":920,"y":4430,"wires":[["6a39103f.86a898"],["dddff52e.7420a"]]},{"id":"6a39103f.86a898","type":"debug","z":"15af81c5.64999e","name":"msg5","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":1050,"y":4420,"wires":[]},{"id":"dddff52e.7420a","type":"debug","z":"15af81c5.64999e","name":"msg6","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":1050,"y":4460,"wires":[]}]

I have tired editing the switch node to be either msg.Modem or msg.payload.Modem.

Neither seem to get through.

You will see that in that switch I test if the value is (or contains) "Online" and otherwise it goes to output 2.

Nothing comes out of either output of the switch.

I've been over it and over it and over it.

I don't get why the new "name" (msg.who) isn't being created when the other two are, and why the switch node isn't spitting the message out of output 2 - though I would have thought that as it says "Online" it would come out of #1.

Here is a test bed I made up to see if things work.

They seem to in this.

[{"id":"744982f7.41d894","type":"change","z":"15af81c5.64999e","name":"change","rules":[{"t":"set","p":"wibily","pt":"msg","to":"blah","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":460,"y":4810,"wires":[["6d7a989d.73e2a","31e119e2.0b00e6"]]},{"id":"6d7a989d.73e2a","type":"switch","z":"15af81c5.64999e","name":"","property":"wibily","propertyType":"msg","rules":[{"t":"eq","v":"blah","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":600,"y":4790,"wires":[["6a05c34a.b7c96c"],["ed5b29d5.acda2"]]},{"id":"31e119e2.0b00e6","type":"debug","z":"15af81c5.64999e","name":"bad","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":590,"y":4750,"wires":[]},{"id":"6d689910.40efd8","type":"function","z":"15af81c5.64999e","name":"","func":"msg.wibily = \"blah\";\nreturn msg;","outputs":1,"noerr":0,"x":450,"y":4770,"wires":[["6d7a989d.73e2a","31e119e2.0b00e6"]]},{"id":"6a05c34a.b7c96c","type":"debug","z":"15af81c5.64999e","name":"good","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":740,"y":4740,"wires":[]},{"id":"ed5b29d5.acda2","type":"debug","z":"15af81c5.64999e","name":"bad","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":740,"y":4830,"wires":[]},{"id":"b984cb8c.6fe24","type":"inject","z":"15af81c5.64999e","name":"","topic":"","payload":"message","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":270,"y":4790,"wires":[["6d689910.40efd8"]]}]

Either way. With the switch or function node.
Pressing the inject gets a good result.

This is a definitive showing of the problem.
Ok, you can't see the messages. But look at the nodes to which I am pointing in the pictures.

1:
a:
RAW message. You can see it pass through that node.
b:
I set some parts of the message.
c:
You see the output on "msg7".
Note: msg7 and msg5.

2:
You can see the higher node configuration.
Remember it didn't have any output in the previous picture.

3:
This is the lower of the two switch nodes marked "MODEM".
See how it is the same as the one in the previous picture.
And that its "msg7" node has a result.

Why didn't "msg5" also have an output if the same message was sent to them both?

Because you are setting it to the value of msg.payload.who which doesn't exist. It should be msg.payload.Who if the sample message you shared is accurate.

1 Like

I am suspicious my SHIFT key has a hidden agenda to make my life miserable.

Hi. Couple of suggestions that may help...

  1. Be consistent in variable naming. E.g. choose a naming method like camelCase and stick to it. It will help at times like this. See here
  2. Use the "copy path" button in the debug output that appears on the far right when you hover over a msg property. The exact and correct spelling will be copied to the clipboard ready to paste into your switch/change nodes. See here
1 Like

Thanks.

I think that old things that were beaten into me aren't helping.

When I "start typing a new sentence", I put a capitol letter. That can be problematic with variable names and when I type the description in the block description.

But yes, I am trying to do what you said with the names and I do try to copy/paste names.