cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Need help navigating or using the PTC Community? Contact the community team. X

Azure Connector 4 Part 2

No ratings

 

 

Step 4: Launch IoT Hub Connector

 

  1. Open a shell or a command prompt window. On a Windows machine, open the command prompt as Administrator.

  2. The AZURE_IOT_OPTS environment variable must be set before starting the Azure IoT Hub Connector. Below are sample commands using the default installation directory.

    • On Windows: set AZURE_IOT_OPTS=-Dconfig.file=C:\ThingWorx-Azure-IoT-Connector-<version>\azure-iot-<version>-application\conf\azure-iot.conf -Dlogback.configurationFile=C:\ThingWorx-Azure-IoT-Connector-<version>\azure-iot-<version>-application\conf\logback.xml

    • On Linux: export AZURE_IOT_OPTS="-Dconfig.file=/var/opt/ThingWorx-Azure-IoT-Connector-<version>/azure-iot-<version>-application/conf/azure-iot.conf -Dlogback.configurationFile=/var/opt/ThingWorx-Azure-IoT-Connector-<version>/azure-iot-<version>-application/conf/logback.xml"

      NOTE: You must run the export command each time you open a shell or command prompt window.

  3. Change directories to the bin subdirectory of the Azure IoT Hub Connector installation.

  4. Start the Azure IoT Hub Connector with the appropriate command for your operating system.

    • On Windows: azure-iot.bat
    • On Linux: /azureiot

      Connector_start.png

       

      NOTE: On Windows you may have to shorten the installation directory name or move the bin directory closer to the root directory of your system to prevent exceeding the Windows limit on the classpath length.

  5. The Connection Server should start with no errors or stack traces displayed. If the program ends, check the following:
    • Java version is 1.8.0, update 92 or greater and is Java(TM) not OpenJDK
    • Open azure-iot.conf and confirm ThingWorx Foundation is set to the correct URL and port.
    • Confirm the platform scheme is ws if http is used to access ThingWorx.
    • Confirm all Azure credentials are correct for your Azure account.

  6. In ThingWorx Foundation click the Monitoring tab then click Connection Servers. You should see a server named azure-iot-cxserver-{server-uuid}, where {server-uuid} is a unique identifier that is assigned automatically to the server.

    CXServerRunning.png

     

 

Step 5: Import Device from Azure

 

With the ThingWorx Azure IoT Connector, you can import into ThingWorx any existing devices that are currently provisioned to the Azure IoT Hub.

 

Add Device Azure IoT Hub

If you have not provisioned any devices to your Azure IoT Hub you can learn more about Azure IoT Hub device identity before following the steps below to create a test device.

  1. In your Azure Portal, click All Resources, then select the name of your IoT Hub.
  2. Under Explorers click IoT devices, then click + Add.
  3. Enter a name for your device, then click Save
  4. When the device name appears in the list it is ready to us

    AddDevice.png

     

 

Import Device into ThingWorx


We will manually execute a service in ThingWorx that will import Azure IoT Hub devices into ThingWorx.

  1. In ThingWorx Composer, navigate to the ConnectionServicesHub Thing.

  2. Click Services tab and scroll to the ImportAzureIotDevices service and click the execute Arrow.

    ImportAzureIotDevice.png

     
    NOTE: The * in the pattern field will act as a wildcard and import all devices, you can enter a string to match that will only import a subset of all available devices.

    ImportAzureIotDevice_execute.png

     

     

  3. Click Execute to import the devices then click Done.

  4. Click Things in the left column to see the Things that were created.

    viewImportedDevice.png

     

 

Step 6: Set-up and Run Demo

 

The ThingWorx Azure IoT Connector download includes a Java application that simulates a device connecting to your Azure IoT Hub. A ThingTemplate is also included and can be imported into ThingWorx.

 

Import Demo Templates

  1. In ThingWorx Composer, click Import/Export menu, then click From File and browse to ../demo/edgedevice- demo/platform/entities/CPUDemo_AllEntities.xml

     

    foundation_QS_uploadSimulator.png

     

  2. Click Import then click Close when the import successful message is displayed.

  3. Create a new Thing using the imported template azureDemo1, enter a name for your Thing and click Save.

    NOTE: You will enter this name in the demo config file in the next step.

 

Configure Demo Application

  1. In the ../demo/edge-device-demo/conf subdirectory, open the edge-device.conf file with a text editor.

  2. Edit the deviceId to be the name of the Thing you created in step 3.

  3. Edit the iotHubHostName to use the name of your hub plus the domain: azure-devices.net. For example, sample-iot-hub.azuredevices.net.

  4. Edit the registryPolicyKey property to use the Primary Key for the registryReadWrite policy in the Azure IoT Hub.

Below is an example configuration:

// Azure Edge Device Demo configuration azure-edge-device { // Name of the remote thing on the ThingWorx platform, which should match the Azure Device ID deviceId = "alstestedgething" // Name of the hub host in Azure iotHubHostname = "alsiot.azure-devices.net" // Policy name used by this thing (could require services as well in future) registryPolicyName = "registryReadWrite" // The Key related to the policy above registryPolicyKey = "pzXAi2nonYWsr3R7KVX9WuzV/1234567NZVTuScl/Kg=" }


Run Demo Script

 

  1. Open a shell or Command Prompt, set the EDGE_DEVICE_DEMO_OPTS environment variable to refer to the file you just edited:
    • Linux - export EDGE_DEVICE_DEMO_OPTS="-Dconfig.file=../conf/edge-device.conf"
    • Windows - set EDGE_DEVICE_DEMO_OPTS="-Dconfig.file=../conf/edge-device.conf"

  2. Launch the demo from the ../demo/edge-device-demo/bin subdirectory, using the edge-device-demo command.

  3. Return to the ThingWorx Composer and open the Properties page of the Azure Thing that you created previously.

  4. Click the refresh button to see the properties change every five seconds.

  5. Open the azure-iot-demo Mashup and view the Load Average and CPU gauges, and the increases in the values of the Cycle and Uptime fields.


    NOTE
    : If the edgedevice-demo is running on Windows, the Load Average does not register.

demo_mashup.png

Step 7: Next Steps

 

Congratulations! You've successfully completed the Connect Azure IoT Hub to ThingWorx Quickstart. By following the steps in this lesson, you imported a device created in Azure into ThingWorx and saw how data from an Azure device could be used in a ThingWorx Mashup.


Learn More

We recommend the following resources to continue your learning experience:

CapabilityGuide
ConnectChoose a Connectivity Method
BuildDesign Your Data Model
ExperienceCreate Your Application UI

 

Additional Resources

 

If you have questions, issues, or need additional information, refer to:

 

ResourceLink
CommunityDeveloper Community Forum
SupportGetting Started with ThingWorx

 

Version history
Last update:
‎Nov 02, 2022 02:29 PM
Updated by:
Labels (1)
Contributors