Hello,
after a lot of trying I got my MQTT Server up and running.
Now I try to process the messages in node-red…
I get a nested object like this:
25.1.2024, 21:37:12node: debug
sn : msg : Object
object
topic: “sn”
payload: object
Time: “2024-01-25T20:45:43”
SML: object <–This is the section I need the values from…
1_8_0: 7895.09949886 <–
1_8_1: 1.017 <–
1_8_2: 7894.08249886 <–
2_8_0: 274.54115471 <–
16_7_0: 319 <–
36_7_0: 185 <–
56_7_0: 10 <–
76_7_0: 125 <–until here….
96_1_0: “090145425a0100137d3b”
qos: 0
retain: true
parts: object
id: “39b59c1733c428c0”
type: “object”
key: “sn”
index: 0
count: 2
_msgid: “2bbb4e8169a5b67a”
How can I separate and name the values to feed them to a dashboard?
Hi.
Are you following a specific project?
Can you provide more details about what you want to do?
It seems to me that you want to parse a json object, but I’m not sure that I understood your question? https://cookbook.nodered.org/mqtt/receive-json
Regards,
Sara
Hi Sara,
thank you for your quick reply I do not follow a prebuilt project. I want to get all the data from my solar installation to a dashboard and later add some functionality to switch a battery on and off depending on the values.
At my power meter I installed a tasmota device which is sending MQTT messages to a broker on a raspberry pi.
the values coming from the tasmota- sensors-node are shown in my last post. What I need is a function to extract the numerical values after “SML: object” to 8 separate outputs to be able to prrocess them , feed them to a influxdb bucket and show them on the dashboard.
Here is a screenshot from my nodered: https://www.dropbox.com/scl/fi/obxr68amzk5t47xdlkg4q/noderedFlow-2024-01-26-18-02-55.png?rlkey=e8f9wweyrlknr2l25dob11bck&dl=0
I tried a function like this:
var msg1 = { payload: “first out of output 1” };
var msg2 = { payload: “first out of output 2” };
var msg3 = { payload: “first out of output 3” };
var msg4 = { payload: “first out of output 4” };
var msg5 = { payload: “first out of output 5” };
var msg6 = { payload: “first out of output 6” };
return msg;
it returns the complete message of the tasmota-node at all the outputs, but I just want the 8 numeric values after SML:object. The leading string (e.g. 1_8_0:) should be omitted, I will use them only to find meaningful names for the variables like “total power” or so…
Hi.
I recommend taking a look at these discussions:
https://discourse.nodered.org/t/retrieving-variables-from-payload-object/13101/5
https://discourse.nodered.org/t/extract-data-from-object/89/4
And read this page:
https://nodered.org/docs/user-guide/messages
I hope this helps.
Regards,
Sara
Thanks Sara,
the links above were interesting but not very close to my problem. Is there any example with a data structure very similar to the Objects I posted? I need the numerical values contained in the string after SML as an output to my dashboard and Influx database.
A function like this
msg.payload.sn.SML[“16_7_0”]
return msg;
yields the complete Object –>
object
sn: object
Time: “2024-01-29T19:51:09”
SML: object
1_8_0: 7926.11222099
1_8_1: 1.017
1_8_2: 7925.09522099
2_8_0: 275.67717328
16_7_0: 319
36_7_0: 184
56_7_0: 10
76_7_0: 125
96_1_0: “090145425a0100137d3b”
ver: 1
A function like this would give me the number but it is not allowed…
return msg.payload.sn.SML[“16_7_0”];
I get an Error: ““Function tried to send a message of type number”
Well, that`s what I want :-)) But it just tries…
How can I make it to really send this number?