Share via


準備更新以匯入裝置更新以進行 IoT 中樞

瞭解如何取得新的更新,並準備更新以匯入裝置更新以進行 IoT 中樞。

必要條件

  • 存取已啟用 IoT 中樞裝置更新的 IoT 中樞

  • Azure CLI 環境:

    1. 使用 az login 命令來登入 Azure CLI。
    2. 執行 az version 以尋找已安裝的版本和相依程式庫。 若要升級至最新版本,請執行 az upgrade
    3. 出現提示時,請在第一次使用時安裝 Azure CLI 擴充功能。 本文中的命令會使用 azure-iot 延伸模組。 執行 az extension update --name azure-iot 以確定您使用的是最新版本的延伸模組。

提示

本文中的 Azure CLI 命令會使用反斜杠 \ 字元進行行接續,讓命令自變數更容易閱讀。 此語法適用於Bash環境。 如果您在 PowerShell 中執行這些命令,請以反引號 ''' 取代每個反斜杠,或完全移除它們。

取得裝置的更新

既然您已設定裝置更新並布建裝置,您需要將部署至這些裝置的更新檔案。

  • 如果您已從原始設備製造商 (OEM) 或解決方案整合者購買裝置,該組織很可能會為您提供更新檔案,而不需要建立更新。 請連絡 OEM 或解決方案整合者,以了解它們如何提供更新。

  • 如果您的組織為您使用的裝置建立軟體,該群組會建立該軟體的更新。

使用適用於 IoT 中樞的裝置更新建立要部署的更新時,請根據您的案例,從映像式或套件型方法開始

建立基本裝置更新匯入指令清單

取得更新檔案之後,請建立匯入指令清單來描述更新。 如果您尚未這麼做,請熟悉基本 匯入概念。 雖然您可以使用文本編輯器手動撰寫匯入指令清單 JSON,但 Azure 命令行介面 (CLI) 可大幅簡化程式,並在下列範例中使用。

提示

如果您尚未這麼做,請嘗試映像型、套件型Proxy 更新教學課程。 您也可以直接從這些教學課程檢視範例匯入指令清單檔案以供參考。

az iot du init v5 命令會採用下列自變數:

  • --update-provider--update-name--update-version:這三個參數會 定義每個更新的唯一標識子 updateId 物件。
  • --compat:相容性對像是一組名稱/值組,描述此更新所相容裝置的屬性。
    • 相同的相容性屬性集不能與多個提供者和名稱組合搭配使用。
  • --step:裝置上的更新處理程式(例如、 microsoft/script:1microsoft/swupdate:1microsoft/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”。

建立 Proxy 更新的進階裝置更新匯入指令清單

如果您的更新較為複雜,例如 Proxy 更新,您可能需要建立多個匯入指令清單。 您可以使用上一 節中的相同 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> \

下一步