带有 IoT 中心触发器的 Azure 函数获取发送设备
Azure function with IoT Hub trigger get send device
我使用 IoT 中心触发器创建了一个函数
log.Info($"C# IoT Hub trigger function processed a message: {Encoding.UTF8.GetString(message.GetBytes())}");
函数仅记录消息。但是我怎样才能得到发送消息的设备呢?
问候
斯特凡
看看下面的例子:
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}"))}");
}
我使用 IoT 中心触发器创建了一个函数
log.Info($"C# IoT Hub trigger function processed a message: {Encoding.UTF8.GetString(message.GetBytes())}");
函数仅记录消息。但是我怎样才能得到发送消息的设备呢?
问候 斯特凡
看看下面的例子:
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}"))}");
}