快速入門 - 開始使用 Azure Digital Twins Explorer 中的範例案例

本快速入門是 Azure Digital Twins 的簡介,示範 Azure Digital Twins 如何代表資料,並示範如何與實體建築物的數位對應項圖形互動。 您將使用 Azure 入口網站 網站 Azure Digital Twins Explorer ,這是在網頁瀏覽器中視覺化和與 Azure Digital Twins 資料互動的工具。

在本快速入門中,您將探討預先建置的範例 模型 ,以數位方式定義建築物、 樓層 會議室 的概念,並使用這些模型定義來建立 數位對應項,以代表實體建築物的特定 樓層和房間。 這些個別對應項會連接到虛擬 對應項圖形 ,以反映彼此的關係,形成範例建築的完整數位標記法。 您將使用的圖表代表包含兩層的建築物,而每個樓層都包含會議室。 圖表看起來會像下圖:

Screenshot of a graph made of four circular nodes connected by arrows in Azure Digital Twins Explorer.

以下是您將用來探索本文圖表的步驟:

  1. 建立 Azure Digital Twins 實例,並在 Azure Digital Twins Explorer 中開啟它。
  2. 上傳預先建置的模型和圖形資料,以建構範例案例。 手動新增一個對應項。
  3. 模擬變更 IoT 資料,並查詢圖表以查看結果。
  4. 從體驗中檢閱您的學習。

注意

為了簡單起見,本快速入門不會涵蓋從模型化環境內的 IoT 裝置或其他資料來源設定即時資料流。 若要設定驅動對應項圖形的模擬端對端資料流程,請繼續進行教學課程: 連線端對端解決方案 。 如需服務之間資料流程以及將 Azure Digital Twins 整合到更廣泛的 IoT 解決方案的詳細資訊,請參閱 資料輸入和輸出

必要條件

您需要 Azure 訂用帳戶才能完成本快速入門。 如果您還沒有帳戶, 請立即免費 建立一個。

您也需要下載快速入門中使用的範例圖表資料。 使用下列指示來下載必要的檔案。 稍後,您將遵循更多指示將其上傳至 Azure Digital Twins。

  • 模型檔案。 流覽至下方的每個連結,以滑鼠右鍵按一下畫面上的任何位置,然後在瀏覽器的右鍵功能表中選取 [另存新檔 ]。 使用 [另存新檔] 視窗,將檔案儲存在您的電腦上某處。

    • Building.json :這是以數位方式定義建築物的模型檔案。 它指定建築物可以包含樓層。
    • Floor.json :這是以數位方式定義樓層的模型檔案。 它指定樓層可以包含會議室。
    • Room.json :這是以數位方式定義會議室的模型檔案。 它有溫度屬性。
  • buildingScenario.xlsx :此試算表包含範例對應項圖形的資料,包括五個數字對應項,代表具有樓層和房間的特定建築物。 對應項是以泛型模型為基礎,並與關聯性連接,指出哪些元素彼此包含。 視您的瀏覽器設定而定,選取此連結可能會自動將 buildingScenario.xlsx 檔案下載 到您的預設下載位置,或者它可能會開啟瀏覽器中有選項可下載的檔案。 以下是 Microsoft Edge 中下載選項的外觀:

    Screenshot of the buildingScenario.xlsx file viewed in a Microsoft Edge browser. A button saying Download is highlighted.

提示

這些檔案來自 GitHub 中的 Azure Digital Twins Explorer 存放庫。 您可以流覽存放庫以取得其他範例檔案、總管程式碼等等。

設定 Azure Digital Twins

使用 Azure Digital Twins 的第一個步驟是建立 Azure Digital Twins 實例,以保存您的所有圖形資料。 在本節中,您將建立服務的實例,並在 Azure Digital Twins Explorer 中開啟它。

建立 Azure Digital Twins 實例

在本節中,您將使用 Azure 入口網站 建立 Azure Digital Twins 的新實例。 流覽至入口網站,並使用您的認證登入。

  1. 在入口網站中,從在 Azure 服務首頁功能表中選取 [建立資源 ] 開始。

    Screenshot of the Azure portal, highlighting the 'Create a resource' icon from the home page.

  2. 在搜尋方塊中搜尋 Azure 數位對應項 ,然後從結果中選擇 Azure Digital Twins 服務。

    將 [ 計畫] 欄位保留為 [Azure Digital Twins ],然後選取 [ 建立 ] 按鈕以開始建立服務的新實例。

    Screenshot of the Azure portal, highlighting the 'Create' button from the Azure Digital Twins service page.

  1. 填入安裝程式 [基本] 索引 標籤上的 欄位,包括您的訂用帳戶、資源群組、新實例的 [資源名稱] 和 [區域]。 核取 [ 指派 Azure Digital Twins 資料擁有者角色] 方塊,賦予自己管理實例中資料的許可權。

    Screenshot of the Create Resource process for Azure Digital Twins in the Azure portal. The described values are filled in.

    注意

    如果 [指派 Azure Digital Twins 資料擁有者角色] 方塊呈現灰色,表示您沒有 Azure 訂用帳戶中的許可權來管理使用者對資源的存取權。 您可以繼續在本節中建立實例,然後應該讓具有必要許可權 的人員在實例 上指派此角色,再完成本快速入門的其餘部分。

    符合此需求的常見角色包括 擁有者 帳戶管理員 或使用者存取管理員istrator 參與者 的組合

  2. 選取 [ 檢閱 + 建立] 以完成實例的建立。

  3. 您會看到摘要頁面,其中顯示您輸入的詳細資料。 選取 [建立 ],確認並建立實例。

這會帶您前往追蹤實例部署狀態的 [概觀] 頁面。

Screenshot of the deployment page for Azure Digital Twins in the Azure portal. The page indicates that deployment is in progress.

等候頁面指出您的部署已完成。

在 Azure Digital Twins Explorer 中開啟實例

部署完成之後,請使用 [ 移至資源 ] 按鈕,流覽至入口網站中的實例 [概觀] 頁面。

Screenshot of the deployment page for Azure Digital Twins in the Azure portal. The page indicates that deployment is complete.

接下來,選取 [ 開啟 Azure Digital Twins Explorer(預覽)] 按鈕。

Screenshot of the Azure portal showing the Overview page for an Azure Digital Twins instance. There's a highlight around the Open Azure Digital Twins Explorer (preview) button.

這會在新索引標籤中開啟 Azure Digital Twins Explorer。如果這是您第一次使用 Explorer,您會看到歡迎模式摘要其主要功能。

Azure Digital Twins Explorer 可能會自動連線到您的實例。 如果沒有,您會看到下列畫面,要求您指定 Azure Digital Twins URL。 (如果您在畫面上看不到此方塊,Azure Digital Twins Explorer 已經自動完成此步驟。

Screenshot of Azure Digital Twins Explorer. The Azure Digital Twins URL modal displays an empty editable box for the Azure Digital Twins URL.

如果您看到此方塊,請在欄位中輸入 HTTPs:// ,後面接著實例的主機名稱(這可以在入口網站的實例 [ 概觀] 頁面上找到)。 這些值一起組成實例 URL。 選取 [ 儲存] 以連線到您的實例。

注意

託管的 Azure Digital Twins Explorer 只能存取已啟用公用存取的 Azure Digital Twins 實例。 如果您使用 Private Link 來限制透過私人端點存取實例,您可以使用 Azure 函式在雲端私下部署 Azure Digital Twins Explorer 程式碼基底。 如需如何執行這項操作的指示,請參閱 Azure Digital Twins Explorer:在雲端 中執行。

建置範例案例

接下來,您將使用 Azure Digital Twins Explorer 來設定範例模型和對應項圖形。 首先,您會在必要條件一節中 匯入您下載至電腦的模型檔案和對應項圖形檔案。 然後,您將手動建立一個對應項來完成案例。

模型

建立 Azure Digital Twins 圖表的第一個步驟是定義您環境的詞彙。 模型 是存在於您環境中之每個實體類型的泛型定義。 此範例建築案例包含建築物、樓層和房間,因此您需要一個模型定義來描述什麼是建築物 、一個描述 Floor 是什麼的模型定義 ,以及一個描述會議室 是什麼 的模型定義。 稍後,您可以建立 這些模型實例的數位對應項 ,代表特定的建築物、樓層和會議室。

Azure Digital Twins 的模型是以數位對應項定義語言 (DTDL) 撰寫 ,其資料物件語言類似于 JSON-LD 。 每個模型都會在其屬性、關聯性和元件方面描述單一類型的實體。

在本快速入門中,模型檔案已經為您撰寫。 您已在 [必要條件 ] 區段中下載 Building.json Floor.json Room.json ,現在您將使用 Azure Digital Twins Explorer 將其上傳至您的 Azure Digital Twins 實例。

上傳模型 (.json 檔案)

在 Azure Digital Twins Explorer 中,遵循下列步驟來上傳建築物、樓層和會議室模型( 您稍早下載的 .json 檔案)。

  1. 在 [ 模型] 面板中,選取 [上傳模型 ] 圖示,以顯示向上箭號。

    Screenshot of the Azure Digital Twins Explorer, highlighting the Models panel and the 'Upload a Model' icon in it.

  2. 在出現的 [開啟] 視窗中,流覽至包含電腦上下載之 .json 檔案的資料夾。

  3. 選取 [Building.json ]、 [Floor.json] 和 [Room.json ],然後選取 [ 開啟 ] 以一次全部上傳。

Azure Digital Twins Explorer 會將這些模型檔案上傳至您的 Azure Digital Twins 實例。 它們應該會顯示在 [ 模型 ] 面板中,並顯示其易記名稱和完整模型識別碼。

您可以從任何模型的選項中選取 [檢視模型 ],以查看定義每個模型類型的 DTDL 程式碼。

Screenshot of the Azure Digital Twins Explorer showing the Models panel with three model definitions listed inside: Building, Floor, and Room.

對應項和對應項圖形

現在,某些模型定義已上傳至您的 Azure Digital Twins 實例,您可以使用這些定義來為環境中的元素建立 數位對應項

解決方案中的每個數位對應項都代表實體環境中的實體。 您可以根據相同的模型類型建立許多對應項,例如所有使用 Room 模型的多個會議室對應項。 在本快速入門中,您將需要建築物的數位對應項,以及建築物中每個樓層和房間的數位對應項。 對應項會與關聯性連線到 代表完整建置環境的對應項圖形

在本節中,您將上傳預先建立的圖形,其中包含建築物對應項、兩層對應項和兩個房間對應項。

匯入圖形 (.xlsx 檔案)

在 Azure Digital Twins Explorer 中,遵循下列步驟來匯入範例圖表( 您稍早下載的 .xlsx 檔案)。

  1. 在 [ 對應項圖形] 面板中,選取 [匯入圖形 ] 圖示,以顯示指向雲端的箭號。

    Screenshot of Azure Digital Twins Explorer Twin Graph panel. The Import Graph button is highlighted.

  2. 在 [開啟] 視窗中,流覽至您稍早下載的 buildingScenario.xlsx 檔案。 此檔案包含範例圖表的對應項和關聯性資料。 選取開啟

    幾秒鐘之後,Azure Digital Twins Explorer 會開啟 [ 入] 檢視,以顯示要載入的圖形預覽。

  3. 若要完成匯入圖形,請選取圖表預覽面板右上角的 [ 儲存 ] 圖示。

    Screenshot of the Azure Digital Twins Explorer highlighting the Save icon in the Graph Preview pane.

  4. Azure Digital Twins Explorer 會使用上傳的檔案來建立要求的對應項及其之間的關聯性。 請確定您看到下列對話方塊,指出在繼續之前,匯入成功。

    Screenshot of the Azure Digital Twins Explorer showing a dialog box indicating graph import success.

    選取關閉

    圖形現在已上傳至 Azure Digital Twins Explorer,且 對應項圖形 面板將會重載。 它會顯示為空白。

  5. 若要查看圖表,請選取 [查詢總管] 面板中的 [執行查詢 ] 按鈕 ,靠近 [Azure Digital Twins Explorer] 視窗頂端。

    Screenshot of the Azure Digital Twins Explorer highlighting the 'Run Query' button in the upper-right corner of the window.

此動作會執行預設查詢,以選取並顯示所有數位對應項。 Azure Digital Twins Explorer 會從服務擷取所有對應項和關聯性。 它會在 [對應項圖形] 面板中繪製它們所定義的圖形 。 現在您可以看到範例案例的上傳圖表。

Screenshot of Azure Digital Twins Explorer showing the uploaded graph.'

圓形 (圖形 「nodes」) 代表數位對應項。 這幾行代表關聯性。 BuildingA 對應項「包含」Floor0 和 Floor1 對應項、Floor0 對應項「包含」Room0,以及 Floor1 對應項「包含」Room1。 如果您使用滑鼠,可以在圖形中按一下並拖曳來移動元素。

新增另一個對應項

建立數位對應項圖形之後,您可以繼續編輯其結構。 想像一下,這個範例建築的 Floor1 最近又建造了另一個房間。 在本節中,您會將新的對應項新增至圖形,以代表新的空間。

首先,選取定義您要建立之對應項類型的模型。 在左側的 [ 模型] 面板中,開啟 [會議室 ] 模型的 [選項] 功能表 。 選取 [建立對應項 ] 以建立此模型類型的新實例。

Screenshot of the Azure Digital Twins Explorer showing the Models panel, and the option to Create a Twin from the Room model.

針對 [ 新增對應項名稱 ] 輸入 Room2 ,然後選取 [ 儲存 ]。 這會建立新的數位對應項,該對應項尚未透過關聯性連接到圖形的其餘部分。

接下來,您將新增關聯性以顯示 Floor1 包含 Room2。 使用 CTRL/CMD 或 SHIFT 鍵來同時選取圖形中的 Floor1 和 Room2。 選取這兩個對應項時,以滑鼠右鍵按一下 Room2,然後選擇 [ 新增關聯性 ]。

Screenshot of the Azure Digital Twins Explorer, adding a relationship between Floor1 and Room2.

這會開啟 [ 建立關聯性 ] 對話方塊,此對話方塊會預先填入從 Floor1 到 Room2 的「包含」關聯性詳細資料。 選取 [儲存]。

Screenshot of the Create Relationship options.

現在,Room2 會在圖形中連接。 如果您使用滑鼠,您可以在圖形中按一下並拖曳對應項,將它們排列成您想要的組態。

Screenshot of Azure Digital Twins Explorer showing the graph, which now includes Room2.'

檢視對應項屬性

您可以選取對應項,在 [ 對應項屬性 ] 面板中查看其屬性及其值的清單。

以下是 Room0 的屬性。 請注意,Room0 的溫度為 70。

Screenshot of the Azure Digital Twins Explorer highlighting the Twin Properties panel, which shows $dtId, Temperature, and Humidity properties for Room0.

以下是 Room1 的屬性。 請注意,Room1 的溫度為 80。

Screenshot of the Azure Digital Twins Explorer highlighting the Twin Properties panel, which shows $dtId, Temperature, and Humidity properties for Room1.

Room2 尚未為其屬性設定值,因為此對應項是手動建立的。 若要設定其屬性值,請編輯欄位,讓濕度為 50 且溫度為 72。 選取儲存圖示。

Screenshot of the Azure Digital Twins Explorer highlighting the Twin Properties panel, where Temperature and Humidity are being set for Room2.

查詢變更 IoT 資料

在 Azure Digital Twins 中,您可以使用 SQL 樣式 的 Azure Digital Twins 查詢語言 ,查詢對應項圖形以回答環境相關問題。 查詢圖形中對應項的其中一種方式是其屬性。 根據屬性進行查詢可協助您回答環境中關於極端值或識別極端值的問題。 在完全連線的資料驅動案例中,對應項的屬性會經常變更,以回應您環境中的感應器或其他連線資料來源的 IoT 資料。 在本快速入門中,您將手動變更值,以模擬變更的感應器讀數。

從執行查詢開始,查看您環境中的對應項溫度高於 75。 在 [ 查詢總管] 面板中執行下列查詢。

SELECT * FROM DIGITALTWINS T WHERE T.Temperature > 75

回想一下,在早些時候檢視雙胞胎屬性時,Room0 的溫度讀數為 70,Room1 的溫度讀數為 80,而 Room2 的溫度讀數為 72。 建築和地板雙胞胎根本沒有溫度屬性。 基於這些原因,這裡只會顯示 Room1 的結果。

Screenshot of the Azure Digital Twins Explorer showing the results of property query, which shows only Room1.

提示

查詢中也支援其他比較運算子 ( < 、、 > =或 !=) 。 您可以嘗試將這些運算子、不同的值或不同的對應項屬性插入查詢中,以嘗試回答您自己的問題。

編輯溫度資料

在完全連線的 Azure Digital Twins 解決方案中,圖形中的對應項會收到來自真實 IoT 裝置和其他資料來源的即時更新,並自動更新其屬性,以保持與您的真實世界環境同步。 為了簡單起見,在本快速入門中,您將在這裡使用 Azure Digital Twins Explorer,手動將 Room0 的溫度讀數設定為 76。

首先,重新執行下列查詢以選取所有數位對應項。 這會在 [ 對應項圖形] 面板中再次顯示完整的圖形

SELECT * FROM DIGITALTWINS

選取 Room0 以在 [ 對應項屬性 ] 面板中顯示其屬性清單。

將溫度值從 70 變更為 76 ,然後選取 [ 儲存 ] 圖示以更新溫度。

Screenshot of the Azure Digital Twins Explorer highlighting that the Twin Properties panel is showing properties that can be edited for Room0.

成功更新屬性之後,您會看到 [ 修補資訊 ] 方塊,其中顯示與 Azure Digital Twins API 搭配幕後使用的修補程式程式碼,以便進行更新。

Screenshot of the Azure Digital Twins Explorer showing Patch Information for the temperature update.

關閉 修補程式資訊。

查詢以查看新結果

若要查看 Graph 中反映 Room0 的新溫度,請從稍早重新執行查詢,以取得環境中溫度高於 75 的所有對應項。

SELECT * FROM DIGITALTWINS T WHERE T.Temperature > 75

現在,Room0 的溫度已從 70 變更為 76,因此,Room0 和 Room1 都應該顯示在結果中。

Screenshot of the Azure Digital Twins Explorer showing the results of property query, which shows both Room0 and Room1.

檢閱和內容化學習

在本快速入門中,您已建立 Azure Digital Twins 實例,並使用 Azure Digital Twins Explorer 填入範例案例。 您也手動新增數位對應項。

然後,您已探索圖形,包括...

  • 使用查詢來回答案例的相關問題。
  • 編輯數位對應項上的屬性。
  • 再次執行查詢,以查看回應因更新而變更的方式。

此練習的目的是要示範如何使用 Azure Digital Twins 圖表來回答有關您環境的問題,特別是隨著 IoT 環境持續變更。

在本快速入門中,您已手動進行溫度更新。 Azure Digital Twins 通常會將數位對應項連線到實際的 IoT 裝置,以便根據裝置遙測資料自動接收更新。 您也可以 連接其他資料來源 、整合來自不同系統的資料,以及定義自己的邏輯,以瞭解如何更新對應項。 如此一來,您可以建置即時圖表,以一律反映您環境的實際狀態。 您可以使用查詢來即時取得環境中發生狀況的相關資訊。

您也可以將 Azure Digital Twins 資料匯出至歷史追蹤、資料分析和 AI 服務,以啟用更深入的見解並執行環境模擬。 將 Azure Digital Twins 整合到 IoT 解決方案中,可協助您更有效地追蹤過去、控制目前,以及預測未來。

清除資源

若要在本快速入門之後清除,請根據您要下一步執行的動作,選擇您想要移除的 Azure Digital Twins 資源。

  • 如果您打算繼續進行 Azure Digital Twins 快速入門和教學課程,您可以針對這些文章重複使用本快速入門中的實例,而不需要將其移除。
  • 如果您不再需要 Azure Digital Twins 實例,您可以使用 Azure 入口網站 加以刪除

    流覽回入口網站中實例的 [概觀 ] 頁面。 (如果您已經關閉該索引標籤,您可以在Azure 入口網站搜尋列中搜尋實例的名稱,然後從搜尋結果中選取它,以再次找到實例。

    選取 [ 刪除 ] 以刪除實例,包括其所有模型和對應項。

    Screenshot of the Overview page for an Azure Digital Twins instance in the Azure portal. The Delete button is highlighted.

您也可以從本機電腦刪除範例專案檔。

下一步

請移至下一個快速入門,以在 3D 環境中將 Azure Digital Twins 案例視覺化。

或者,請跳到教學課程,深入瞭解 SDK、對應項圖形建立和事件流程設定。