Azure Digital Twins(2)- 在本地使用ADT Explorer 管理數字孿生

本文介紹:

在本地運行ADT Explorer 並連接Azure Digital Twins 實例;

使用 VS CODE DTDL插件開發第一個 模型文件;

ADT Explorer的幾個基本功能;

使用ADT Explorer 上傳模型文件並生成 twin 孿生;

 

視頻演示:

https://www.51azure.cloud/post/2021/4/12/azure-digital-twins-adt-explorer

 

重點圖文步驟:

 

下載並在本地運行ADT Explorer


在ADT首頁,點擊 探索數字孿生體,瞭解更多連接打開ADT Explorer 工具下載頁面

或者直接進入:下載 ADT Explorer:https://aka.ms/adt-explorer

 

在右側release中下載最新版本

 

 

 

點擊Azure_Digital_Twins_ADT_Explorer.zip 文件並下載

 

 

 

解壓後,可以看到如下圖內容,read me中包含安裝方式:

1.本地安裝

2.容器安裝

3.在Azure 雲中安裝

本文僅介紹在本地安裝運行。

按照如下步驟執行本地安裝:

1. Set up an Azure Digital Twins service instance and give yourself appropriate permissions (e.g. *Azure Digital Twins Owner*). For instructions, please see the following how-to article:
*[Set up an Azure Digital Twins instance and authentication](https://docs.microsoft.com/azure/digital-twins/how-to-set-up-instance-portal)
1. When running locally, adt-explorer will use Azure default credentials. In order to authenticate, you can run, for example, **az login** in any command prompt. When you later run adt-explorer, it will pick up the credentials. Alternatively, you can sign into Visual Studio Code.
1. Select the **Download ZIP** button to download a .zip file of this sample code to your machine. Unzip the **Azure_Digital_Twins__ADT__explorer.zip** folder, and extract the files.
1. From a command prompt in the `client/src` folder, run `npm install`. This will retrieve all dependencies
1. From the same command prompt, run `npm run start`.
> By default, the app runs on port 3000. To customize the port, change the run command. For example, to use port 8080:
>* Linux/Mac (Bash): `PORT=8080 npm run start`
>* Windows (cmd): `set PORT=8080 && npm run start`
> Note: Your ADT app registration must have a reply URL using the same port you are using - e.g. localhost:7000 if that is the port you are using.
1. Your browser should open and the app should appear.
 
進入client/src,運行 npm install,注意,如果不知道npm是什麼,可參照https://www.51azure.cloud/post/2020/4/15/azure-iot-hub-1-prepare 中安裝node js 部分。

 

根據不同的操作系統,執行不同的命令:

>* Linux/Mac (Bash): `PORT=8080 npm run start`
>* Windows (cmd): `set PORT=8080 && npm run start`
 

 

可以看到 ADT Explorer已經在指定的端口運行了起來。

 

注意,ADT Explorer 本地運營依賴Azure CLI中的用戶信息,需要在Azure CLI中執行 az login先登錄自己的賬戶:

 

 

連接到ADT實例


將ADT的主機名拷貝

 

在ADT Explorer的右上角連接按鈕中輸入剛纔複製的主機名,注意保留https

 

 

 

使用VS Code 開發第一個 模型文件


VS code中安裝 DTDL插件

 

ctrl+shift+p 在上方輸入 DTDL:Create interface

選擇一個文件夾後,輸入 模型文件名稱:本例子輸入的是 myfirstmodel

 

可以看到DTDL模型文件創建成功。本例子中不用修改該文件。

 

在ADT Explorer中上傳模型並從模型生成twin


在ADT Explorer中點擊上傳模型按鈕,選擇剛纔在vs code創建的 dtdl的json文件。

 

上傳完成後,可以在ADT Explorer左側看到 模型文件,點擊模型文件的+,輸入一個名稱,可以爲模型文件生成一個twin孿生

此過程類似於編程當中的,從 類 到 對象 的過程。

 

ADT Explorer 幾個常見的功能:

1. 通過查詢語句可以查詢數字孿生實例中的twin孿生

2. 可在2處顯示查詢語句的查詢結果

3.點擊2處,可在右側顯示該twin的當前的數據

4. 點擊4處可進行關係綁定,刪除等操作





聲明:

 

點擊可查閱本站文章目錄 《文章分類目錄》

本站所有內容僅代表個人觀點,如與官文檔衝突,請以官方文檔爲準。

可在本頁面下方留言或通過下方聯繫方式聯繫我:

微信:wxyusz;郵箱:[email protected]

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



知識共享許可協議

本作品由Sean Yu 採用知識共享署名-非商業性使用-相同方式共享 4.0 國際許可協議進行許可。
歡迎轉載、使用、重新發布,但務必保留文章鏈接:https://www.51azure.cloud,且不得用於商業目的。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章