Msg.payload undefined - message object

#1

Hi,
I have been stuck on this problem for hours. It is probably an easy thing to solve, but the forum nor google resulted in a solution.

when i debug the node i get the following:
2018-11-17 22:28:18 node: msg.payload : undefined
undefined

when i look at full message i get the following:
2018-11-17 22:28:18[ ode: msg : Object
{ class: "sensor", protocol: "fineoffset", id: 247, model: "temperaturehumidity", humidity: 45 …}

If i expand it looks like this:
2018-11-17 22:28:18 node: msg : Object
object
class: "sensor"
protocol: "fineoffset"
id: 247
model: "temperaturehumidity"
humidity: 45
temp: 26.5
_msgid: "e1432419.b8f6f8"

All i want to do is to get the humidity and temp into msg.payload so i can use the values further in the flow.

0 Likes

#2

Do you mean you are starting with the message that you have shown and you want to end up with the payload being an object containing just the temperature and humidity?
If so then you want something like

msg.payload = {humidity: msg.humidity, temp: msg.temp}
return msg
0 Likes

#3

Slightly odd that the source provides the data like that... but...
simplest would be to use a change node to move msg.temp to msg.payload.temp and likewise humidity.

(or indeed a small function as per Colin's post above)

0 Likes

#4

Thank you!

0 Likes