[英]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.