Advanced Configurations and Integrations > Displaying Azure IoT Hub Data as Property Values on an Asset
Displaying Azure IoT Hub Data as Property Values on an Asset
Azure IoT Hub data can be displayed as property values on an asset using ThingWorx Composer.
Prerequisites
A minimum Java Runtime Environment (JRE) of 1.8
ThingWorx Composer 8.3.0 or higher with ThingWorx Apps installed.
Azure IoT Connector Extension installed on ThingWorx. For more information, see the ThingWorx Azure IoT Hub Connector Help Center.
Azure IoT Hub installed.
A ThingWorx application key created for the ThingWorx Azure IoT Hub Connector, for example azure_appkey.
To display Azure IoT Hub data for asset properties:
* 
To display an Azure IoT Hub Thing as an asset in ThingWorx Apps, without making Azure IoT Hub data able to be browsed from the tag picker common component, you only need to edit the Thing to add the Implemented Shapes listed in step 3, and can skip the rest of the following procedure.
1. In ThingWorx Composer, create a new resource provider Thing Template, to add the Azure IoT Hub connection to the Equipment Type drop-down list in the tag picker common component:
Name—The name for the Thing Template, for example AzureIot_ResourceProvider_ThingTemplate.
Base Thing TemplatePTC.SCA.SCO.EquipmentResourceProviderTemplate
Implemented ShapesPTC.SCA.SCO.RemoteConnectionResourceProviderThingShape
Under Services, click Override service icon to override the GetConnectedServers service with the following code. (Line breaks and spaces have been added to the following code for presentation purposes. If you cut-and-paste the code, remove these characters before attempting to use the code in your application.)
var params = {
infoTableName : "InfoTable",
dataShapeName : "PTC.Factory.OPCDAServerNames"
};
var infoTableWithName = Resources["InfoTableFunctions"].CreateInfoTableFromDataShape(params);


var params = {
columnName: "ResourceProviderName",
value: me.name
};

// result: INFOTABLE dataShape: PTC.SCA.SCO.RemoteConnectionSettingsTableDataShape
var result = Things["PTC.Factory.LaunchPointConfigurationThing"].
GetRemoteConnectionTableRowByStringProperty(params);

var thingTemplateName;
if (result) {
thingTemplateName = result.getRow(0).RemoteConnectionThingTemplateName;
}

var paramsForThingTemplate = {
maxItems : 1000,
nameMask : undefined,
query : undefined,
thingTemplate : thingTemplateName,
tags : undefined
};
var thingsWithTemplate = Resources["SearchFunctions"].SearchThingsByTemplate(paramsForThingTemplate);
for (var i = 0; i < thingsWithTemplate.rows.length; i++) {
var row = thingsWithTemplate.rows[i];
// infotable datashape iteration
var name = row.name;
var isThingEnabled = Things[name].IsEnabled();

if (name !== "" && name !== null && isThingEnabled) {
var serverName = row.ServerName;
var rowObject = new Object();
rowObject.Name = name;
if (serverName === null || serverName === undefined || serverName === "") {
serverName = name;
}
rowObject.ServerName = serverName;
infoTableWithName.AddRow(rowObject);
}
}
result = infoTableWithName;
For information on the other services related to the PTC.SCA.SCO.RemoteConnectionResourceProviderThingShape Thing Shape, see step 1 under Browse Data from Custom Connectors.
2. Create a resource provider Thing implementing the Thing Template created in step 1:
Name—For example, AzureIot_ResourceProviderThing.
Base Thing Template—Specify the new Thing Template created in step 1. In this example, AzureIot_ResourceProvider_ThingTemplate.
3. Create a Thing Template to be used as for creating Azure IoT Hub assets (Things) with the following settings:
Name—For example, AzureIot_RemoteThing_ThingTemplate.
Description—A description of the Thing Template.
Base Thing TemplateAzureIotThing (or any Thing Template that extends from AzureIotThing)
Implemented Shapes:—Implement all required Thing Shapes listed for assets in Creating Custom Thing Templates for Equipment Types.
4. Define an equipment type for your Azure IoT Hub assets in the EquipmentTypeSettings configuration table on the PTC.Factory.C_LaunchPointconfigurationThing_[ReleaseVersion] following the instructions in Creating Custom Equipment Types and Structures.
For the ThingTemplate value, specify the Thing Template created in step 3.
For the ResourceProvider value, specify the resource provider created in step 2.
5. Add the Azure IoT Hub connection type to the launch point configuration Thing.
a. Open PTC.Factory.C_LaunchPointConfigurationThing_[ReleaseVersion].
b. Add a new row to the RemoteConnectionSettings table with the following settings:
ConnectionType—Enter the name that you want displayed for the Azure IoT Hub connection type on the Create Connection window in Controls Advisor. For example, AzureIot.
ResourceProviderName—Enter the resource provider Thing created in step 2. In this example, AzureIot_ResourceProviderThing.
RemoteConnectionThingTemplateName—Select the AzureIotThing Thing Template.
EnabledInControlsAdvisor—Ensure that this checbox is cleared.
EnabledInTagPicker—Select this checkbox to make the connection type visible in the tag picker.
* 
If you create an asset based on the AzureIotThing Thing Template as a Thing in ThingWorx Composer, you must set the displayName property on the Thing for the asset to display correctly in ThingWorx Apps. If assets are created from Configuration and Setup > Equipment in ThingWorx Apps, this property is automatically set.
Was this helpful?