English
English
简体中文
Contact Us
Register
Log In
Language
English
English
简体中文
Contact Us
Log In
Register
Go to main website
App Develop

App Development

Tuya provides multiple mobile app development methods such as no-code or IoT App SDK development to maximize the monetization of IoT apps.
layoutIndex

Gyroscope and Visual Robot Vacuums

Last Updated on : 2021-11-10 07:12:02download

Sweeper SDK provides HTTP/HTTPS API requests and real-time channels to enable data queries. Historical records and other data can be queried or deleted by HTTP/HTTPS API requests. The cleaning data transmitted from and to robot vacuums can be queried by the registration of listeners on real-time channels.

HTTP API methods

Smart Life App SDK provides common HTTP/HTTPS methods. In the API requests, the method name, version, and request parameters are required.

API entry: TuyaHomeSdk.getRequestInstance()

public interface ITuyaSmartRequest {

	/**
	*
	* @param apiName  The API name.
	* @param version  The version.
	* @param postData The transmitted data.
	* @param callback The callback.
	* @param object The data structure that receives callback data, such as a JavaBean.
	*/
	<T> void requestWithApiName(String apiName, String version, Map<String, Object> postData, Class<T> object, final ITuyaDataCallback<T> callback);

	<T> void requestWithApiNameWithoutSession(String apiName, String version, Map<String, Object> postData, Class<T> object, final ITuyaDataCallback<T> callback);

	void onDestroy();
}

Query the latest cleaning task

Request parameter

  • apiName:tuya.m.device.media.latest

  • version:2.0

  • postData:

    {
    "devId": "xxx",
    "start":"",
    "size": 500
    }
    

Example

{
	"devId": "xxx",
	"startRow": "mtnva58ee6817b605ddcc6_35_1535629239586",
	"dataList": [ "373702373700", "383702383802373901383901383800"],
	"subRecordId": 35,
	"hasNext": true,
	"startTime": 1535629049,
	"endTime": 1535629244,
	"status": 2
}

Query historical data of cleaning tasks

Request parameter

  • apiName:tuya.m.sweeper.cleaning.history.get

  • version:1.0

  • postData:

    Field name Type Description
    devId String The device ID.
    offset Integer The number of entries starting from which entries are returned.
    limit Integer The maximum number of entries returned on each page.
    startTime Long The start time of the time range to be queried.
    endTime Long The end time of the time range to be queried.

Response parameter

{
	"recordId":"162992AAXKaZCdL2tDvVcWYecT9AA9630150",
	"gid":38498424,
	"dpId":15,
	"gmtCreate":1629929630203,
	"value":"20210826052504804100145",
	"uuid":"ecc8c633ef1d9ede"
}
Field name Type Description
recordId String The map ID.
gid int The home group ID.
dpId int The data point (DP) ID generated on the Tuya IoT Platform.
gmtCreate long The time when the cleaning record was created.
value String The information about the map. The value is returned after subRecordId is parsed.
uuid String The device ID.

Query the details of a cleaning task

Request parameter

  • apiName:tuya.m.device.media.detail

  • version:2.0

  • postData:

    {
    "devId": "xxx",
    "subRecordId": 31,
    "start":"",
    "size": 500
    }
    
    Field name Type Description
    devId String The device ID.
    subRecordId Integer The ID of the cleaning task to be queried. Parse the value parameter of the historical cleaning tasks to get the ID. The parsing rules vary depending on different data lengths. The following table describes the rules.
    start String The start position. The value in the first request is empty. In the follow-up requests, the value of startRow in the last response is required.
    size Integer The maximum number of returned entries in total.

    value parsing protocol

    Record time (12 bits) Cleaning time (3 bits) Cleaning area (3 bits) subRecordId (5 bits)) Example Description
    Yes Yes Yes Yes 20200319202500300200123
    • The panel displays the timestamp when the record was reported by the microcontroller unit (MCU).
    • Tap the record to show the map.
    No Yes Yes Yes 00300200123
    • The panel displays the timestamp when the record was reported to the cloud.
    • Tap the record to show the map.
    Yes Yes Yes No 202003192025003002
    • The panel displays the timestamp when the record was reported by the MCU.
    • Tap the record without showing the map.
    No Yes Yes No 003002
    • The panel displays the timestamp when the record was reported to the cloud.
    • Tap the record without showing the map.

Response parameter

{
	"devId": "xxx",
	"startRow": "mtnva58ee6817b605ddcc6_31_1535622776561",
	"dataList": ["3e3f02403e013e3f00", "3f3f024040013f3f00"],
	"subRecordId": 31,
	"hasNext": true,
	"startTime": 1535621566,
	"endTime": 1535623017,
	"status": 2
}
Field name Type Description
startRow String The value of Start required in the next request.
subRecordId Integer The cleaning record ID.
startTime String The start time of the queried time range.
endTime String The end time of the queried time range.
hasNext Boolean Indicates whether the next page is included.

Delete one or more historical cleaning tasks

A maximum of 100 historical cleaning tasks can be deleted in each call.

Request parameter

  • apiName:tuya.m.sweeper.cleaning.history.delete

  • version:1.0

  • postData:

    {
    	"devId": "xxx",
    	"uuid": "15607600058B81A6C4A0273FDD61091D0B02403848501,
    15607600058B81A6C4A0273FDD61091D0B0240384850"、
    }
    

    In this example, uuid is the cleaning record ID indicated by recordId, rather than the device uuid.

Response parameter

{
	"result":true,
	"success":true,
	"status":"ok",
	"t":1557740732829
}

Real-time data channels

Real-time channels can be registered to listen for reported device data streams. Arrays are returned in the response and parsed into required data, such as the x-coordinate, y-coordinate, and color values, using the device protocol.

API entryTuyaHomeSdk.getTransferInstance();

Data flow

Gyroscope and Visual Robot Vacuums

Subscribe to map streaming data

void registerTransferDataListener(ITuyaDataCallback<TransferDataBean> callback);

Example

TuyaHomeSdk.getTransferInstance().registerTransferDataListener(new ITuyaDataCallback<TransferDataBean>() {
	@Override
	public void onSuccess(TransferDataBean result) {

	}

	@Override
	public void onError(String errorCode, String errorMessage) {

	}
});

TransferDataBean

Field name Type Description
data byte[] The streaming data of NSData type.
  • Bits 0 to 3 indicate subRecordId of a map.
  • Bits 4 to 12 are not business data and will neither be parsed.
Note that actual map data is indicated starting from Bit 13. Every three bits create a map point, including the x-coordinate, y-coordinate, and point type of the map point.
devId String The device ID.

Unsubscribe from map streaming data

void unRegisterTransferDataListener(ITuyaDataCallback<TransferDataBean> callback);

Example

TuyaHomeSdk.getTransferInstance().unRegisterTransferDataListener(this);