Azure Sphere(6)- 30分钟内 连接到Azure IoT Central

本文中讲介绍:

30分钟内将Azure Sphere 连接到Azure IoT Central并展示基本图表

本节主要以实操为主,不对Azure IoT Central做过多讲解,后续章节中会单独介绍Azure IoT Central。

 

本文步骤:

1. 创建Azure IoT Central;

2.将Azure Sphere 租户证书配置到Azure IoT Central中;

3.在Azure IoT Central中创建设备模板;

4. 在Visual Studio 调试Azure Sphere 高级程序并配置DPS以连接到Azure IoT Central;

5.在IoT Central中创建报警规则;

 

视频讲解:

您可以在B站观看本文视频讲解:https://www.bilibili.com/video/BV1D54y1R7Z3/

 

图文讲解(视频讲解更详细):

注意:本文案例的配置步骤,尤其是设备模板部分,只适用于Azure Sphere 默认的Azure IoT central demo,如果您设计的是其他产品,例如温湿度计等等,需要按照你实际的产品进行设计!

本例的示例代码与上一节内容相同,请参见:https://github.com/Azure/azure-sphere-samples

1. 创建Azure IoT Central

img-f3b392d7-450f-4809-a11a-75f84cd7b09d.png

 

 

填写名称,选择定价层,选择位置,本例中选择离我们最近的亚太区域。

其中模板里针对特定的场景做了一些预置的模板,可供大家选择,本例中,我们选择自定义应用程序。

img-9e83d7c0-9e94-4615-8a4a-2e0d9ac3ab03.png

其中定价参考如下:

新客户有7天免费试用层,除此之外:

定价层 标准层 1 标准层 2
用例 适用于每小时发送少量消息的设备 适用于每隔几分钟发送一次消息的设备
每设备价格 每月 $0.4 每月 $0.7
每月设备消息分配* 5,000 条消息 30,000 条消息
每个 IoT Central 应用程序包含的免费数量 2 台免费设备(包含 10,000 条消息) 2 台免费设备(包含 60,000 条消息)
超出每月消息分配的超额使用价格1 每 1K 条消息 $0.015 每 1K 条消息 $0.015

* 跨 IoT Central 应用程序中的所有设备共享消息分配总数

1 标准消息大小为 4 KB。例如,如果设备发送 4.5 KB 消息,则按 2 条消息计费。

创建完成后,点击下图连接可进入主界面:

img-87183b56-a45a-4233-9103-91479f419641.png

 

2.将Azure Sphere 租户证书配置到Azure IoT Central中

 

img-8a9049f3-49c2-478a-be01-f089100ad79f.png

Azure Sphere 租户证书获取命令:

下载Azure Sphere 租户证书:

azsphere tenant download-CA-certificate --output C:\CAcertificate.cer

img-dfdaced8-0bea-4889-a734-a9e6fefa8e5e.png

 

img-f7689c56-061c-4bb9-bd99-7b1aaf181e6a.png

使用如下命令 通过验证码生成验证证书,然后点击上图的验证按钮,上传验证证书。

获取验证证书:

azsphere tenant download-validation-certificate --output C:\ValidationCertification.cer --verificationcode codeXXXXX

 

img-ed6dd5b5-63d2-4589-9867-70d3fdf09612.png

 

3.在Azure IoT Central中创建设备模板

选择IoT 设备,下一步

img-94138f8f-9029-45c7-8218-8b42a30ee753.png

如下图直接点击下一步:

img-766765cf-4f36-4432-8c4a-42bd4c3b25aa.png

 

如下图直接点击下一步:

img-a0d3d5ef-cf96-4d73-9b7b-b65078c119d3.png

 

 

 

 

输入名称后,点击 自定义

img-6b14d7ac-1672-4bd9-a0ca-9515d3973f48.png

 

点击添加接口:

img-b6ff6f6a-14c7-4683-8c26-575be52cd542.png

点击自定义接口:

img-8c2f40b3-f45d-469b-868e-2c7c1f0a4c20.png

点击添加功能:

img-2b010bb6-232c-4530-92d9-3acd255f33f1.png

 

输入“Temperature” 的相关信息,点击保存;

点击右上角发布:

img-3d764669-d01c-455d-89bf-e14aa19ceec8.png

添加完成后可以在设备中看到 Azure Sphere 分组:

img-adc19e3e-daa7-4998-8346-6dd1f437e0e0.png

4. 在Visual Studio 调试Azure Sphere 高级程序并配置DPS以连接到Azure IoT Central

划重点,在示例代码中的Tools 路径中,执行ShowIoTContralConfig命令,按照提示执行,即可获得json配置文件中需要的值。

其中API Token 新建一个即可!

img-03d9f7d1-2580-49fa-b4bd-f1b97a8b89a9.png

将提示的配置文件更新到代码中:

img-6b2b31f7-aac0-439a-b381-99b46a1c2c11.png

编译项目:

img-1a5786d2-c659-44e0-a5ab-0a1a92e94045.png

编译CMakelist.txt(鼠标右键)

img-43b47d82-d9b1-4e13-b3df-795a9830e76b.png

选择GDB Debugeger(HL Core) 并开始调试

img-aee14986-45ab-4795-94d4-f586bf206432.png

运行之后可以看到如下OK的结果,表示连接到IoT Central成功:

img-5ed21b2a-2ebf-4b7e-ac87-77ec578f6cc4.png

可以看到自动注册到IoT Central中的设备:

img-126e9e50-a399-432c-88e8-a3f6050a6c16.png

 

点击迁移,将其迁移到 Azure shpere模板即可,即将物理设备和设备模板绑定。

img-664faf65-dbb4-4292-94ff-dd1eee4c0744.png

 

编辑仪表板,设置如下:

img-5920dd7c-e6ad-4ab4-aada-77436c2bc98e.png

保存后在首页刷新即可看到效果:

img-31e652b9-2b32-474d-964d-826cd85b7189.png

5.在IoT Central中创建报警规则;

img-8698a7a7-e3ce-483f-8574-c0f548e116af.png

在符合条件时,即可收到报警邮件:

img-d3c485b0-7586-4a07-a51a-84ca8f53bee3.png

 

 

本系列其他内容:

  1. (视频)一起学Azure Sphere(1)- 什么是 Azure Sphere

  2. (视频)一起学Azure Sphere(2)- 准备 Azure Sphere开发环境并声明设备

  3. (视频)一起学Azure Sphere(3)- 本地开发调试高级程序,上传映像后云端部署到设备

  4. (视频)一起学Azure Sphere(4)- 将Azure Sphere 通过DPS注册到Azure IoT Hub并发送遥测消息

  5. (视频)一起学Azure Sphere(5)- 将Azure Sphere 预配到Azure China IoT Hub

  6. (视频)一起学Azure Sphere(6)- 30分钟内将Azure Sphere 连接到Azure IoT Central并展示基本图表

 


猜你喜欢

转载自blog.51cto.com/10117438/2486631