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

Community Tip - Did you get called away in the middle of writing a post? Don't worry you can find your unfinished post later in the Drafts section of your profile page. X

Java SDK Tutorial Part 1

0% helpful (0/2)

 

Use our developer toolkit to connect Java-enabled devices and build an application.

 

 

GUIDE CONCEPT

This project will introduce complex aspects of the ThingWorx Java SDK and help you to get started with development.

 

Following the steps in this guide, you will develop your own IoT application with the ThingWorx Java SDK.

 

We will teach you how to use the Java programming language to connect and build IoT applications to be used with the ThingWorx Platform.

 

NOTE: This guide's content aligns with ThingWorx 9.3. The estimated time to complete all parts of this guide is 60 minutes.

 

 

YOU'LL LEARN HOW TO

 

  • Establish and manage a secure connection with a ThingWorx server, including SSL negotiation and connection maintenance
  • Enable easy programmatic interaction with the Properties, Services, and Events that are exposed by Entities running on a ThingWorx server
  • Create applications that can be directly used with your device running the Java programming language
  • Basic concepts of the Java Edge SDK
  • How to use the Java Edge API to build a real-world application
  • How to utilize resources provided in the Edge SDK to help create your own application

 

Step 1: Completed Example

 

Download the Java_SDK_Extra_Samples.zip attached to this article and extract the contents.

 

In this tutorial we walk you through a real-world scenario for a power grid network. The Java_SDK_Extra_Files.zip file provided to you contains the following files and Entities as a completed version of the scenario we will cover. Please keep in mind, the Java SDK can also be utilized for Android development and general Java development.

 

NameDescription
PowerGridSource code for an extensive example of a power grid network
Delivery TruckSource code for the delivery truck application
ExampleClientSource code for examples on how to do different tasks
FileTransferSource code for a file transfer application
TunnelingSource code for a tunneling application
SimpleThingSource code for simple connections and examples
SteamSensorSource code for a steam sensor that provides configuration during runtime

 

Once you complete your Java environment setup and import the JavaExampleEntities.xml file into ThingWorx Composer, you will be able to utilize these Entities:

 

FeatureEntity TypeDescription
 Generator1 Thing Used with the power grid edge example
 Generator2 Thing Used with the power grid edge example
 Generator3 Thing Used with the power grid edge example
 Consumer1 Thing Used with the power grid edge example
 Consumer2 Thing Used with the power grid edge example
 Consumer3 Thing Used with the power grid edge example
DeliveryTruck_1ThingUsed with the delivery truck edge example
DeliveryTruck_2ThingUsed with the delivery truck edge example
DeliveryTruck_3ThingUsed with the delivery truck edge example
FileTransferExampleThingUsed with the file transfer edge example
TunnelExampleThingUsed with the tunnel edge example
SimpleThing_1ThingUsed as a simple edge example for coding and connectivity
SimpleDataShapeData ShapeUsed as a simple edge Data Shape example for coding and connectivity
DeliveryTruckShapeData ShapeUsed as a Data Shape with the delivery truck edge example
EdgeExampleModel TagUsed as a Model Tag for tagging all entities; enables quicker searches
DeliveryTableData TableUsed as a Data Table with the delivery truck edge example
Default_userUserUser created to be used with the SDK examples
PTCOrganizationAn Organization that helps with security in edge examples
Admin_keyApplication KeyAn Application Key used for the Admin
Default_keyApplication Key

An Application Key used for the Default User; this is the recommended key to use


 

Step 2: Environment Setup

 

You can use the Java SDK with any IDE of your choice. The steps below demonstrate how to use the Eclipse IDE as an example.

 

If you have not already done so, install a Java Development Kit (JDK) from Corretto or OpenJDK in order to compile and run Java code and download the ThingWorx Java SDK. The download will include the JARs necessary to run the SDK.

 

The Eclipse Java IDE is a centralized location to store the code, resources, and files utilized by this guide. Download and install the latest Eclipse Java IDE from the Eclipse website.

 

Create Java Project

 

  1. When the Eclipse Welcome window appears, click Create a new Java Project.

    Step-Java-1.png

  2. In the New Java Project setup wizard, enter ThingWorx Development as the project name. Java 1.8 is the supported and recommended JDK.

    Step-Java-2.png

     

  3. Click Finish

 

Set Up User Library

 

  1. Right click the newly created ThingWorx Development project in the Package Explorer.

  2. Expand the Build Path selection and select Add Libraries.

    Step-Java-3.png

  3.  Click User Library. Click Next.

    Step-Java-4.png

  4.  Click User Libraries.

    Step-Java-5.png

  5. Click New, enter ThingWorx Java SDK as the library name. Click OK.

    Step-Java-6.png

     

Set Up Javadoc

 

  1. With the ThingWorx Java SDK selected, click the Add External JARs button.


    Step-Java-7.png

     

     

     
  2. In the pop-up window, navigate to the location in which you unzipped the ThingWorx Java Edge SDK.

  3. Navigate to the lib folder, select all of the JARs, then click Open.

    select_all_sdk_library.png

  4. Within the ThingWorx Java SDK library, expand the thingworx-common-xxxx.jar folder and select Javadoc location.

  5. Click Edit.

    Step-Java-9.png

  6. Select the Javadoc in archive and External file radio buttons, then click Browse.

    Step-Java-10.png

  7. In the pop-up window, navigate to the location in which you unzipped the ThingWorx Java Edge SDK. Navigate to the lib folder, highlight the thingworx-java-sdk JavaDoc JAR File, then click Open.

    select_sdk_library.png

  8. Click OK.

  9. Repeat steps 1-8 for the thingworx-communications-client JAR’s Javadoc location field shown in step 10.

  10. Confirm that your setup looks like this:

     Step-Java-12.png

  11. Click OK.

  12. Select the checkbox for the ThingWorx Java SDK library, then click Finish.

    Step-Java-13.png

     

Import Sample Files

 

  1. Right click the ThingWorx Development project and click Import.Step-Java-14.png
     
  2. In the Import wizard, type File System into the filter. Click Next.

    Step-Java-15.png

     

     

  3. In the pop-up window, navigate to the location in which you unzipped the ThingWorx Java Edge SDK. Navigate inside the samples folder and select the src folder.


    Step-Java-16.png

     

     
  4. Click OK.

  5. Select the checkbox for the src folder, then click Browse.


    Step-Java-17.png

     

     
  6. Type ThingWorx Development/src into the text box.


    Step-Java-18.png

     

  7. Click OK.

  8. Click Finish.

    Step-Java-19.png

     

     
  9. Expand the ThingWorx Development project.


    Step-Java-End.png

     

 

 

Click here to view Part 2 of this guide.

Version history
Last update:
‎Oct 17, 2022 04:04 PM
Updated by:
Labels (1)
Attachments
Contributors