Tutorial: Dynamic Templating
This step-by-step interactive tutorial provides an introduction to dynamic templating in Intelligence Hub.
What Does This Tutorial Cover?
This tutorial will walk you through the basics of working with dynamic templating. Templating is supported for Inputs, Instances, and Pipelines. Templating offers an efficient method for generating hundreds of configuration objects, with only minor variations between them. For example, if an OPC UA Server has 100 machines and the address of each machine only differs by a unique machineID, a single Input can represent all 100 machines.
When comparing dynamic templating with static templating, dynamic uses external values (example from a SQL table) to drive parameters into configuration components. In this tutorial, we'll start by staging OPC UA tags with a parameter that will then associate with a dynamically Templated Instance. Our dynamic source will be a SQL input.
- Tutorial Prerequisites
- Tutorial Preparation
- Tutorial Instructions
- Tutorial Summary
Tutorial Prerequisites
- You have completed the initial Installation of the Intelligence Hub.
- It is recommended to read the Getting Started Series before completing this tutorial exercise.
- It is recommended to complete "Tutorial: Connections", "Tutorial: Models and Instances", and "Tutorial: Static Templating".
Tutorial Preparation
-
Enable Intelligence Hub MQTT broker
- In the left-hand navigation panel, navigate to Manage, and click Settings
- Under the MQTT Broker section enable the broker, if ports 1885 and 1886 are being utilized on your Intelligence Hub server, update to ports of your choosing, otherwise accept the defaults and click save
-
Import the required Components
- In the left-hand navigation panel, navigate to Manage, and click Project.
- Within the Import screen, ensure Full Project is off (otherwise your existing project will be overwritten).
- Copy the JSON provided here. Project JSON.
- Change the Import Type to JSON and paste in the following with the Project box and click the Import button.
-
Update the imported Connections as required
-
Navigate to Configure and click Connections, click "HB_Tutorial_MQTT" and update the MQTT settings as required based on the prior preparation step #1.
-
Navigate to Configure and click Connections, Click "HB_Tutorial_SQL_Server" and type the following within the password field and click the Save button.
-
password
-
-
-
Setup UNS Client
- In the left-hand navigation panel, navigate to Tools and right click UNS Client and select Open Link in New Tab.
- Enter login information
- For Connection select "HB_Tutorial_MQTT".
- For Subscribed Topics enter [Tutorial/#]. Do not include the brackets.
-
- Click Add
-
Click the "x" to remove topic "#".
-
Click the Connect button.
-
Confirm the UNS Client says "Connected to HB_Tutorial_MQTT".
-
Return to the previous web browser tab.
Tutorial Instructions
-
Review the dynamic templating source. This will show you where we are sourcing our templating parameters from.
-
Navigate to Connections.
-
Select "HB_Tutorial_SQL_Server".
-
Navigate to the Inputs tab.
-
Select "HB_Tutorial_SQL_Server_Input_Get_All_CNC_Asset_IDs".
-
Review the query syntax and click the Test Input button.
- Note: we are obtaining an array of the asset_id values to use in the dynamic template, the asset_id value from the source is different from prior Tutorials (Fanuc_#### vs. #####).
-
-
Stage parameters in source OPC UA inputs.
-
Note in this step you will be updating OPC UA Inputs to have a parameter in the identifier setting. We will NOT be enabling templating from the Connection but will drive the InputAssetID parameter set externally later in this Tutorial.
-
Navigate to Connections.
-
Select "HB_Tutorial_OPC_UA".
-
Navigate to the Inputs tab.
-
Open "Tutorial_CNC_Fanuc_Machine_State_Dynamic". The Input might be on the second page of Inputs.
-
Within the Identifier, replace Fanuc_1001 with {{this.InputAssetID}}
Before: Tutorial.CNC_Fanuc_1001.MachineState After: Tutorial.CNC_{{this.InputAssetID}}.MachineState
-
Click the Save button.
-
Navigate back to the Inputs of "HB_Tutorial_OPC_UA" and repeat the last step with the following Inputs:
- Tutorial_CNC_Fanuc_Part_Program_ID_Dynamic
- Tutorial_CNC_Fanuc_Reject_Count_Dynamic
- Tutorial_CNC_Fanuc_Tool_ID_Dynamic
Before: Tutorial.CNC_Fanuc_1001.PartProgramID Tutorial.CNC_Fanuc_1001.RejectCount Tutorial.CNC_Fanuc_1001.ToolID After: Tutorial.CNC_{{this.InputAssetID}}.PartProgramID Tutorial.CNC_{{this.InputAssetID}}.RejectCount Tutorial.CNC_{{this.InputAssetID}}.ToolID
-
Note no data will be returned from the Test Input, this is expected.
-
-
Create a Dynamic Template within a new Instance
-
Navigate to Models
-
Select "HB_Tutorial_Program_Info".
-
Click the Create Instance button.
-
From the new Instance details view, enter "HB_Tutorial_Program_Info_Instance_Dynamic_Template" as the name and click the Next button.
- From the New Instance view, set the References panel to type Input and the Connection to "HB_Tutorial_OPC_UA"
-
Using the References panel, map the following
- ProgramID -
{{Connection.HB_Tutorial_OPC_UA.Tutorial_CNC_Fanuc_Part_Program_ID_Dynamic}}
- ToolID -
{{Connection.HB_Tutorial_OPC_UA.Tutorial_CNC_Fanuc_Tool_ID_Dynamic}}
- MachineState -
{{Connection.HB_Tutorial_OPC_UA.Tutorial_CNC_Fanuc_Machine_State_Dynamic}}
- RejectCount -
{{Connection.HB_Tutorial_OPC_UA.Tutorial_CNC_Fanuc_Reject_Count_Dynamic}}
- ProgramID -
-
-
-
Click the Create Button.
-
Select Dynamic from the Template Type drop down list.
- From the References panel, set the type to Input and Connection to "HB_Tutorial_SQL_Server".
-
From the References panel, map "HB_Tutorial_SQL_Server_Input_Get_All_CNC_Asset_IDs" to the Template Reference field.
-
Add {{this.asset_id}} as the Template Name.
-
Add "(InputAssetID={{this.asset_id}})" to our each attribute expressions.
-
Before: {{Connection.HB_Tutorial_OPC_UA.Tutorial_CNC_Fanuc_Part_Program_ID_Dynamic}}
-
After: return {{Connection.HB_Tutorial_OPC_UA.Tutorial_CNC_Fanuc_Part_Program_ID_Dynamic(InputAssetID={% raw %}{{this.asset_id}})}}
-
Click the Save button.
-
Click the Test Instance button and review the results.
-
To recap, what we just configured was a Dynamic Template configuration. We utilized the asset_id column from the HB_Tutorial_SQL_Server connection, and dynamically passed this into the instance and ultimately to the OPC UA Connection Input. This also is a lesson on dynamically passing parameters from object to object. This works because the source OPC UA tags have {{this.InputAssetID}} configured within the identifier.
-
Review the Output target
- Navigate to Connections
- Select "HB_Tutorial_MQTT"
- Navigate to the Outputs tab
- Select "HB_Tutorial_MQTT_Output_CNC_Templated_Pipeline" and review the configuration
- Take note we having a dynamic reference of {{this._name}} within the topic. This will utilize the internal attribute _name.
-
Create a new Pipeline. Note in order to build a practical example of a Templated Pipeline, we will use a Flow Trigger and Event mode and OnChange publish mode to monitor a templated event source.
- Navigate to Pipelines.
- Click New Pipeline.
- Enter “HB_Tutorial_Program_Dynamic_Templated_Instance_To_MQTT” for the Name.
- Select the Build Flow option to create a Pipeline with Sources, Targets, and a Trigger.
- Click the Next button.
- Within the Sources & Target view, use the References Panel and set Type to Instance.
- Drag “HB_Tutorial_Program_Info_Instance_Dynamic_Template” into the Sources box.
- Change Type to Output.
- Set Connections to "HB_Tutorial_MQTT".
- Drag "HB_Tutorial_MQTT_Output_CNC_Templated_Pipeline" to the Targets box.
- Click the Next button.
- Select Event in the Execution Type drop down list.
- Use the References Panel and set Type to Input.
- Select "HB_Tutotrial_OPC_UA" for the Connection.
- Drag "Tutorial_CNC_Fanuc_Machine_State_Dynamic" into the Event Sources box.
- Before:
{{Connection.HB_Tutorial_OPC_UA.Tutorial_CNC_Fanuc_Machine_State_Dynamic}}
- After:
{{Connection.HB_Tutorial_OPC_UA.Tutorial_CNC_Fanuc_Machine_State_Dynamic(InputAssetID={% raw %}{{this.asset_id}})}}
Add "(InputAssetID={{this.asset_id}})" to the end of the expression.
- Before:
- Click the Create button.
- Select the Flow stage.
- Select Dynamic from the Templating drop down list.
- Use the References Panel and set Type to Input.
- Select "HB_Tutotrial_SQL_Server" for the Connection.
- Drag "HB_Tutorial_SQL_Server_Input_Get_All_CNC_Asset_IDs" into the Reference box.
- Add {{this.asset_id}} as the Template Name.
-
Template the new Flow
-
Within the new Flow, Enable Use Template
-
Set type to Dynamic
-
From the References panel, set the type to Input and Connection to Tutorial_CMMS_servicelogs
-
From the References panel, map Tutorial_CNC_AssetIDs to the Template Reference field
-
Add {{this.asset_id}} as the Template name
-
In the References box add (asset_id={{this.asset_id}}) to the Instance Name.
-
Before: {{Instance.HB_Tutorial_Program_Info_Instance_Dynamic_Template}}
-
After: {{Instance.HB_Tutorial_Program_Info_Instance_Dynamic_Template(asset_id={% raw %}{{this.asset_id}})}}
-
- Enable the Pipeline.
-
Click the Save button and review the results in the UNS Client.
-
Take note we just configured a Pipeline that is dynamically passing static template parameters (asset_id) to two separate objects. The first object was to the source Instance to link the Pipeline parameters with the Instance dynamic parameters. The second object was to the event source OPC UA Connection Input to control the Pipeline execution. As you can see in the UNS client, we are only seeing Fanuc_1002 and Fanuc_1003 as the event values are changing. Fanuc_1001 has a simulated MachineState that is NOT changing.
Tutorial Summary
This tutorial covered how to utilize templating within Intelligence Hub components to assist in scaling successful use cases from one configuration object to many. Templating can happen within Inputs, Instances and Pipelines. We covered how to connect multiple templated objects together to ensure consistency with our use cases.
Next Tutorial