Releasing Data
API Function
This API is used by the gateway to release data of directly connected devices or indirectly connected devices to the IoT platform. In data releasing, users can select topics for the released data, which is not supported in data reporting. In addition, the JSON character strings need to be assembled by the developer and transferred to the API. The SDK is used only for transparent transmission.
API Description
1 |
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 |
Specifies the topic of the released data. |
uiQos |
Mandatory |
int |
Specifies the value of MQTT. Default value: 1 |
pbstrServiceData |
Mandatory |
byte[] |
Specifies the packet body of the released data. |
Return Value
Return Value |
Description |
true |
Success |
false |
Failure |
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 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 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;
}
}
|
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot