Msg root to file

#1

I'm using the Azure IoT hub palette to resgister a device which responds with a key. This key I'm trying to save into a file but the Azure node responds back with msg and not msg.payload so the file node is not catching anything.

I also tried using change to move msg to msg.payload before the file node but it doesn't like it when I leave the source as just msg (blank).

anyone know how to capture the msg root itself?

0 Likes

#2

can you send the whole msg to a debug node and see what it contains ? (You have to configure the debug node to see complete msg). It can't really just be sending msg as all msg have to be objects.

PS don't paste the key here :slight_smile:

0 Likes

#3

Funny enough that's how I found out there wasn't any properties on msg.

0 Likes

#4

That's just completely wrong. An issue needs to be raised against whatever node is sending a string as a message.

0 Likes

#5

I guess I'll open an issue on the authors GitHub. I'm new to node-red so I wasn't sure if i was doing something wrong.

0 Likes

#6

Just out of curiosity, would I be able to use a function node to capture the string and output it as the payload object?

0 Likes

#7

Is that debug display showing the whole msg object or is it showing the msg.payload? If the former then you can't even expect any of the nodes to handle a string instead of an object as a msg - though some will likely have catered for it. If it is msg.payload then you can handle it normally.

0 Likes

#8

Yes, debug is set to display the whole msg. The output from the node is a string not an object (payload), hence the predicament. I was simply wondering if there was anything I could do on my end instead of waiting for the author to fix the node.

0 Likes

#9

did you try a function node just looking at msg like you suggested ? If in doubt try it :slight_smile:

0 Likes

#10

Yea i gave it a try but nothing was captured.

0 Likes

#12

Just in case anyone else ends up with the same issue (not being able to get errors during the device registration to the Azure IoT hub) I'm adding my code below.

var iothub = global.get('iothub'); //needs to have settings.js modification
var connectionString = '';
var registry = iothub.Registry.fromConnectionString(connectionString);


// Create a new device
var device = {
    deviceId: msg.piInfo.deviceId
};



registry.create(device, function(err, deviceInfo, res) {
    if (err)        node.send({hubError:err.toString()});
    if (res)        node.send({hubResponse:res.statusMessage});
    if (deviceInfo) node.send({hubInfo:deviceInfo});
});


return msg;
0 Likes