瞭解如何取得新的更新,並準備將更新匯入至 IoT Hub 的裝置更新。
先決條件
- 啟用了裝置更新功能的 IoT 中樞存取權。
- 針對IoT中樞內的 裝置更新布建 的IoT裝置(或模擬器)。
- PowerShell 5 或更新版本 (包括 Linux、macOS 和 Windows 安裝)
- 支援的瀏覽器:
- Microsoft Edge
- Google Chrome
取得裝置的更新
既然您已設定更新裝置並布建了裝置,您將需要用於部署到這些裝置上的更新檔案。
如果您已從原始設備製造商 (OEM) 或解決方案整合者購買裝置,該組織很可能會為您提供更新檔案,而不需要建立更新。 請連絡 OEM 或解決方案整合者,以了解他們如何提供更新。
如果您的組織已經為您使用的裝置開發軟體,則相同的團隊將會負責更新該軟體。
在使用 IoT Hub 的裝置更新來建立要部署的更新時,請根據您的案例選擇 映像型或套件型方法 作為起點。
建立基本裝置更新匯入資訊清單
取得更新檔案之後,請建立匯入指令清單來描述更新。 如果您尚未這麼做,請務必熟悉基本的 匯入概念。 雖然您可以使用文本編輯器手動撰寫匯入指令清單 JSON,但本指南會使用PowerShell作為範例。
從 PowerShell 導航到本地副本中的
Tools/AduCmdlets。使用您自己的 提供者、名稱、版本、屬性、處理程式、已安裝準則、檔案取代下列範例參數值之後,執行下列命令。 如需您可以使用哪些值的詳細資訊,請參閱 匯入架構和 API 資訊 。 特別是請注意,相同的相容性屬性集不能與多個提供者和名稱組合搭配使用。
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope Process Import-Module ./AduUpdate.psm1 $updateId = New-AduUpdateId -Provider Contoso -Name Toaster -Version 1.0 $compat = New-AduUpdateCompatibility -Properties @{ deviceManufacturer = 'Contoso'; deviceModel = 'Toaster' } $installStep = New-AduInstallationStep -Handler 'microsoft/swupdate:1'-HandlerProperties @{ installedCriteria = '1.0' } -Files 'path to your update file' $update = New-AduImportManifest -UpdateId $updateId -Compatibility $compat -InstallationSteps $installStep # Write the import manifest to a file, ideally next to the update file(s). $update | Out-File "./$($updateId.provider).$($updateId.name).$($updateId.version).importmanifest.json" -Encoding utf8
建立匯入指令清單之後,如果您準備好匯入更新,您可以捲動至此頁面底部的 [後續步驟] 連結。
建立 Proxy 更新的進階裝置更新匯入資訊清單
如果您的更新較為複雜,例如 Proxy 更新,您可能需要建立多個匯入指令清單。 您可以使用上一節中的相同 PowerShell 腳本來建立父匯入清單和子匯入清單,以進行複雜更新。 以您自己的參數值取代範例參數值之後,執行下列命令。 如需您可以使用哪些值的詳細資訊,請參閱 匯入架構和 API 資訊 。
Import-Module $PSScriptRoot/AduUpdate.psm1 -ErrorAction Stop
# We will use arbitrary files as update payload files.
$childFile = "$env:TEMP/childFile.bin.txt"
$parentFile = "$env:TEMP/parentFile.bin.txt"
"This is a child update payload file." | Out-File $childFile -Force -Encoding utf8
"This is a parent update payload file." | Out-File $parentFile -Force -Encoding utf8
# ------------------------------
# Create a child update
# ------------------------------
Write-Host 'Preparing child update ...'
$microphoneUpdateId = New-AduUpdateId -Provider Contoso -Name Microphone -Version $UpdateVersion
$microphoneCompat = New-AduUpdateCompatibility -DeviceManufacturer Contoso -DeviceModel Microphone
$microphoneInstallStep = New-AduInstallationStep -Handler 'microsoft/swupdate:1' -Files $childFile
$microphoneUpdate = New-AduImportManifest -UpdateId $microphoneUpdateId `
-IsDeployable $false `
-Compatibility $microphoneCompat `
-InstallationSteps $microphoneInstallStep `
-ErrorAction Stop -Verbose:$VerbosePreference
# ------------------------------
# Create another child update
# ------------------------------
Write-Host 'Preparing another child update ...'
$speakerUpdateId = New-AduUpdateId -Provider Contoso -Name Speaker -Version $UpdateVersion
$speakerCompat = New-AduUpdateCompatibility -DeviceManufacturer Contoso -DeviceModel Speaker
$speakerInstallStep = New-AduInstallationStep -Handler 'microsoft/swupdate:1' -Files $childFile
$speakerUpdate = New-AduImportManifest -UpdateId $speakerUpdateId `
-IsDeployable $false `
-Compatibility $speakerCompat `
-InstallationSteps $speakerInstallStep `
-ErrorAction Stop -Verbose:$VerbosePreference
# ------------------------------------------------------------
# Create the parent update which parents the child update above
# ------------------------------------------------------------
Write-Host 'Preparing parent update ...'
$parentUpdateId = New-AduUpdateId -Provider Contoso -Name Toaster -Version $UpdateVersion
$parentCompat = New-AduUpdateCompatibility -DeviceManufacturer Contoso -DeviceModel Toaster
$parentSteps = @()
$parentSteps += New-AduInstallationStep -Handler 'microsoft/script:1' -Files $parentFile -HandlerProperties @{ 'arguments'='--pre'} -Description 'Pre-install script'
$parentSteps += New-AduInstallationStep -UpdateId $microphoneUpdateId -Description 'Microphone Firmware'
$parentSteps += New-AduInstallationStep -UpdateId $speakerUpdateId -Description 'Speaker Firmware'
$parentSteps += New-AduInstallationStep -Handler 'microsoft/script:1' -Files $parentFile -HandlerProperties @{ 'arguments'='--post'} -Description 'Post-install script'
$parentUpdate = New-AduImportManifest -UpdateId $parentUpdateId `
-Compatibility $parentCompat `
-InstallationSteps $parentSteps `
-ErrorAction Stop -Verbose:$VerbosePreference
# ------------------------------------------------------------
# Write all to files
# ------------------------------------------------------------
Write-Host 'Saving manifest and update files ...'
New-Item $Path -ItemType Directory -Force | Out-Null
$microphoneUpdate | Out-File "$Path/$($microphoneUpdateId.Provider).$($microphoneUpdateId.Name).$($microphoneUpdateId.Version).importmanifest.json" -Encoding utf8
$speakerUpdate | Out-File "$Path/$($speakerUpdateId.Provider).$($speakerUpdateId.Name).$($speakerUpdateId.Version).importmanifest.json" -Encoding utf8
$parentUpdate | Out-File "$Path/$($parentUpdateId.Provider).$($parentUpdateId.Name).$($parentUpdateId.Version).importmanifest.json" -Encoding utf8
Copy-Item $parentFile -Destination $Path -Force
Copy-Item $childFile -Destination $Path -Force
Write-Host "Import manifest JSON files saved to $Path" -ForegroundColor Green
Remove-Item $childFile -Force -ErrorAction SilentlyContinue | Out-Null
Remove-Item $parentFile -Force -ErrorAction SilentlyContinue | Out-Null