IoTIoT

Compute
Elastic Cloud Server
Bare Metal Server
Auto Scaling
Image Management Service
Dedicated Host
FunctionGraph
Networking
Virtual Private Cloud
Elastic IP
Elastic Load Balance
NAT Gateway
Direct Connect
Virtual Private Network
Domain Name Service
VPC Endpoint
Cloud Connect
Enterprise Switch
Security & Compliance
Anti-DDoS
Web Application Firewall
Host Security Service
Data Encryption Workshop
Database Security Service
Advanced Anti-DDoS
Data Security Center
Container Guard Service
Situation Awareness
Managed Threat Detection
Compass
Cloud Certificate Manager
Anti-DDoS Service
Databases
Relational Database Service
Document Database Service
Data Admin Service
Data Replication Service
GaussDB NoSQL
GaussDB(for MySQL)
Distributed Database Middleware
GaussDB(for openGauss)
Developer Services
ServiceStage
Distributed Cache Service
Simple Message Notification
Application Performance Management
Application Operations Management
Blockchain
API Gateway
Cloud Performance Test Service
Distributed Message Service for Kafka
Distributed Message Service for RabbitMQ
Distributed Message Service for RocketMQ
Cloud Service Engine
DevCloud
ProjectMan
CodeHub
CloudRelease
CloudPipeline
CloudBuild
CloudDeploy
Cloud Communications
Message & SMS
Cloud Ecosystem
Marketplace
Partner Center
User Support
My Account
Billing Center
Cost Center
Resource Center
Enterprise Management
Service Tickets
HUAWEI CLOUD (International) FAQs
ICP License Service
Support Plans
Customer Operation Capabilities
Partner Support Plans
Professional Services
enterprise-collaboration
Meeting
IoT
IoT
Intelligent EdgeFabric
DeveloperTools
SDK Developer Guide
API Request Signing Guide
Terraform
Koo Command Line Interface
Updated at: Feb 24, 2022 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);

Did you find this page helpful?

Failed to submit the feedback. Please try again later.

Which of the following issues have you encountered?







Please complete at least one feedback item.

Content most length 200 character

Content is empty.

OK Cancel