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.

serviceProperties

Mandatory

String

Specifies the service attribute.

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 TOPIC_DATA_REPORT_RSP broadcast is received.

Output

Broadcast Name

Broadcast Parameter

Member

Description

TOPIC_DATA_REPORT_RSP

IotaMessage

(Obtained by using intent.getSerializableExtra(DataTransService.DATATRANS_BROADCAST_IE_IOTAMSG))

DATATRANS_IE_RESULT

Specifies the data reporting result.

DATATRANS_IE_COOKIE

The value ranges from 1 to 65535.

Example

A user uses JSON components to assemble service attributes (serviceProperties) based on the profile format.

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

The device waits for the data reporting result.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
//Register a broadcast receiver to process the device service data reporting.
BroadcastReceiver mReportDataRsp;
mReportDataRsp = new BroadcastReceiver() {
    @Override 
    public void onReceive(Context context, Intent intent) {
        //Do Something 
        IotaMessage iotaMsg = (IotaMessage)intent.getSerializableExtra(DataTransService. DATATRANS_BROADCAST_IE_IOTAMSG);
        int cookie = iotaMsg.getUint(DataTransService.DATATRANS_IE_COOKIE, 0);
        int ret = iotaMsg.getUint(DataTransService.DATATRANS_IE_RESULT, 0);
        return;
    }
};
mLocalBroadcastManager = LocalBroadcastManager.getInstance(this);
IntentFilter filterReportData 
= new IntentFilter(DataTransService.TOPIC_DATA_REPORT_RSP);
mLocalBroadcastManager.registerReceiver(mReportDataRsp, filterReportData);