快速入門:無線部署應用程式Quickstart: Deploy an application over the air

本快速入門說明如何建立第一個無線 (OTA) 應用程式部署。This quickstart shows how to create your first over-the-air (OTA) application deployment. OTA 部署會透過饋送將應用程式遞送至裝置群組中符合饋送目標庫存單位 (SKU) 的裝置。OTA deployment delivers an application through a feed to the devices in a device group that match the target stock-keeping unit (SKU) for the feed.

必要條件Prerequisites

本快速入門中的步驟假設:The steps in this quickstart assume that:

準備裝置以進行 OTA 部署Prepare your device for OTA deployment

在測試 OTA 部署程序之前,Azure Sphere 裝置必須已準備好而可接受 OTA 應用程式更新。Before you test the OTA deployment process, your Azure Sphere device must be ready to accept OTA application updates. 實際上,您要「鎖定」裝置並啟用 OTA 更新,這就是其在客戶網站的運作方式。In effect, you "lock" the device and enable OTA updates, which is how it will operate at a customer site. 若要這樣做,azsphere device prep-field 命令是最簡單的方式。The azsphere device prep-field command is the simplest way to do this. 此命令:This command:

  • 會讓 Visual Studio 停用將應用程式載入到裝置的功能,而讓您只能載入 OTA 應用程式Disables the ability for Visual Studio to load applications onto the device, so that only OTA applications can be loaded
  • 將新的產品 SKU 指派給裝置Assigns a new product SKU to the device
  • 將裝置指派給啟用 OTA 應用程式更新的新裝置群組Assigns the device to a new device group that enables OTA application updates

azsphere device prep-field 命令適用於已連線至 PC 的裝置。The azsphere device prep-field command works on the device that is connected to your PC. 其具備下列格式:It has the following form:

azsphere device prep-field --newdevicegroupname <unique-dg-name> --newskuname <unique-sku-name>

--newdevicegroupname 旗標會為此命令建立的新裝置群組指定名稱。The --newdevicegroupname flag specifies a name for the new device group that the command creates. 您可於此處了解裝置群組。Learn about device groups here. 此命令建立的所有裝置群組都支援自動 OTA 應用程式更新。All device groups created by this command support automatic OTA application updates. 請提供與 Azure Sphere 租用戶中的裝置群組名稱都不相同的描述性名稱。Supply a descriptive name that is unique among the device group names in your Azure Sphere tenant.

--newskuname 旗標會為此命令建立的產品 SKU 指定名稱。The --newskuname flag specifies a name for the new product SKU that the command creates. 產品 SKU 可識別內含 Azure Sphere 晶片的連線裝置型號。A product SKU identifies a model of the connected device that contains an Azure Sphere chip. Azure Sphere 租用戶中的每個 SKU 都必須有唯一的名稱。Each SKU in an Azure Sphere tenant must have a unique name.

Azure Sphere 安全性服務會使用裝置群組和 SKU 來判斷是否要在裝置上更新應用程式The Azure Sphere Security Service uses the device group and the SKU to determine whether to update the application on a device.

提示

對於包含空格的字串,請用雙引號括住,例如 "this string"。Enclose any strings that include spaces in double quotation marks, like "this string".

例如,下列命令會建立名為 FieldGroupOTA 的新裝置群組,以便讓 OTA 應用程式更新連結的裝置並指派給該群組。For example, the following command creates a new device group named FieldGroupOTA that enables OTA application updates and assigns the attached device to it. 它也會建立名為 FieldProductSKU 的新產品 SKU,並將該 SKU 指派給裝置。It also creates a new product SKU named FieldProductSKU and assigns that SKU to the device.

azsphere device prep-field --newdevicegroupname ota-test-3 --newskuname test-sku-3

Removing applications from device.
Component '68c95ce8-e06c-4713-95f2-00cc1861a996' deleted or was not present beforehand.
Removing debugging server from device.
Component '8548b129-b16f-4f84-8dbe-d2c847862e78' deleted or was not present beforehand.
Successfully removed applications from device.
Locking device.
Downloading device capability configuration for device ID <deviceID>.
Successfully downloaded device capability configuration.
Applying device capability configuration to device.
Successfully applied device capability configuration to device.
The device is rebooting.
Successfully locked device.
Creating a new device group with name 'ota-test-3'.
Setting device group ID 'fee1a5fe-59a3-44fc-8fc1-ab6848e09490' for device with ID <deviceID>.
Creating a new SKU with name 'test-sku-3'.
Setting product SKU to 'ae7927d0-1cbd-4e87-995a-495964e7facf' for device with ID <deviceID>.
Successfully set up device <deviceID> for OTA loading.
Command completed successfully in 00:00:15.5644027.

您不必在每次準備裝置以供現場使用時,都建立新的裝置群組和 SKU。You aren't required to create a new device group and SKU every time you prepare a device for field use. 一般而言,您會為每個產品型號建立一個 SKU,並為您想要一起更新的每個裝置集合建立一個裝置群組。Typically, you would create one SKU for each product model, and one device group for each collection of devices that you want to update together. 如需其他詳細資料,請參閱 prep-fieldFor additional details, see prep-field.

部署的下一個步驟是將裝置連結到摘要,以傳遞您從範本建置的高層級 Blink 範例。The next step in deployment is to link your device to a feed that delivers the high-level Blink sample that you build from the template. 您必須提供:You must supply:

  • 應用程式所仰賴 Azure Sphere OS 饋送的識別碼The ID of Azure Sphere OS feed on which the application depends
  • Visual Studio 為 HelloWorld 應用程式所建立的映像套件檔案路徑The path to the image package file that Visual Studio created for the HelloWorld application
  • 會遞送應用程式的饋送名稱A name for the feed that will deliver the application

連結至饋送To link to a feed

  1. 針對遞送 Azure Sphere OS 的「零售 Azure Sphere」摘要,取得其摘要識別碼。Get the feed ID for the Retail Azure Sphere feed, which delivers the Azure Sphere OS. 您所看到的饋送可能會與範例中的饋送不同。The feeds that you see might differ from those in the example.

    azsphere feed list
    
    Listing all feeds.
    Retrieved feeds:
    --> [3369f0e1-dedf-49ec-a602-2aa98669fd61] 'Retail Azure Sphere OS'
    --> [82bacf85-990d-4023-91c5-c6694a9fa5b4] 'Retail Evaluation Azure Sphere OS'
    Command completed successfully in 00:00:03.0017019.
    

    複製「零售 Azure Sphere OS」摘要的識別碼,以在下一個步驟中使用。Copy the ID for the Retail Azure Sphere OS feed to use in the next step.

  2. 發出 azsphere device link-feed 命令來建立饋送,並將饋送與您在快速入門:建置 Blink 應用程式Issue the azsphere device link-feed command to create a feed and associate it with the Blink image package that you created in Quickstart: Build the Blink application.

    azsphere device link-feed --dependentfeedid 3369f0e1-dedf-49ec-a602-2aa98669fd61 --imagepath <path-to-image> --newfeedname <unique-name>
    

    --dependentfeedid 旗標會提供「零售」摘要的識別碼。The --dependentfeedid flag supplies the ID of the Retail feed.

    --imagepath 旗標會提供 Blink 應用程式的映像套件檔案路徑。The --imagepath flag provides the path to the image package file for the Blink application. 快速入門:建置 Blink 應用程式中所述,映像檔案的完整路徑會顯示在 Visual Studio 的 [建置輸出] 視窗中。As noted in Quickstart: Build the Blink application, the full path to the image file is displayed in the Visual Studio Build Output window. azsphere device link-feed 命令會將映像套件檔案上傳至 Azure Sphere 安全性服務,並建立具有唯一名稱的映像集。The azsphere device link-feed command uploads the image package file to the Azure Sphere Security Service and creates an image set with a unique name.

    --newfeedname 旗標會為此命令所建立的饋送提供名稱。The --newfeedname flag provides a name for the feed that the command creates. 饋送名稱在 Azure Sphere 租用戶中必須是唯一的,因此請指定可用以區別此饋送的名稱。Feed names must be unique in an Azure Sphere tenant, so specify a name that distinguishes this feed from any others.

    例如︰For example:

    azsphere device link-feed --dependentfeedid 3369f0e1-dedf-49ec-a602-2aa98669fd61 --imagepath "C:\Users\user\Documents\Visual Studio 2017\Projects\AzureSphereBlink3\AzureSphereBlink3\bin\ARM\Debug\AzureSphereBlink3.imagepackage" --newfeedname blink-feed-test-3

    Getting the details for device with ID <deviceID>.
    Uploading image from file 'C:\Users\user\Documents\Visual Studio 2017\Projects\AzureSphereBlink3\AzureSphereBlink3\bin\ARM\Debug\AzureSphereBlink3.imagepackage':
     --> Image ID:       5fae38c5-48ee-4934-96b0-445b4f3e68fa
     --> Component ID:   68c95ce8-e06c-4713-95f2-00cc1861a996
     --> Component name: 'AzureSphereBlink3'
    Removing temporary state for uploaded image.
    Create a new feed with name 'blink-feed-test-3'.
    Adding feed with ID '21b69146-2d6d-4aec-b626-e70b6a19dc2c' to device group with ID 'fee1a5fe-59a3-44fc-8fc1-ab6848e09490'.
    Creating new image set with name 'ImageSet-AzureSphereBlink3-2019.05.07-18.30.00-07:00' for images with these IDs: 5fae38c5-48ee-4934-96b0-445b4f3e68fa.
    Adding image set with ID '607a5a24-c648-40c5-b496-6c5338a263fd' to feed with ID '21b69146-2d6d-4aec-b626-e70b6a19dc2c'.
    Successfully linked device <deviceID> to feed with ID '21b69146-2d6d-4aec-b626-e70b6a19dc2c'.
    Command completed successfully in 00:00:33.3283634.   
    

    此命令會建立摘要,並將其連結至已連結裝置所屬的裝置群組,也就是稍早在本快速入門中建立的 ota-test-2 群組。This command creates a feed that is linked to the device group to which the attached device belongs—that is, the ota-test-2 group created earlier in this quickstart. 它會將 AzureSphereBlink3 應用程式遞送至群組中產品 SKU 是 test-sku-3的所有 Azure Sphere 裝置。It will deliver the AzureSphereBlink3 application to all Azure Sphere devices in the group whose product SKU is test-sku-3.

觸發部署Trigger the deployment

前面的步驟會設定所有必要的部署元素。The previous steps set up all the required deployment elements. 若要立即觸發下載,請按 Azure Sphere 裝置上的 [重設] 按鈕。To trigger the download immediately, press the Reset button on the Azure Sphere device. 應用程式應該會在數分鐘內下載並啟動,然後您應該會看到 LED 開始閃爍。The application should download and start within several minutes, and you should see the LED start to blink.

若要確認應用程式已安裝到裝置上:To verify that the application was installed on your device:

azsphere device image list-installed

啟用偵錯Enable debugging

當您繼續開發和測試應用程式時,請使用 Visual Studio 來載入應用程式,直到您準備好要進行更廣泛地部署為止。As you continue to develop and test applications, you will probably want to use Visual Studio to load them until you're ready to deploy them more broadly. 若要反轉 device prep-field 命令,並讓裝置能夠進行開發和偵錯,請使用 device prep-debug,方法和您建置應用程式時相同:To reverse the device prep-field command and enable the device for development and debugging, use device prep-debug, as you did when you built the application:

azsphere device prep-debug

此命令:This command:

  • 會將裝置移動至停用 OTA 應用程式更新的裝置群組Moves the device to a device group that disables OTA application updates
  • 讓裝置能夠接受 Visual Studio 中的應用程式以便進行偵錯Enables the device capability to accept applications from Visual Studio for debugging

後續步驟Next steps