[英]How to receive from IoT Hub the all messages a specific device sent?
该代码将消息发送到IoT中心,该中心将消息存储在BLOB存储中。
_device = DeviceClient.Create(_iotHubUri, new
DeviceAuthenticationWithRegistrySymmetricKey(_deviceId, _deviceKey),
TransportType.Amqp_Tcp_Only);
await _device.OpenAsync();
await _device.SendEventAsync(message);
我在Azure门户中看到该消息。
我不明白的是如何从设备已发送的IoT中心获取所有消息 (C#)?
Azure IoT中心是用于设备中实时物联网流管道的入口网关。 从这个物联网流管道可以捕获(过滤)任何特定事件,在时间窗口中分析事件等。
基本上,(从Azure IoT中心的角度来看),可以在两个地方过滤此流管道,例如:
借助内置的Azure IoT中心路由功能,可以根据路由查询字符串将设备事件路由到自定义终结点,请参阅此处的更多详细信息。 请注意,存在一些限制,例如路由的最大数量(100)和自定义端点的最大数量(10)。
在Azure IoT中心之外,作为流管道的使用者。 简单的方法是使用Azure EventHubTrigger函数,请参见示例中的更多详细信息。
下面的代码片段显示了EventHubTrigger函数的示例:
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($"\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}"))}");
}
function.json文件:
{
"bindings": [
{
"type": "eventHubTrigger",
"name": "myIoTHubMessage",
"direction": "in",
"path": "myIoTHubName",
"connection": "myIoTHubConnectionString",
"consumerGroup": "function"
}
],
"disabled": false
}
注意,可以从systemproperties [“ iothub-connection-device-id”]获取deviceId。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.