Releasing Data
API Function
This API is used by a directly connected device to release data to the platform or used by a gateway to release data received from an indirectly connected device to the platform. Different from the parameters of the API Reporting Device Data, topic of this API is fixed at /cloud/signaltrans/v2/categories/data, and serviceData serves as the message body (containing the header and body) and is transmitted by the AgentLite SDK without format adjustment or assembling.
API Description
1 | public static boolean mqttDataPub(int cookie, String topic, int qos, byte[] serviceData);
|
Class
DataTransService
Parameter Description
| Parameter | Mandatory or Optional | Type | Description |
|---|---|---|---|
| uiCookie | Optional | int | The value ranges from 1 to 65535. |
| pucTopic | Mandatory | String | Topic of the data to be released. |
| uiQos | Mandatory | int | Value of MQTT. Generally, the value is 1. |
| pbstrServiceData | Mandatory | byte[] | Packet body of the data to be released. |
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 released successfully. The service data is released successfully only after the DataTransService broadcast is received.
Example
Call this API to release data.
1 | DataTransService. mqttDataPub(1211, "/huawei/v1/devices/336d9bac-9ebf-44e9-95cf-efac5f05da3a/services/Storage", 1, bstrBody);
|
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 27 28 29 30 31 32 | 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;
case IodevService.IODEV_MSG_MQTT_SUB_RSP:
//TopicSubcribeResultAction(iotaMsg);
break;
case IodevService.IODEV_MSG_MQTT_DATA_RECV_RSP:
//DataRecvAction(iotaMsg);
break;
default:
break;
}
}
|
Last Article: Receiving a Command
Next Article: AgentLite API Reference (Android)
Did this article solve your problem?
Thank you for your score!Your feedback would help us improve the website.