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

设备模拟解决方案加速器概述Device Simulation solution accelerator overview

在基于云的 IoT 解决方案中,设备在连接到云终结点后即可发送遥测数据,例如温度、位置和状态。In a cloud-based IoT solution, your devices connect to a cloud endpoint to send telemetry such as temperature, location, and status. 解决方案可以使用该遥测数据,方便你采取行动或汲取见解。Your solution consumes this telemetry, enabling you to take actions or derive insights from it.

开发 IoT 解决方案时,试验和测试是该过程的重要部分。When you develop an IoT Solution, experimentation and testing are essential parts of that process. 在此过程中,模拟始终是一项重要的工具。Simulation is an important tool throughout this process. 设备模拟的功能如下:With Device Simulation you can:

  • 通过即时调整模拟设备行为,可快速启动原型让其运行,然后进行迭代。Quickly get a prototype up and running and then iterate by adjusting simulated device behavior on the fly. 通过此过程证明想法令人满意之后,再购买昂贵的硬件。This process lets you prove out the idea before investing in costly hardware. 可以通过 Web UI 创建自定义设备,在数秒内生成原型设备。You can create custom devices through the web UI to generate a prototype device in seconds.
  • 通过模拟实际的设备行为,验证解决方案是否可以按照从设备到解决方案的预期方式正常工作。Validate the solution works as expected from device to solution by simulating real-world device behaviors. 可以采用 JavaScript 编写复杂的设备行为,以生成逼真的模拟遥测。You can script complex device behaviors using JavaScript to generate realistic simulated telemetry.
  • 通过模拟正常、峰值和超出峰值的负载条件,对解决方案进行缩放测试。Scale test your solution by simulating normal, peak, and beyond peak load conditions. 缩放测试还有助于调整运行解决方案所需的 Azure 资源的大小。Scale tests also help you to right size the Azure resources needed to run your solution.

无人机模拟示例

使用设备模拟时,可以定义模拟真实设备所需的设备模型。With Device Simulation, you can define device models to simulate your real devices. 该模型包括消息格式、孪生属性和方法。This model includes message formats, twin properties, and methods. 还可以使用 JavaScript 模拟复杂的设备行为。You can also simulate complex device behaviors with JavaScript.

可以为一到一千台连接到 IoT 中心的设备运行模拟。You can run simulations for one to thousands of devices connecting to any IoT hub. 为了方便测试,可以选择为单独的环境部署 IoT 中心和设备模拟。To help with testing, you can optionally deploy an IoT hub along with Device Simulation for a standalone environment.

设备模拟可以免费使用。Device Simulation is free. 但是,设备模拟需要部署到云中的 Azure 订阅并消耗 Azure 资源。However, Device Simulation deploys to your Azure subscription in the cloud and does consume Azure resources. 如果设备模拟不符合要求,你可以复制并修改 GitHub 上提供的源代码If Device Simulation doesn't meet your requirements, the source code is also available on GitHub for you to copy and modify.

示例模拟Sample simulations

部署设备模拟时,会得到一些示例模拟和示例设备。When you deploy Device Simulation, you get some sample simulations and sample devices. 可以通过这些示例来学习如何使用设备模拟。You can use these samples to learn how to use Device Simulation. 若要开始,请运行 示例模拟To get started, run a sample simulation. 也可使用已提供的多个示例设备中的一个来创建自己的模拟You can also create your own simulation using one of the many sample devices provided.

模拟配置

自定义模拟设备Custom simulated devices

可以使用设备模拟创建自定义设备模型,以便在模拟中使用。You can use the Device Simulation to create custom device models to use in your simulations. 例如,可以定义一个新的冰箱设备模型,以便发送温度和湿度遥测数据。For example, you could define a new refrigerator device model that sends temperature and humidity telemetry. 自定义模拟设备适用于简单的设备行为,可以使用随机的、递增的或递减的遥测值。Custom simulated devices are ideal for simple device behaviors with random, incrementing, or decrementing telemetry values.

创建设备模型

高级模拟设备Advanced simulated devices

需要对设备发送的遥测值进行更多控制时,可以使用高级设备模型。When you need more control over the telemetry values a device sends, you can use an advanced device model. 高级设备模型启用 JavaScript 支持,可以操作已发送的遥测值。Advanced device models enable JavaScript support to manipulate the sent telemetry values. 例如,可以模拟一辆在炎热的晴天停靠的车辆的内部温度 - 当外部温度上升时,内部温度会呈指数上升。For example, you could simulate the interior temperature of a parked car on a hot sunny day - as the exterior temperature rise, the interior temperature increases exponentially.

可以通过高级设备模型来创建并上传自己的设备模型,其中包含一个 JSON 设备定义文件和相应的 JavaScript 文件。Advanced device models let you create and upload your own device models that consist of a JSON device definition file and corresponding JavaScript files.

可以通过高级设备模型执行以下操作:Advanced device models let you:

  • 指定从设备发送的消息格式以及遥测类型。Specify the message format sent from the device along with the telemetry types.
  • 使用自定义脚本生成遥测值,这些遥测值保留设备在一段时间的状态。Use custom scripting to generate telemetry values that maintain state of the device over time.
  • 使用自定义脚本指定模拟设备对方法的响应方式。Use custom scripting to specify how the simulated device responds to methods.

后续步骤Next steps

本文介绍了设备模拟解决方案加速器及其功能。In this article, you learned about the Device Simulation solution accelerator and its capabilities. 若要部署解决方案加速器,请访问 GitHub 存储库:To deploy the solution accelerator, visit the GitHub repository: