Skip to content

OpenAPI SDK Usage Guide

OpenAPI SDK is mainly used for SaaS system integration, enabling product device management and remote control of devices through SaaS applications.

Operation Steps

Prerequisites

  1. Before using OpenAPI services, you need to create a SaaS application under the SaaS Development -> SaaS Management menu.

  2. Enable and authorize the API service packages you need to use on the SaaS Details -> Services page. You can only call the API interfaces under that service package after authorization.

  3. Authorize product data that the SaaS application can access on the SaaS Details -> Products page. You can only query data under authorized products through the API after authorization.

  4. Obtain AccessKey and AccessSecret, which will be used to exchange for an access Token later.

Development Environment Preparation

The example uses the following development environment:

SDK Function List

quecloud-sdk-dev-mgr:

Method NameFunction Description
getProductItemsGet product categories
getProductDetailGet product details
getProductListGet product list
getDeviceListGet device list
getDeviceDetailGet device details
deviceResourceGet device resources
getDeviceDataHistoryGet device historical uplink/downlink data
getDeviceEventDataGet device event log data
getDeviceLocationLatestGet device location information data
getTslJsonGet thing model data
generateSnGet SN
createSnBindDeviceCreate SN and device binding relationship
findDkListQuery corresponding device list by PK and SN list
findSnListQuery corresponding SN list by device list
delSnBindDeviceDelete SN and device binding relationship
createQueceCreate queue
deleteQueceDelete queue
getQueceDetailGet queue details
createSubscribeCreate regular subscription
createEnterpriseUserSubscribeCreate enterprise user subscription
createSaasUserSubscribeCreate SaaS user subscription
createEndUserSubscribeCreate end-user subscription
getSubscribeDetailGet subscription details
startSubscribeStart subscription
stopSubscribeStop subscription
deleteSubscribeDelete subscription

quecloud-sdk-dev-msg:

Method NameFunction Description
sendDeviceDataSend downlink data to device
batchSendDeviceDataSend downlink data to devices in batch
deviceDmReadDataRead device thing model property data
deviceDmWriteDataSend downlink thing model data to device
deviceRawSendDataSend downlink transparent transmission data
deviceDmsendServiceDataSend downlink thing model service data to device

SDK Example

  1. Reference jar package from central repository
Plain
a) Product and device management
<dependency>
  <groupId>com.quectel.aiot</groupId>
  <artifactId>quecloud-sdk-standard-mgr</artifactId>
  <version>2.1.0.RELEASE</version>
</dependency>

b) Device data uplink/downlink management
<dependency>
    <groupId>com.quectel.aiot</groupId>
    <artifactId>quecloud-sdk-dev-msg</artifactId>
    <version>1.9.0.RELEASE</version>
</dependency>
  1. Initialize SDK

a) Create an InitClientProfile object to store accessKey, accessSecret, endpoint (for Europe data center, enter iot-api.acceleronix.io) and other information

b) Create a Client object. For product and device management, initialize a MgrClient object; for device uplink/downlink, initialize a MsgClient object

  1. Call steps:

SaaS SDK encapsulates two classes for each API: the request parameter class (*Request) and the request response class (*Response).

a) Complete SDK initialization. Get MgrClient Client/MsgClient Client object

b) Create a parameter object for the corresponding API request method

c) Use set methods on the parameter object to set the request parameter values required by the API.

  i) Use the obtained Client object to directly call methods in the object to get a response object. Each response object includes success (success indicator), msg (return information), errorMsg (error information, returns specific error information when success is false), body (body is an object that carries the specific information value returned by each API)

  ii) Use the catch() method to handle exception errors.

For API list and corresponding Request and Response object descriptions, please see API List

d) Using the downlink data API as an example, write the code as follows:

bash
public static void main(String[] args) {
        try{
            // accessKey and accessSecret are created by developers in the developer center
            InitClientProfile initClientProfile = new InitClientProfile(
                    "${accessKey}",
                    "${accessSecret}",
                    "${endpoint}");
            // Get the MsgClient object. Singleton pattern is recommended. This object contains SDK for device data downlink.
            MsgClient msgClient = new MsgClient(initClientProfile);
 
            // PASSTHROUGH:transparent transmission PROPERTY:property SERVICE:service
            String type="PASSTHROUGH|PROPERTY|SERVICE";
            // GET:report UP DOWN:downlink
            String operate="GET|DOWN";
 
            // Send thing model property data to a single device
            /**
             * Send downlink data to device. data is the specific content of the downlink data. When operate=GET, the data format is "["key1","key2",…]" (key is the thing model identifier). When operate=DOWN, the data format is "[{key1:value1},{key2:value2}]" (key is the thing model identifier).
             * Examples:
             * Property bool/int/float/double/enum/date/text
             * "[{\"key\":\"value\"}]"
             * Property array
             * "[{\"key\":[{\"id\":\"value1\"},{\"id\":\"value2\"}]}]" (id is 0)
             * Property struct
             * "[{\"key\":[{\"key1\":\"value1\"},{\"key2\":\"value2\"}]}]"
             * Property array containing struct
             * "[{\"key\":[{\"id\":[{\"key1\":\"value1\"}]},{\"id\":[{\"key2\":\"value2\"}]}]}]" (id is 0)
             * Service call bool/int/float/double/enum/date/text
             * "[{\"key\":[{\"key1\":\"value1\"},{\"key2\":\"value2\"},{\"key3\":\"value3\"}]}]"
             * Service call array
             * "[{\"key\":[{\"key1\":[{\"id\":\"value1\"},{\"id\":\"value1\"}]}]}]" (id is 0)
             * Service call struct
             * "[{\"key\":[{\"key1\":[{\"key2\":\"value2\"},{\"key3\":\"value3\"}]}]}]"
             * Service call array, and array contains struct
             * "[{\"key\":[{\"key1\":[{\"id\":[{\"key2\":\"value2\"}]},{\"id\":[{\"key3\":\"value3\"}]}]}]}]" (id is fixed at 0)
             */
 
            type = "PROPERTY";
            operate = "DOWN";
            DeviceSendDataRequest deviceSendTslDataRequest = new DeviceSendDataRequest("${productKey}","${deviceKey}","${data}",type,operate);
            DeviceSendDataResponse tslResult = msgClient.sendDeviceData(deviceSendTslDataRequest);
            log.info("Single device downlink model data return result:{}", JSONObject.toJSONString(tslResult));
        }catch(Exception e){
            log.info("Error sending thing model property data to single device",e);
        }
    }

For detailed Demo code, see GitHub repository: Product and device management (quecloud-sdk-dev-mgr)

https://github.com/thridparty-cloud2/quecloud-sdk-dev-mgr-demonstration.git

Device data uplink/downlink (quecloud-sdk-dev-msg)

https://github.com/thridparty-cloud2/quecloud-sdk-dev-msg-demonstration.git