我处于一个项目的中间,我必须使用IoTHub将一些IoT设备连接到天蓝色。我一直在遵循此指南:https://docs.microsoft.com/en-us/samples/azure-samples/functions-js-iot-hub-processing/processing-data-from-iot-hub-with-azure-functions/
一切正常,我有一个连接到IoTHub的设备MyPythonDevice,所以现在在我的代码中我想看到这个deviceId。在以上文章中给出的示例中,我们看到了一个deviceId,但是对我来说,如果我登录它,它就是undefined
。
因此我正在搜索并找到以下代码片段:
context.log(context.bindingData.systemProperties["iothub-connection-device-id"])
但这将返回以下
Exception: TypeError: Cannot read property 'iothub-connection-device-id' of undefined
这意味着systemProperties
未定义。
有关如何获取deviceId的任何帮助?
答案 0 :(得分:0)
尝试一下:
context.bindingData.systemPropertiesArray[0]["iothub-connection-device-id"]
答案 1 :(得分:0)
这个作品:
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();}