Set Object name from msg.topic?

Hi All, I'm banging my head with this and I'm sure the answer is obvious but I can't find the search term or work it out.

I'm pinging a series of devices with the ping node I want to create a message object that contains device:ping_value

All the info is in there as msg.topic contains the device name
And msg.payload contains the ping value

sadly this doesn't work.

msg.payload = {msg.topic:msg.payload}; 
return msg;

so how can I combine the two?

At present I'm making a bunch of function nodes that are manually setting the object name.

msg.payload = {
    Rpi2White:msg.payload
};
return msg;

Something like

let value = msg.payload
msg.payload = {}
msg.payload[msg.topic] = value

Perfect thank you so very much.

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