Learn together Azure Sphere (3) - Local development and debugging advanced program, after uploading the image to deploy cloud to device

In this article you will learn:

Case: Call GPIO control LED Strobe

Local development and debugging -> Publish to the cloud -> deployed from the cloud to device

First, by VS Code development and debugging advanced application examples Azure Sphere

       This procedure calls the LED strobe control GPIO

Second, deployed from the cloud

       Create a product;

       Configure the device as a "cloud-based applications to accept updates";

       Create a deployment;

       Trigger deployment;

       Re-configure the device to "Enable debugging";

 

Video Tutorial:

You can watch a video explaining the B station: https://www.bilibili.com/video/av98276348/

Or at the site to watch:

 

Photo explanation:

 

 

First, by VS Code development and debugging advanced application examples Azure Sphere

Referring to Microsoft's official documentation:

https://docs.microsoft.com/zh-cn/azure-sphere/install/qs-blink-vscode

Sample code used:

https://github.com/Azure/azure-sphere-samples

 

1. Start Visual Studio Code and open the folder from Azure Sphere HelloWorld_HighLevelApp example repository.  Do not open the higher-level folder.  VS Code only once to generate a solution.  If the VS Code display a dialog indicating CMake not available kits, select  Do not use a kit. 

img-f313f8e3-ddf8-464c-8139-b4954074b9d8.png

2. modify the configuration file sample code:

  • Open .vscode / settings.json.

  • Update AZURE_SPHERE_TARGET_HARDWARE_DEFINITION_DIRECTORY CMake variable to point to the definition of the target hardware device that contains a directory.  Microsoft provides a definition of the target hardware in the hardware catalog Azure Sphere examples of the vaults.  E.g: <path-to-cloned-samples>/Hardware/mt3620_rdb

  • Ensure AZURE_SPHERE_TARGET_HARDWARE_DEFINITION CMake variable points to the definition of the target hardware JSON file directory.  For the sample application, please use  sample_hardware.json.

img-c285c8b7-779e-4d70-890a-b0106b70ef7a.png

 

3. Press F5 to debug the project.  If you do not build the project before, or if the file has changed and needs to be regenerated, the VS Code will build the project before you begin debugging.

4. Wait a few minutes for Visual Studio Code compile an application, create an image package, deploy it to the plate and start it in debug mode.

5. After a short delay, should see the LED flashes.

img-c63904c1-6032-4345-81fc-c0966850bdf4.png

6. Set in main.c a location in breakpoints and step through the application so you can browse VSCode debugging features of Azure Sphere.

 

Second, deployed from the cloud

 1. Create Products

Incorporated into the product identification device connected to Azure Sphere perform specific functions MCU.  As a manufacturer, you can create a product for each type of connected device (such as a dishwasher or coffee machine).  Each product has a unique GUID in tenants and can not be changed.

Each connection device has a single product, but a single product may be associated with multiple devices.  Each product must have a unique name, and a description of the tenants.  Product name and described in order to distinguish a user-readable manner with other products.  You can modify the name and description of the product.

azsphere product create --name MyProduct --description "My First Product"

 

This command will automatically create a default device group for this new product:

  • Development (Development) : Development Group aims for developers during development next to load the application to use.  By default, this group receiving apparatus retail OS source; application update is disabled.  To test for different OS versions, you can change the default OS group.

  • Field testing (Field, the Test) : field test set is intended for use in laboratory or field test developers in test equipment.  By default, this group receiving apparatus retail source OS and all application updates.

  • Production (Production's) : Production Group for the production equipment.  By default, this group receiving apparatus retail source OS and all application updates.  This applies to a particular set of production equipment.

  • Field test evaluation of OS (OS Field, the Test Evaluation) : field test evaluation team OS is intended for laboratory or field tests to verify the new Azure Sphere OS and applications on the device is compatible with the developers.  By default, the source device receives retail OS evaluation of this group and all application updates.

  • Production assess OS (OS Production's Evaluation) : The evaluation is intended for the production of OS verify the new Azure Sphere OS and productivity applications are compatible.  By default, the source device receives retail OS evaluation of this group and all application updates.

其中,开发设备组会禁用基于云的更新。 其他组支持基于云的更新。

产品名称在租户中必须唯一,并且不区分大小写。 如果名称包含空格,则在命令中将其用双引号括起来。

如下图,生成了5个设备组:

img-fbc4385b-a066-4644-b492-bdfb1a1320dd.png

 

2.配置设备为“接受基于云的应用程序更新”

之前的步骤中,设备处于“开发状态”,开发状态的设备无法从云端接收更新,所以,此时需要先将设备配置为“接受基于云的应用程序更新”。

使用 azsphere device enable-cloud-test 准备设备 :

azsphere device enable-cloud-test --productname "MyProduct"

 

此命令:

  • 禁用 SDK 将应用程序加载到设备上的功能,以便只能加载基于云的应用程序

  • 根据需要将设备分配给产品

  • 将设备分配到启用基于云的应用程序更新的设备组 如果未指定设备组,则会将设备分配给其产品的默认“现场测试(Field Test)”设备组。

Azure Sphere 安全服务使用设备组和产品来确定是否在设备上更新应用程序

img-4ea65de4-2b14-4c5d-a1e3-6a5299c9cc89.png

 

此时可以通过如下命令查询Field Test group 的信息:

azsphere device-group show --devicegroupid “Field Group ID”
其中Field Group ID 在创建Product后显示过

img-7d657b78-9da3-414f-8a33-37e41fd02e8b.png

 

3.上传映像并创建部署

此步骤可以通过一个命令执行,也可以分部执行,

本文中,分布执行,1. 上传;2. 创建部署

1.上传:

azsphere image add --filepath Path\HelloWorld_HighLevelApp.imagepackage --temporary

本例中Path见下图所示:

参数 说明
-t, --temporary 将映像包标记为临时。 此参数适合在生产过程中使用。

 

img-f6158c94-d785-4e2e-aef2-117db28c77c3.png

2.部署规定了某个产品的某个产品组部署某个映像。

 azsphere device-group deployment create 命令将创建部署 。

有如下两种方案:本例中选择第二种方案,其中 imageid为 上一步 上传映像后返回值中的Image ID:

azsphere device-group deployment create --devicegroupname "Field Test" --productname MyProduct --filepath c:\temp\blink.imagepackage

 

azsphere device-group deployment create --devicegroupname "Field Test" --productname MyProduct --imageid  "例1bd8f03f-297e-43ab-819b-d2b0d05d0230"注意,映像ID 不带引号

img-293b6f4a-5d85-4f59-a0ed-363fa59f10db.png

 

  4. 触发部署

若要立即触发下载,请在 Azure Sphere 设备上按“重置”按钮 。 应用程序应在几分钟内下载并启动,然后应看到 LED 开始闪烁。

可通过如下命令查看部署结果:

azsphere device show-deployment-status

img-42579116-0c20-46ea-9954-a18f4b579729.png

 

 

5. 重新配置设备为“启用调试”;

 

At this point, if you use F5 to debug in VS Code in the open, the following error will be reported, because the "Filed Test" group is not on debugging that the debugger can not be started from the local Windows computer, by default, the device receives this group retail source OS and all application updates.

img-4eaa8d1f-2497-4d22-855b-01c8c1d76d89.png

If you want to start debugging, you need to switch back to "developing device group", execute the following command:

azsphere device enable-development

img-d69c6eab-df6b-4be0-8ab5-0e6f8f67dde7.png

 


Guess you like

Origin blog.51cto.com/10117438/2480976