你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn。
准备要导入到 Device Update for IoT Hub 更新
了解如何获取新的更新,并准备要导入到 Device Update for IoT Hub 的更新。
先决条件
Azure CLI 环境:
在 Azure Cloud Shell 中使用 Bash 环境。
或者,如需在本地运行 CLI 参考命令,请安装 Azure CLI
- 通过使用 az login 命令登录到 Azure CLI。
- 运行 az version 以查找安装的版本和依赖库。 若要升级到最新版本,请运行 az upgrade。
- 出现提示时,请在首次使用时安装 Azure CLI 扩展。 本文中的命令使用 azure-iot 扩展。 运行
az extension update --name azure-iot
以确保使用最新版本的扩展。
提示
本文中的 Azure CLI 命令使用反斜杠 \
字符进行续行,以便更轻松地读取命令参数。 此语法适用于 Bash 环境。 如果在 PowerShell 中运行这些命令,请将每个反斜杠替换为反引号 ```,或将其完全删除。
获取设备的更新
现在,你已设置了设备更新并预配了设备,接下来需要的是打算部署到这些设备的更新文件。
如果已从原装设备制造商 (OEM) 或解决方案集成器购买设备,则该组织很可能会为你提供更新文件,你无需创建更新。 请联系 OEM 或解决方案集成商,了解他们如何提供更新。
如果你的组织已为你使用的设备创建了软件,则同一组将为该软件创建更新。
创建要使用 Device Update for IoT Hub 部署的更新时,请从基于映像或基于包的方法开始,具体取决于你的方案。
创建基本设备更新导入清单
获得更新文件后,请创建一个导入清单来说明更新。 如果尚未这样做,请熟悉基本的导入概念。 虽然可以使用文本编辑器手动创作导入清单 JSON,但最好是使用 Azure 命令行界面 (CLI),因为该界面会大大简化此过程,并在以下示例中使用。
az Iot du init V5 命令采用以下参数:
--update-provider
、--update-name
和--update-version
:这三个参数定义 updateId 对象,该对象是每个更新的唯一标识符。--compat
:compatibility 对象是一组名称-值对,用于描述此更新兼容的设备的属性。- 同一完整的兼容性属性集不能与多个提供程序和名称组合一起使用。
--step
:设备上的更新处理程序(例如,microsoft/script:1
、microsoft/swupdate:1
或microsoft/apt:1
)及其与此更新关联的属性。--file
:更新文件(一个或多个)的路径。
有关这些参数的详细信息,请参阅导入模式和 API 信息。
az iot du update init v5 \
--update-provider <replace with your Provider> \
--update-name <replace with your update Name> \
--update-version <replace with your update Version> \
--compat <replace with the property name>=<replace with the value your device will report> <replace with the property name>=<replace with the value your device will report> \
--step handler=<replace with your chosen handler> properties=<replace with any handler properties (JSON-formatted)> \
--file path=<replace with path(s) to your update file(s), including the full file name>
例如:
az iot du update init v5 \
--update-provider Microsoft \
--update-name AptUpdate \
--update-version 1.0.0 \
--compat manufacturer=Contoso model=Vacuum \
--step handler=microsoft/script:1 properties='{"installedCriteria": "1.0"}' \
--file path=/my/apt/manifest/file
对于处理程序属性,可能需要转义 JSON 中的某些字符。 例如,如果要在 PowerShell 中运行 Azure CLI,请使用 '\'
来转义双引号。
init
命令支持高级方案,包括相关文件功能,可用于定义不同更新文件之间的关系。 有关更多示例和可选参数的完整列表,请参阅 az iot du init v5。
创建导入清单并将其保存为 JSON 文件后,便已准备好导入更新。 如果计划使用 Azure 门户 UI 进行导入,请确保使用以下格式来命名导入清单:“<manifestname>.importmanifest.json”。
为代理更新创建高级设备更新导入清单
如果更新更为复杂,如代理更新,则可能需要创建多个导入清单。 可以使用上一部分中的相同 Azure CLI 方法为复杂更新创建父导入清单和一些子导入清单。 在将示例参数值替换为自己的值后,运行以下 Azure CLI 命令。 要详细了解可以使用的值,请参阅导入架构和 API 信息。 在下面的示例中,有三个要部署到设备的更新:一个父更新和两个子更新:
az iot du update init v5 \
--update-provider <replace with child_1 update Provider> \
--update-name <replace with child_1 update Name> \
--update-version <replace with child_1 update Version> \
--compat manufacturer=<replace with the value your device will report> model=<replace with the value your device will report> \
--step handler=<replace with your chosen handler> \
--file path=<replace with path(s) to your update file(s), including the full file name> \
az iot du update init v5 \
--update-provider <replace with child_2 update Provider> \
--update-name <replace with child_2 update Name> \
--update-version <replace with child_2 update Version> \
--compat manufacturer=<replace with the value your device will report> model=<replace with the value your device will report> \
--step handler=<replace with your chosen handler> \
--file path=<replace with path(s) to your update file(s), including the full file name> \
az iot du update init v5 \
--update-provider <replace with the parent update Provider> \
--update-name <replace with the parent update Name> \
--update-version <replace with the parent update Version> \
--compat manufacturer=<replace with the value your device will report> model=<replace with the value your device will report> \
--step handler=<replace with your chosen handler> properties=<replace with any desired handler properties (JSON-formatted)> \
--file path=<replace with path(s) to your update file(s), including the full file name> \
--step updateId.provider=<replace with child_1 update provider> updateId.name=<replace with child_1 update name> updateId.version=<replace with child_1 update version> \
--step updateId.provider=<replace with child_2 update provider> updateId.name=<replace with child_2 update name> updateId.version=<replace with child_2 update version> \