在Azure函数中从iothub获取deviceId

我处于一个项目的中间,我必须使用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的任何帮助?

format_88 回答:在Azure函数中从iothub获取deviceId

尝试一下:

context.bindingData.systemPropertiesArray[0]["iothub-connection-device-id"]
,

这个作品:

    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();}
本文链接:https://www.f2er.com/3151553.html

大家都在问