Reporting Device Data

API Function

This API is used by a directly connected device to report data to the platform or used by a gateway to report data received from an indirectly connected device to the platform.

deviceId, requestId, and serviceId of the API Reporting Device Data are assembled by the SDK as the header of the message, and serviceProperties is assembled as the body of the message. The message is assembled in JSON format.

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

Identifier of a request. This parameter is used to match the service command delivered by the 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

Identifier of a device.

serviceId

Mandatory

String

Identifier of a service, which is defined in the device's product model.

serviceProperties

Mandatory

String

Service properties, which are the parameter names and values in JSON format defined in the device's product model. The values are the data to be reported by the device.

Return Value

Return Value

Description

true

Success

false

Failure

Return values only show the API call result. 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 SDK 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;
        }
    }