我使用IoT中心触发器创建了一个功能
log.Info($"C# IoT Hub trigger function processed a message: {Encoding.UTF8.GetString(message.GetBytes())}");
该功能仅记录消息。但是我如何获得发送消息的设备?
问候 斯蒂芬
答案 0 :(得分:2)
看看下面的例子:
using System;
public static void Run(string myIoTHubMessage, IDictionary<string, object> properties, IDictionary<string, object> systemproperties, TraceWriter log)
{
log.Info($"C# IoT Hub trigger function processed a message: \n\t{myIoTHubMessage}");
log.Info($"DeviceId = {systemproperties["iothub-connection-device-id"]}");
log.Info($"\nSystemProperties:\n\t{string.Join("\n\t", systemproperties.Select(i => $"{i.Key}={i.Value}"))}");
log.Info($"\nProperties:\n\t{string.Join("\n\t", properties.Select(i => $"{i.Key}={i.Value}"))}");
}