您现在访问的是微软AZURE全球版技术文档网站,若需要访问由世纪互联运营的MICROSOFT AZURE中国区技术文档网站,请访问 https://docs.azure.cn.

什么是 IoT 即插即用?What is IoT Plug and Play?

通过 IoT 即插即用,解决方案构建者无需进行任何手动配置即可将智能设备集成到解决方案中。IoT Plug and Play enables solution builders to integrate smart devices with their solutions without any manual configuration. IoT 即插即用的核心是设备模型,设备通过设备模型将其功能告知支持 IoT 即插即用的应用程序。At the core of IoT Plug and Play, is a device model that a device uses to advertise its capabilities to an IoT Plug and Play-enabled application. 该模型被构造为一组元素,这些元素定义以下内容:This model is structured as a set of elements that define:

  • 属性:表示设备或其他实体的只读或可写状态。Properties that represent the read-only or writable state of a device or other entity. 例如,设备序列号可以是只读属性,而调温器上的目标温度可以是可写属性。For example, a device serial number may be a read-only property and a target temperature on a thermostat may be a writable property.
  • 遥测:设备发出的数据,包括常规的传感器读数流、偶发性错误或信息消息。Telemetry that's the data emitted by a device, whether the data is a regular stream of sensor readings, an occasional error, or an information message.
  • 命令:描述可在设备上执行的功能或操作。Commands that describe a function or operation that can be done on a device. 例如,命令可以重新启动网关,或使用远程相机拍照。For example, a command could reboot a gateway or take a picture using a remote camera.

你可以在接口中对这些元素进行分组,以在模型之间重复使用,从而使协作更加轻松并加快开发速度。You can group these elements in interfaces to reuse across models to make collaboration easier and to speed up development.

要使 IoT 即插即用与 Azure 数字孪生协同工作,你可以使用数字孪生定义语言 (DTDL) 定义模型和接口。To make IoT Plug and Play work with Azure Digital Twins, you define models and interfaces using the Digital Twins Definition Language (DTDL). IoT 即插即用和 DTDL 在社区中开放,Microsoft 欢迎与各客户、合作伙伴与行业合作。IoT Plug and Play and the DTDL are open to the community, and Microsoft welcomes collaboration with customers, partners, and the industry. 两者都基于 JSON-LD 和 RDF 等开放 W3C 标准,因此在不同的服务和工具中更易于采用。Both are based on open W3C standards such as JSON-LD and RDF, which enables easier adoption across services and tooling.

使用 IoT 即插即用和 DTDL 不会产生额外的费用。There's no extra cost for using IoT Plug and Play and DTDL. Azure IoT 中心和其他 Azure 服务的标准费率保持不变。Standard rates for Azure IoT Hub and other Azure services remain the same.

本文概述:This article outlines:

  • 与使用 IoT 即插即用的项目关联的典型角色。The typical roles associated with a project that uses IoT Plug and Play.
  • 如何在应用程序中使用 IoT 即插即用设备。How to use IoT Plug and Play devices in your application.
  • 如何开发支持 IoT 即插即用的 IoT 设备应用程序。How to develop an IoT device application that supports IoT Plug and Play.

用户角色User roles

IoT 即插即用适用于两种类型的开发人员:IoT Plug and Play is useful for two types of developers:

  • 解决方案构建者负责使用 Azure IoT 和其他 Azure 资源开发 IoT 解决方案,并识别要集成的 IoT 设备。A solution builder is responsible for developing an IoT solution using Azure IoT Hub and other Azure resources, and for identifying IoT devices to integrate.
  • 设备构建者创建在已连接到解决方案的设备上运行的代码。A device builder creates the code that runs on a device connected to your solution.

使用 IoT 即插即用设备Use IoT Plug and Play devices

解决方案构建者可以开发使用 IoT 即插即用设备的云托管式 IoT 解决方案。As a solution builder, you can develop a cloud-hosted IoT solution that uses IoT Plug and Play devices. IoT 中心 - 一项充当消息中心的托管式云服务,用于在 IoT 应用程序与设备之间进行双向通信。Use IoT Hub - a managed cloud service, that acts as a message hub for secure, bi-directional communication between your IoT application and your devices.

将 IoT 即插即用设备连接到 IoT 中心时,你可以使用 Azure IoT 资源管理器工具查看构成模型的接口中定义的遥测、属性和命令。When you connect an IoT Plug and Play device to an IoT hub, you can use the Azure IoT explorer tool to view the telemetry, properties, and commands defined in the interfaces that compose the model.

如果已将现有传感器附加到 Windows 或 Linux 网关,则可以使用 IoT 即插即用桥接连接这些传感器并创建 IoT 即插即用设备,而无需编写设备软件/固件(针对支持的协议)。If you have existing sensors attached to a Windows or Linux gateway, you can use IoT Plug and Play bridge, to connect these sensors and create IoT Plug and Play devices without the need to write device software/firmware (for supported protocols ).

开发 IoT 设备应用程序Develop an IoT device application

设备构建者可以开发支持 IoT 即插即用的 IoT 硬件产品。As a device builder, you can develop an IoT hardware product that supports IoT Plug and Play. 此过程包括三个关键步骤:The process includes three key steps:

  1. 定义设备模型。Define the device model. 使用 DTDL 创作一组定义设备功能的 JSON 文件。You author a set of JSON files that define your device's capabilities using the DTDL. 模型描述完整的实体(例如物理产品),并定义该实体实现的接口集。A model describes a complete entity such as a physical product, and defines the set of interfaces implemented by that entity. 接口是唯一标识设备所支持的遥测、属性和命令的共享协定。Interfaces are shared contracts that uniquely identify the telemetry, properties, and commands supported by a device. 可跨不同的模型重复使用接口。Interfaces can be reused across different models.

  2. 按照遥测、属性和命令遵循 IoT 即插即用约定的方式编写设备软件或固件。Author device software or firmware in a way that their telemetry, properties, and commands follow the IoT Plug and Play conventions. 如果要连接已附加到 Windows 或 Linux 网关的现有传感器,IoT 即插即用桥接可以简化此步骤。If you are connecting existing sensors attached to a Windows or Linux gateway, the IoT Plug and Play bridge can simplify this step.

  3. 设备将模型 ID 作为 MQTT 连接的一部分进行公告。The device announces the model ID as part of the MQTT connection. Azure IoT SDK 包括用于在连接时提供模型 ID 的新构造。The Azure IoT SDK includes new constructs to provide the model ID at connection time.

重要

IoT 即插即用设备必须通过 WebSocket 使用 MQTT 或 MQTT。IoT Plug and Play devices must use MQTT or MQTT over WebSockets. 其他协议(例如 AMQP 或 HTTP)对于实现 IoT 即插即用设备是无效的。Other protocols such as AMQP or HTTP are not valid to implement IoT Plug and Play devices.

设备认证Device certification

IoT 即插即用认证计划验证设备是否符合 IoT 即插即用认证要求。The IoT Plug and Play device certification program verifies that a device meets the IoT Plug and Play certification requirements. 可将已验证的设备添加到公共 Azure IoT 认证设备目录You can add a certified device to the public Certified for Azure IoT device catalog.

后续步骤Next steps

大致了解 IoT 即插即用后,我们建议接下来尝试学习以下快速入门之一:Now that you have an overview of IoT Plug and Play, the suggested next step is to try out one of the quickstarts: