天天看點

一起學Azure Sphere(4)- 将Azure Sphere 通過DPS注冊到Azure IoT Hub并發送遙測消息

本文包含如下内容:

一.  使用Azure Sphere SDK 擷取CA憑證并配置到Azure IoT Hub DPS服務;

      建立IoT Hub;

      建立DPS;

      通過Azure Sphere SDK獲驗證書并上傳到DPS進行驗證。

二. 使用示例進階應用程式部署到Azure Sphere開發闆并上報資料到IoT Hub;

     Visual studio 進行環境準備:(需解除安裝上節内容中的Azure Sphere SDK,然後重新安裝Azure Sphere SDK For Visual studio)

     在Visual studio 中編譯項目并進行調試;

     在DPS注冊組和IoT Hub中進行檢查;

     在Azure IoT Hub explorer中觀察裝置到雲的資料。

視訊講解:

您可以在B站觀看本節視訊講解:https://www.bilibili.com/video/av98475432/

或在本站觀看:https://www.51azure.cloud/search/azure%20sphere

圖文講解:

一.  使用Azure Sphere SDK 擷取CA憑證并配置到Azure IoT Hub DPS服務;

      建立IoT Hub;

      建立DPS;

      通過Azure Sphere SDK獲驗證書并上傳到DPS進行驗證。

關鍵步驟:

下載下傳Azure Sphere 租戶證書:

azsphere tenant download-CA-certificate --output C:\CAcertificate.cer
           
一起學Azure Sphere(4)- 将Azure Sphere 通過DPS注冊到Azure IoT Hub并發送遙測消息

擷取驗證證書:

azsphere tenant download-validation-certificate --output C:\ValidationCertification.cer --verificationcode codeXXXXX
           
一起學Azure Sphere(4)- 将Azure Sphere 通過DPS注冊到Azure IoT Hub并發送遙測消息
一起學Azure Sphere(4)- 将Azure Sphere 通過DPS注冊到Azure IoT Hub并發送遙測消息
一起學Azure Sphere(4)- 将Azure Sphere 通過DPS注冊到Azure IoT Hub并發送遙測消息
一起學Azure Sphere(4)- 将Azure Sphere 通過DPS注冊到Azure IoT Hub并發送遙測消息
一起學Azure Sphere(4)- 将Azure Sphere 通過DPS注冊到Azure IoT Hub并發送遙測消息
一起學Azure Sphere(4)- 将Azure Sphere 通過DPS注冊到Azure IoT Hub并發送遙測消息

如下圖驗證通過。

一起學Azure Sphere(4)- 将Azure Sphere 通過DPS注冊到Azure IoT Hub并發送遙測消息

建立組注冊:

一起學Azure Sphere(4)- 将Azure Sphere 通過DPS注冊到Azure IoT Hub并發送遙測消息

建立組注冊:

一起學Azure Sphere(4)- 将Azure Sphere 通過DPS注冊到Azure IoT Hub并發送遙測消息

二. 使用示例進階應用程式部署到Azure Sphere開發闆并上報資料到IoT Hub;

     Visual studio 進行環境準備:(需解除安裝上節内容中的Azure Sphere SDK,然後重新安裝Azure Sphere SDK For Visual studio)

     在Visual studio 中編譯項目并進行調試;

     在DPS注冊組和IoT Hub中進行檢查;

     在Azure IoT Hub explorer中觀察裝置到雲的資料。

注意,本步驟需要解除安裝上一講當中的Azure Sphere SDK for windows, 然後安裝Azure Sphere SDK for Visual studio 

示例代碼中如下位置需要修改:

一起學Azure Sphere(4)- 将Azure Sphere 通過DPS注冊到Azure IoT Hub并發送遙測消息

編譯項目:

一起學Azure Sphere(4)- 将Azure Sphere 通過DPS注冊到Azure IoT Hub并發送遙測消息

編譯CMakelist.txt(滑鼠右鍵)

一起學Azure Sphere(4)- 将Azure Sphere 通過DPS注冊到Azure IoT Hub并發送遙測消息

選擇GDB Debugeger(HL Core) 并開始調試

一起學Azure Sphere(4)- 将Azure Sphere 通過DPS注冊到Azure IoT Hub并發送遙測消息

編譯之後,可以看到已經開始向IoT Hub 發送遙測消息了:

一起學Azure Sphere(4)- 将Azure Sphere 通過DPS注冊到Azure IoT Hub并發送遙測消息

在Iot Hub DPS 檢查組注冊記錄:

一起學Azure Sphere(4)- 将Azure Sphere 通過DPS注冊到Azure IoT Hub并發送遙測消息

在IoT Hub Device中檢查Device記錄:

一起學Azure Sphere(4)- 将Azure Sphere 通過DPS注冊到Azure IoT Hub并發送遙測消息

使用Azure IoT Hub Explorer 中查閱D2C 消息

一起學Azure Sphere(4)- 将Azure Sphere 通過DPS注冊到Azure IoT Hub并發送遙測消息

本節中,關于Azure IoT Hub DPS的内容,請參見:

《Azure 智能雲 之 Azure IoT DPS 十分鐘中級系列文章目錄》

聲明:

本站所有内容僅代表個人觀點,如與官文檔沖突,請以官方文檔為準,如有指正/咨詢/意見/建議,請直接在51azure.cloud留言。

點選可查閱本站最新 《文章分類目錄》

歡迎關注公衆号“雲計算實戰”,接收最新文章推送。

繼續閱讀