Help Center/ IoT/ API Reference/ AgentLite API Reference (Java)/ APIs/ Reporting Device Service Data
Updated on 2022-02-24 GMT+08:00

Reporting Device Service Data

API Function

This API is used by the gateway to report data of directly connected devices or indirectly connected devices to the IoT platform.

API Description

1
public static boolean dataReport(int cookie, String requstId, String deviceId, String serviceId, String serviceProperties);

Class

DataTransService

Parameter Description

Parameter

Mandatory or Optional

Type

Description

cookie

Optional

int

The value ranges from 1 to 65535.

requstId

Mandatory

String

Identifies a request. This parameter is used to match the service command delivered by the IoT platform, which can be obtained from the broadcast described in Receiving a Command.

  • Active data reporting: The value of this parameter is NULL.
  • Command result reporting: The value of this parameter is the request ID of the command which the reported data matches.

deviceId

Mandatory

String

Identifies a device.

serviceId

Mandatory

String

Identifies a service, which is defined in the device profile.

serviceProperties

Mandatory

String

Specifies the service attributes, which are the parameter names and values in JSON format defined in the device profile. The attribute values are the data to be reported by the device.

Return Value

Return Value

Description

true

Success

false

Failure

NOTE:

Return values only show API calling results. For example, the return value true indicates that the API is called successfully but does not indicate that the service data is reported successfully. The service data is reported successfully only after the DataTransService broadcast is received.

Example

Call this API to report data.

1
DataTransService.dataReport(1211, NULL, "xxxx_xxxx_xxxx_xxxx", "DoorWindow", "{\"status\":\"OPEN\"}");

Implement the observer API provided by the AgentLite before calling this API.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
public class Subscribe implements MyObserver {
    public Subscribe (Observable dataTransService) {
        dataTransService. registerObserver (this);
    }
    @Override
    public void update(IotaMessage arg0) {
        // TODO Auto-generated method stub
        System.out.println("AgentLiteDataTrans receives a notification:" + arg0)
        int mMsgType = arg0.getMsgType();
        switch(mMsgType) {
//Receive a data reporting response.
            case IodevService.IODEV_MSG_DATA_REPORT_RSP:
            getDataReportAnswer(arg0);
            break;
//Receive a command passively.
            case IodevService.IODEV_MSG_RECEIVE_CMD:
            getCmdReceive(arg0);
            break;
//MQTT message push
            case IodevService.IODEV_MSG_MQTT_PUB_RSP:
            //logoutResultAction(iotaMsg);
            break;
            default:
            break;
        }
    }