我有一个由 IOThub 触发的 Azure 函数。所以在Azure功能中,我有
public static async Task Run(EventData myIoTHubMessage1, TraceWriter log)
如何从事件数据中获取设备 ID。
我试过了
log.Info("devid="+myIoTHubMessage1.SystemProperties["ConnectionDeviceId"]);
它给出了一个错误,说
The given key was not present in the dictionary.
下面的文件说 https://learn.microsoft.com/en-us/azure/iot-hub/iot-hub-devguide-messages-construct
ConnectionDeviceId 包含设备 ID。有人知道如何从 EventData 检索 deviceid 还是我应该使用其他类。
最佳答案
您可以从SystemProperties
获取设备ID:
public static async Task Run(EventData myIoTHubMessage1, TraceWriter log)
{
var deviceId = myIoTHubMessage1.SystemProperties["iothub-connection-device-id"];
// ....
}
关于azure - 如何在Azure函数中获取由IOThub消息触发的消息的deviceid,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48954173/