Msg.payload undefined - message object

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.

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
1 Like

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)

Thank you!

Hi,
I have a similar question, so I just didn't open a new threat.

I tried do get data from Ubidots, but I'm not able to get the data into my msg.payload.

If I activate node-state, I get following result:

{ data_1: { value:0 } }

The communication between ubidots and nodered works well. It's just this little problem I can't solve yet.

Thanks for help.

Welcome to the forum @tbet.

You haven't said what the problem is. Note that in the debug window if you click on object it will expand that so you can see what is there. If you don't know how to get the data out of the object (if that is what you need to do) have a read of the node-red docs page Working with Messages which will help you to do that. Also, if you are a beginner then watch the excellent Node red Essentials videos linked from the node red docs.

Hi Colin, thanks for your quick answer.

What I want at the end is to write the value of the variable that I get from Ubidots into a variable existing at PLC S7-1500.
The connection to PLC already works, but what I need is to format the Ubidots input message into boolean value that I can work with.

I just want to exclude the rest of the message that there is only the 0 (false) or 1 (true).

All in all I just want to convert "{ data_1: { value:0} }" into "0".

Thanks.

So yes - you can use a change node to move the property you want to the payload - and as Colin said

https://nodered.org/docs/user-guide/messages

as that will give you all you need to work out how to access the value.

Thanks for your hints. I got it.

1 Like