I am writing this as I am on another quest to try and get my head around how to do something.
Taking it to basics - the flow:
[{"id":"75a8babad6400d8f","type":"inject","z":"7e987ddf260bdf0d","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":4180,"y":2310,"wires":[["47405ea11fe09c0c"]]},{"id":"47405ea11fe09c0c","type":"function","z":"7e987ddf260bdf0d","name":"Example 2","func":"msg = { \"WIFI_DEVICE\": \"TelePi\", \"IP_Address\": \"192.168.0.93\", \"Sent\": \"2022-04-27 07:24:54\" };\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":4350,"y":2310,"wires":[["6b24df8a1f645f03","50fe4009ba4846bf"]]},{"id":"6b24df8a1f645f03","type":"function","z":"7e987ddf260bdf0d","name":"","func":"let x = \"WIFI_DEVICE\";\nlet y = \"msg.\"+x;\nnode.warn(y);\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":4520,"y":2310,"wires":[[]]}]
The message being sent in is this (example)
{"WIFI_DEVICE":"TelePi","IP_Address":"192.168.0.93","Sent":"2022-04-27 07:24:54","_msgid":"bf56e1984a7c7ab2"}
In the second function
node I want to define which sub part of the message I want to get/see.
Alas rather than getting the value, I get the path.
This may be easier to explain:
let x = "WIFI_DEVICE";
let y = "msg."+x;
node.warn(y);
return msg;
x
is the path I create the path name (let y = "msg."+x
) but then I get that echoed to me.
I want to see the value of where that is pointing. (I think is the term)
So I should get TelePi
.
Efforts:
let x = "WIFI_DEVICE";
let y = "msg."+x;
node.warn(y); // a
node.warn(msg.WIFI_DEVICE); // b
node.warn(msg.x); // c
return msg;
a
gets what I've shown.
b
works.
c
doesn't.
Trying to .... concatenate the msg.
and x
isn't working if I put a +
sign.
Ok, maybe I am wrong with one of those... I'm working on it now, in real time.
It's impossible to keep the thread up to date with what is happening now.
I'm asking if someone could confirm how to do this before I go any more batty than I already am.