How to access mulitple payloads from function node?

Hi folks,

i read a very interesting thing about storing multiple values in one payload with using a function node. It is described here.
But how can i access this multiple values e.g. show it values on a dashboard with a text node? Can you show me an example?
At the moment i use such a construct to do this, but i think i could improve this with multiple payloads?

Thanks!

If you look at the Help tab for the ui-test and ui-gauge nodes you will see they are expecting the value tto be in msg.payload:

text

Will display a non-editable text field on the user interface.

Each received msg.payload will update the text based on the provided Value Format .

gauge

Adds a gauge type widget to the user interface.

The msg.payload is searched for a numeric value and is formatted in accordance with the defined Value Format , which can then be formatted using Angular filters.

So you need to put the data in msg.payload. You coud always add a change node after each function node to set msg.payload to what ever part of the msg needs to be put in it.

Not knowing the format of the data, there is no way to tell you exactly, but you shoud be able to work that out.

Here is an example of accessing different properties in a payload in a gauge and text node.
msg.payload.temp holds the temperature value 20 and msg.payload.text holds the string for the ui text node.

[{"id":"d768963a.3a79d","type":"inject","z":"c74669a0.6a34f8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"temp\":20,\"text\":\"her is some text\"}","payloadType":"json","x":130,"y":2960,"wires":[["dc2de9a2.425a88","f9b3ccf.c67f6b"]]},{"id":"dc2de9a2.425a88","type":"ui_text","z":"c74669a0.6a34f8","group":"8b5cde76.edd58","order":9,"width":0,"height":0,"name":"","label":"text","format":"{{msg.payload.text}}","layout":"row-spread","x":320,"y":3000,"wires":[]},{"id":"f9b3ccf.c67f6b","type":"ui_gauge","z":"c74669a0.6a34f8","name":"","group":"8b5cde76.edd58","order":8,"width":0,"height":0,"gtype":"gage","title":"gauge","label":"units","format":"{{msg.payload.temp}}","min":0,"max":10,"colors":["#00b500","#e6e600","#ca3838"],"seg1":"","seg2":"","x":280,"y":2940,"wires":[]},{"id":"8b5cde76.edd58","type":"ui_group","name":"","tab":"8f03e639.85956","order":1,"disp":true,"width":"12","collapse":false},{"id":"8f03e639.85956","type":"ui_tab","name":"Home","icon":"dashboard","disabled":false,"hidden":false}]

Your example with the inject node is working :+1:

In a function node, i have to set the payload in the following syntax:

msg.payload = {"temp":20,"text":"her is some text"};
return msg;

Is there no easier way? Like:

msg.payload.temp = "20";
msg.payload.text = "her is some text";

??

That should work as well as long as msg.payload is an object;
e.g.

msg.payload = {};
msg.payload.temp = "20";
msg.payload.text = "her is some text";

Thank you very much!

The solution was:
msg.payload = {};

Now the flow looks more cleaner:

And the code in the function is more easy to maintain:

const arrPayload = msg.payload.split(",");
var vTS = arrPayload[0].slice(9);
vTS = vTS.split("T");
//Zeitstempel
var vDS = vTS[0].split("-");
var vDate = vDS[2] + "." + vDS[1] + "." + vDS[0];
var vTime = vDate + "\t" + vTS[1].slice(0, (vTS[1].length - 1));
//Temperatur Kollektor
var vKollektor = arrPayload[1].slice(17);
//Temperatur Pufferspeicher
var vPuffer = arrPayload[2].slice(6)
//Temperatur Vorlauf Pufferspeicher
var vVorPuffer = arrPayload[3].slice(8)
//Temperatur Vorlauf Solar
var vVorSolar = arrPayload[4].slice(11)
//Status Pumpe
var vStatus = arrPayload[5].slice(8)
if (vStatus > 0){
  vStatus = "Ein " + vStatus + " %";
} else {
    vStatus = "Aus";
}
msg.payload = {};
msg.payload.pump1 = vStatus;
msg.payload.time = vTime;
msg.payload.tkoll = vKollektor;
msg.payload.tps = vPuffer;
msg.payload.vorps = vVorPuffer;
msg.payload.vorsolar = vVorSolar;
return msg;

:+1: :slightly_smiling_face:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.