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?
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
Funny enough that's how I found out there wasn't any properties on msg.
That's just completely wrong. An issue needs to be raised against whatever node is sending a string as a message.
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.
Just out of curiosity, would I be able to use a function node to capture the string and output it as the payload object?
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.
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.
did you try a function node just looking at msg like you suggested ? If in doubt try it
Yea i gave it a try but nothing was captured.
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;