如何在IOThub消息触发的Azure函数中获取消息的设备ID [英] How to get deviceid of message in Azure function that is triggered by IOThub message

查看:115
本文介绍了如何在IOThub消息触发的Azure函数中获取消息的设备ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个由IOThub触发的Azure函数.所以在Azure功能中,我有

I have an Azure function that is triggered by IOThub. So in the Azure function, I have

public static async Task Run(EventData myIoTHubMessage1, TraceWriter log)

如何从事件数据中获取设备ID.

How do I get the device id from the Event Data.

我尝试了

log.Info("devid="+myIoTHubMessage1.SystemProperties["ConnectionDeviceId"]);

出现错误提示

The given key was not present in the dictionary.

以下文件说: https://docs.microsoft. com/en-us/azure/iot-hub/iot-hub-devguide-messages-construct

ConnectionDeviceId包含设备ID.有人会知道如何从EventData检索设备ID还是应该使用其他一些类.

ConnectionDeviceId contains the deviceId. Would anybody know how to retrieve the deviceid from EventData or should I use some other class.

推荐答案

您可以从SystemProperties获取设备ID:

You can get device ID from SystemProperties:

public static async Task Run(EventData myIoTHubMessage1, TraceWriter log)
{
    var deviceId = myIoTHubMessage1.SystemProperties["iothub-connection-device-id"];
    // ....
}

这篇关于如何在IOThub消息触发的Azure函数中获取消息的设备ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆