3

I am in the middle of a project where I having to connect some IoT devices to azure using IoTHub. I have been following this guide: https://learn.microsoft.com/en-us/samples/azure-samples/functions-js-iot-hub-processing/processing-data-from-iot-hub-with-azure-functions/

And things are working fine, I have a device connected to the IoTHub called MyPythonDevice, so now in my code I would like to see this deviceId. In the examples given in the article above, we see a deviceId, but for me that is undefined if I log it.

So I was searching and found the following code snippet:

context.log(context.bindingData.systemProperties["iothub-connection-device-id"])

But this returns the follwing

Exception: TypeError: Cannot read property 'iothub-connection-device-id' of undefined

That means that systemProperties is undefined..

Any help on how to get the deviceId ?

Shadesfear
  • 749
  • 4
  • 17

2 Answers2

6

Try this:

context.bindingData.systemPropertiesArray[0]["iothub-connection-device-id"]
kgalic
  • 2,441
  • 1
  • 9
  • 21
0

This Works:

    public static string Run([EventHubTrigger("EventHubName", Connection = "EventHubConnectionAppSetting", ConsumerGroup = "xxxxx")] EventData eventMsg, DateTime enqueuedTimeUtc, ILogger log) {
var deviceId = eventMsg.SystemProperties["iothub-connection-device-id"].ToString();}
Gowtham
  • 635
  • 1
  • 7
  • 17