Birdy
15 April 2020 11:50
1
Hi,
I have this specific JSON-Object:
15.4.2020, 13:46:47node: 8ab35232.361e7
tele/TB01_Orgon/SENSOR : msg : Object
object
topic: "tele/TB01_Orgon/SENSOR"
payload: object
Time: "2020-04-15T12:46:47"
SDS0X1: object
PM2.5: 3.7
PM10: 6.9
qos: 0
retain: false
_msgid: "142a99e1.7fd376"
I try to read the PM2.5 and the PM10 values from the object like this:
msg.PM25 = msg.payload.SDS0X1+".PM2.5";
msg.PM10 = msg.payload.SDS0X1+".PM10";
But the output I get looks like this ... and that's not what I want
PM25: "[object Object].PM2.5"
PM10: "[object Object].PM10"
Any ideas whats going wrong here ?
BR
Birdy
The statement:
msg.PM25 = msg.payload.SDS0X1+".PM2.5";
Is asking it to turn msg.payload.SDS0X1
into a String and then join the string ".PM2.5"
to the end of it. Because msg.payload.SDS0X1
is an Object, when it gets converted to a string, you get "[object Object]"
.
The syntax you need is:
msg.PM25 = msg.payload.SDS0X1["PM2.5"]
msg.PM10 = msg.payload.SDS0X1["PM10"]
If you haven't already, its worth reading this page of the docs - https://nodered.org/docs/user-guide/messages
It explains how, using the Debug sidebar, you can get the path to any element of a message.
system
Closed
29 April 2020 12:19
3
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.