从设备到云通信指南Device-to-cloud communications guidance

将信息从设备应用发送到解决方案后端时,IoT 中心会公开三个选项:When sending information from the device app to the solution back end, IoT Hub exposes three options:

  • 设备到云消息,用于时序遥测和警报。Device-to-cloud messages for time series telemetry and alerts.

  • 设备孪生的报告属性,用于报告设备状态信息,例如可用功能、条件或长时间运行的工作流的状态。Device twin's reported properties for reporting device state information such as available capabilities, conditions, or the state of long-running workflows. 例如,配置和软件更新。For example, configuration and software updates.

  • 文件上传,用于由间歇性连接的设备上传的或为了节省带宽而压缩的媒体文件和大型遥测批文件。File uploads for media files and large telemetry batches uploaded by intermittently connected devices or compressed to save bandwidth.

备注

本文中提到的某些功能(例如云到设备消息传递、设备孪生、设备管理)仅在 IoT 中心的标准层中提供。Some of the features mentioned in this article, like cloud-to-device messaging, device twins, and device management, are only available in the standard tier of IoT hub. 有关基本和标准 IoT 中心层的详细信息,请参阅如何选择合适的 IoT 中心层For more information about the basic and standard IoT Hub tiers, see How to choose the right IoT Hub tier.

下面是各种设备到云通信选项的详细比较。Here is a detailed comparison of the various device-to-cloud communication options.

设备到云的消息Device-to-cloud messages 设备克隆的报告属性Device twin's reported properties 文件上传File uploads
方案Scenario 遥测时序和警报。Telemetry time series and alerts. 例如,每隔 5 分钟发送 256-KB 的传感器数据批。For example, 256-KB sensor data batches sent every 5 minutes. 可用功能和条件。Available capabilities and conditions. 例如,当前设备连接模式,诸如手机网络或 WiFi。For example, the current device connectivity mode such as cellular or WiFi. 同步长时间运行的工作流,如配置和软件更新。Synchronizing long-running workflows, such as configuration and software updates. 媒体文件。Media files. 大型(通常为压缩的)遥测批。Large (typically compressed) telemetry batches.
存储和检索Storage and retrieval 通过 IoT 中心临时进行存储,最多存储 7 天。Temporarily stored by IoT Hub, up to 7 days. 仅顺序读取。Only sequential reading. 通过 IoT 中心存储在设备孪生中。Stored by IoT Hub in the device twin. 可使用 IoT 中心查询语言进行检索。Retrievable using the IoT Hub query language. 存储在用户提供的 Azure 存储帐户中。Stored in user-provided Azure Storage account.
大小Size 消息大小最大为 256-KB。Up to 256-KB messages. 最大报告属性大小为 32 KB。Maximum reported properties size is 32 KB. Azure Blob 存储支持的最大文件大小。Maximum file size supported by Azure Blob Storage.
频率Frequency 高。High. 有关详细信息,请参阅 IoT 中心限制For more information, see IoT Hub limits. 中。Medium. 有关详细信息,请参阅 IoT 中心限制For more information, see IoT Hub limits. 低。Low. 有关详细信息,请参阅 IoT 中心限制For more information, see IoT Hub limits.
协议Protocol 在所有协议上可用。Available on all protocols. 使用 MQTT 或 AMQP 时可用。Available using MQTT or AMQP. 在使用任何协议时可用,但设备上必须具备 HTTPS。Available when using any protocol, but requires HTTPS on the device.

应用程序可能需要同时将信息作为遥测时序或警报发送,并且使其在设备孪生中可用。An application may need to send information both as a telemetry time series or alert and make it available in the device twin. 在这种情况下,可以选择以下选项之一:In this scenario, you can choose one of the following options:

  • 设备应用发送一条设备到云消息并报告属性更改。The device app sends a device-to-cloud message and reports a property change.
  • 解决方案后端在收到消息时可将信息存储在设备孪生的标记中。The solution back end can store the information in the device twin's tags when it receives the message.

由于设备到云消息允许的吞吐量远高于设备孪生更新,因此有时需要避免为每条设备到云消息更新设备孪生。Since device-to-cloud messages enable a much higher throughput than device twin updates, it is sometimes desirable to avoid updating the device twin for every device-to-cloud message.