JAVA Library

The following page provides you assistance in developing an IoT application program using the TR50 compliant library implemented using the JAVA programming language.

  • This Open Source library is available from the Management Portal Developer -> Resources -> TR50_Clients -> JAVA folder.
    You can directly download it from the TR50 client JAVA library.
    • This code is for reference only. Necessary permissions are granted by the MIT license to modify it.
  • Uses client functions that implement both MQTT and HTTP 1.0 protocol to communicate with the IoT Portal. Can also be easily extended to use other protocols.
  • Uses a common worker, for each client implementation, that provides helper functions to interact with the IoT Portal

The following describes TR50 compliant APIs provided in the JAVA Library implementation. The client APIs handle connectivity, authentication and sending/receiving synchronous and asynchronous TR50 messages to and from the IoT Portal. The common worker or helper APIs provide the user a full set of extended functions intended to be used to leverage the full capabilities of the IoT Portal.

CLIENT API LIBRARY

To use any of the client API libraries below you must initialize a DwMqttClient or DwHttpClient object based on the protocol you will be using to communicate with the IoT Portal

Connection:

MQTT: To establish a connection over MQTT, initialize the MQTT connection with the appropriate connection parameters and provide a valid username and password to authenticate and connect to the IoT Portal as a user. When connecting to the IoT Portal as a Thing, the user will be the ThingKey and the password will be the application token associated with the organization for that Thing.

public void initialize(String host, String port, boolean isSSL, String clientID);
public int authenticate(String user, String password);

HTTP: To establish a connection over HTTP, initialize the HTTP connection with the appropriate connection url and provide a valid username and password to connect to the IoT Portal as a user. When authenticating to the IoT Portal as a Thing,  the user will be the ThingKey and the password will be the application token associated with the organization for that Thing.

public void initialize(String url);
public int authenticate(String user, String password);

For a more comprehensive description of the TR50 connection APIs with examples, see Client API reference guide. 

Communication:

To send a raw JSON message over MQTT/HTTP use the following client APIs for synchronous communication. The MQTT client also can use asynchronous communication.

public int sendJSONRequest(int msgId,String json, StringReply response);
public int sendAsyncJSONRequest(int msgId, String json);

To send a TR50 message over MQTT/HTTP use the following client APIs for synchronous communication. The MQTT client also can use asynchronous communication. For more information on how to build a tr50 message, see Communication examples. (DwPacket)

public int sendPacket(DwPacket packet);
public int sendPacket(DwPacket packet, DwOpenReceiveActionListener recv, Object response);

All other TR50 Communication is handle by through the common worker library and associated APIs. See TR50 Compliant IoT Portal APIs section below.

For a more comprehensive list of the TR50 connection APIs with examples, see TR50 Client API reference guide.

Response:

Responses in the TR50 JAVA library are divided into a generic responses and helper objects for parsing more specific responses from the common worker APIs.

All APIs can pass in the DwOpenResponse object to parse a standard tr50 response message from the IoT Portal. The DwOpenResponse object has the following set of functions to gather data parsed in the TR50 response message.

The following are the APIs supported for gathering response data from the IoT Portal.

public boolean isSuccess();
public String[] getErrormessages();
public int[] getErrorcodes();
public void parseResponse(String json);
public String getJsonResponse();

In addition, each individual API call in the common worker library can pass in a helper response object that parses data in a TR50 response message from the IoT Portal, that is specific to that API call. 

For a more comprehensive list of the worker APIs and helper functions, see TR50 Worker API reference guide.

TR50 Compliant IoT Portal APIs 

The following section will provide you with an up-to-date list of helper functions intended to be used to leverage the full capabilities of IoT Portal. These helper functions use the TR50 compliant JAVA library and implement the functionality exposed by the IoT Portal Interface. Refer to the IoT Portal APIs to explore the request and reply message formats for each of the IoT Portal Interface commands.