I need to read the persistent data and combine it into a single piece of text

Hello, as shown in the picture
1111

I want to read them out and arrange them into a text
The format looks like this:
{"a": load__v data, "b": fan_v data, "c": fan_A data}
And so on
I tried a lot of things but couldn't put them together
Can you help me
Thank you very much

This is a job for the template node
e.g.

[{"id":"b75fcc44.64f79","type":"inject","z":"b779de97.b1b46","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":130,"y":4840,"wires":[["fafe62fc.c05b88"]]},{"id":"fafe62fc.c05b88","type":"template","z":"b779de97.b1b46","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{\"a\": {{global.load_v}}, \"b\": {{global.fan_v}}, \"c\": {{global.fan_a}}}","output":"str","x":290,"y":4840,"wires":[["51b9b0de.3f9dd"]]},{"id":"51b9b0de.3f9dd","type":"debug","z":"b779de97.b1b46","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":500,"y":4840,"wires":[]}]
{"a": {{global.load_v}}, "b": {{global.fan_v}}, "c": {{global.fan_a}}}

from the template help info

It is possible to use a property from the flow context or global context. Just use {{flow.name}} or {{global.name}} , or for persistable store store use {{flow[store].name}} or {{global[store].name}} .

That's great. He fulfilled my needs perfectly. Thank you very much

I am interested in knowing why you need to make a string of that form. It is not very common to need to do that.

It is more complicated, I have someone customized a modbus to JSON device, his network data format is such.....

OK, the other way to do this would be to use a Change node to make a javascript object with those values, then feed it through a JSON node to convert it to JSON. There is no great advantage to doing it that way other than it reduces the likelihood of typos when building the JSON string manually.

Can you send a routine
I want to compare that

Here is the start of the Change node setup, you can add extra entries for the other data items. It starts by setting msg.payload to an empty object, then sets msg.payload.a to the global load_v. Add the extra rows for the others.

image

Then feed that into a JSON node it will convert it to a JSON string.

thank you
I'll test this routine

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