如何将 IoT Edge 设备用作网关How an IoT Edge device can be used as a gateway

IoT Edge 解决方案中的网关为 IoT 设备提供了设备连接和边缘分析,否则这些设备将不具备这些功能。Gateways in IoT Edge solutions provide device connectivity and edge analytics to IoT devices that otherwise wouldn't have those capabilities. Azure IoT Edge 可用于满足对 IoT 网关的任何需求,无论该需求是否与连接、标识或边缘分析有关。Azure IoT Edge can be used to satisfy any need for an IoT gateway, whether it's related to connectivity, identity, or edge analytics. 本文中的网关模式仅指下游设备连接和设备标识的特征,而不是指在网关上处理设备数据的方式。Gateway patterns in this article only refer to characteristics of downstream device connectivity and device identity, not how device data is processed on the gateway.

模式Patterns

将 IoT Edge 设备用作网关有三种模式:透明、协议转换和标识转换:There are three patterns for using an IoT Edge device as a gateway: transparent, protocol translation, and identity translation:

  • 透明 – 理论上可以连接到 IoT 中心的设备可以改为连接到网关设备。Transparent – Devices that theoretically could connect to IoT Hub can connect to a gateway device instead. 下游设备有其自己的 IoT 中心标识,并将使用任一 MQTT、AMQP 或 HTTP 协议。The downstream devices have their own IoT Hub identities and are using any of the MQTT, AMQP, or HTTP protocols. 网关只是在设备与 IoT 中心之间传递通信。The gateway simply passes communications between the devices and IoT Hub. 设备和通过 IoT 中心与其交互的用户都不知道网关正在协调它们的通信。Both the devices and the users interacting with them through IoT Hub are unaware that a gateway is mediating their communications. 这种缺乏感知意味着网关被认为是透明的 。This lack of awareness means that the gateway is considered transparent. 请参阅创建透明网关,了解有关将 IoT Edge 设备用作透明网关的详细信息。Refer to Create a transparent gateway for specifics on using an IoT Edge device as a transparent gateway.
  • 协议转换 - 也称为不透明网关模式,不支持 MQTT、AMQP 或 HTTP 的设备可以使用网关设备以它们的名义将数据发送到 IoT 中心。Protocol translation – Also known as an opaque gateway pattern, devices that do not support MQTT, AMQP, or HTTP can use a gateway device to send data to IoT Hub on their behalf. 网关了解下游设备使用的协议,并且是 IoT 中心中唯一具有标识的设备。The gateway understands the protocol used by the downstream devices, and is the only device that has an identity in IoT Hub. 所有信息好像都来自一台设备,即网关。All information looks like it is coming from one device, the gateway. 如果云应用程序想要以设备位单位分析数据,则下游设备就必须在其消息中嵌入额外的标识信息。Downstream devices must embed additional identifying information in their messages if cloud applications want to analyze the data on a per-device basis. 此外,IoT 中心基元(例如孪生和方法)仅适用于网关设备,而不适用于下游设备。Additionally, IoT Hub primitives like twins and methods are only available for the gateway device, not downstream devices.
  • 标识转换 - 无法连接到 IoT 中心的设备可以改为连接到网关设备。Identity translation - Devices that cannot connect to IoT Hub can connect to a gateway device, instead. 网关代表下游设备提供 IoT 中心标识和协议转换。The gateway provides IoT Hub identity and protocol translation on behalf of the downstream devices. 网关非常智能,它能够理解下游设备使用的协议,为其提供标识,并转换 IoT 中心基元。The gateway is smart enough to understand the protocol used by the downstream devices, provide them identity, and translate IoT Hub primitives. 下游设备作为一流设备出现在 IoT 中心,随附克隆和方法。Downstream devices appear in IoT Hub as first-class devices with twins and methods. 用户可以与 IoT 中心的设备进行交互,但并觉察不到中间网关设备。A user can interact with the devices in IoT Hub and is unaware of the intermediate gateway device.

关系图 - 透明、协议和标识网关模式

用例Use cases

所有网关模式提供以下优势:All gateway patterns provide the following benefits:

  • 边缘分析 – 在本地使用 AI 服务处理来自下游设备的数据,而无需向云发送完全保真的遥测数据。Analytics at the edge – Use AI services locally to process data coming from downstream devices without sending full-fidelity telemetry to the cloud. 本地查找和响应见解,并仅将一部分数据发送到 IoT 中心。Find and react to insights locally and only send a subset of data to IoT Hub.
  • 下游设备隔离 – 网关设备可以屏蔽所有下游设备,而不对 Internet 公开。Downstream device isolation – The gateway device can shield all downstream devices from exposure to the internet. 它可以位于无连接的 OT 网络和提供 Web 访问权限的 IT 网络之间。It can sit in between an OT network that does not have connectivity and an IT network that provides access to the web.
  • 连接多路复用 - 通过 IoT Edge 网关连接到 IoT 中心的所有设备使用同一个基础连接。Connection multiplexing - All devices connecting to IoT Hub through an IoT Edge gateway use the same underlying connection.
  • 流量平滑 - 在本地保存消息的同时,如果 IoT 中心对流量进行限制,IoT Edge 设备将自动执行指数回退。Traffic smoothing - The IoT Edge device will automatically implement exponential backoff if IoT Hub throttles traffic, while persisting the messages locally. 此优点使解决方案能灵活应对流量高峰。This benefit makes your solution resilient to spikes in traffic.
  • 脱机支持 - 网关设备存储不能传递到 IoT 中心的消息和孪生更新。Offline support - The gateway device stores messages and twin updates that cannot be delivered to IoT Hub.

此外,执行协议转换的网关还可以对现有设备和资源受限的新设备执行边缘分析、设备隔离、流量平滑和脱机支持。A gateway that does protocol translation can also perform edge analytics, device isolation, traffic smoothing, and offline support to existing devices and new devices that are resource constrained. 许多现有设备将生成能够为企业提供见解的数据;然而,它们的设计并未考虑云连接。Many existing devices are producing data that can power business insights; however they were not designed with cloud connectivity in mind. 不透明的网关允许解锁这些数据,并在 IoT 解决方案中使用这些数据。Opaque gateways allow this data to be unlocked and used in an IoT solution.

实现标识转换的网关提供了协议转换的好处,并且还允许从云完全管理下游设备。A gateway that does identity translation provides the benefits of protocol translation and additionally allows for full manageability of downstream devices from the cloud. IoT 解决方案中的所有设备都显示在 IoT 中心内,不管它们使用的是什么协议。All devices in your IoT solution show up in IoT Hub regardless of the protocol they use.

备忘单Cheat sheet

下面一个速查表,用于在使用透明、不透明(协议)和代理网关时比较 loT 中心基元。Here is a quick cheat sheet that compares IoT Hub primitives when using transparent, opaque (protocol), and proxy gateways.

基元Primitive 透明网关Transparent gateway 协议转换Protocol translation 标识转换Identity translation
存储在 IoT 中心标识注册表中的标识Identities stored in the IoT Hub identity registry 所有已连接的设备的标识Identities of all connected devices 仅网关设备的标识Only the identity of the gateway device 所有已连接的设备的标识Identities of all connected devices
设备孪生Device twin 每个已连接的设备均有自己的设备孪生Each connected device has its own device twin 仅网关具有设备和模块孪生Only the gateway has a device and module twins 每个已连接的设备均有自己的设备孪生Each connected device has its own device twin
直接方法和云到设备的消息Direct methods and cloud-to-device messages 云可以对每个已连接的设备单独寻址The cloud can address each connected device individually 云只能对网关设备寻址The cloud can only address the gateway device 云可以对每个已连接的设备单独寻址The cloud can address each connected device individually
IoT 中心限制和配额IoT Hub throttles and quotas 适用于每个设备Apply to each device 适用于网关设备Apply to the gateway device 适用于每个设备Apply to each device

使用不透明网关(协议转换)模式时,通过该网关连接的所有设备共享同一个可包含最多 50 条消息的云到设备的队列。When using an opaque gateway (protocol translation) pattern, all devices connecting through that gateway share the same cloud-to-device queue, which can contain at most 50 messages. 它遵循的原则是,仅当很少设备通过各字段网关进行连接以及云到设备的流量较低时,才使用不透明网关模式。It follows that the opaque gateway pattern should be used only when few devices are connecting through each field gateway, and their cloud-to-device traffic is low.

后续步骤Next steps

了解如何设置透明网关:Learn how to set up a transparent gateway: