I have created one IOT Hub in Azure and added two devices in that. I am sending same message from both of the device. I have also created one function app in Azure. The function is triggering with Azure IoT Hub and it saving data to azure storage table. All things are working as per expectation. Now I want to filter message using device id. I meant my azure function app should recognize the message is came from which device.
Here is my function app java script code
module.exports = function (context, iotHubMessage) {
context.log(iotHubMessage.length + ' Message received');
var date = Date.now();
var partitionKey = Math.floor(date / (24 * 60 * 60 * 1000)) + '';
var rowKey = date;
context.bindings.messageLog1 = {
"partitionKey": partitionKey,
"rowKey": rowKey + '',
"MsgCount": iotHubMessage.length,
"data": JSON.stringify(iotHubMessage)
};
var defaultData = [];
for (var i = 0; i < iotHubMessage.length; i++) {
var iotMsgObj = iotHubMessage[i];
iotMsgObj.CreatedDate = new Date();
defaultData.push({ "partitionKey": partitionKey, "rowKey": (rowKey+i) + '', "data": JSON.stringify(iotMsgObj) });
}
context.bindings.pbDefaultPara1 = defaultData;
context.done();
};
Thanks!