Gyroscope and Visual Robot Vacuums

Last Updated on : 2023-05-22 06:38:30download

Sweeper SDK provides HTTP and HTTPS API requests and real-time channels to enable data queries. Historical records and other data can be queried or deleted by HTTP and 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 and HTTPS API requests

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

Access to API

TuyaHomeSdk.getRequestInstance()

Example

public interface ITuyaSmartRequest {

	/**
	*
	* @param apiName  The API name.
	* @param version  The version number.
	* @param postData Sends data.
	* @param callback The callback.
	* @param object The data structure that receives the callback data, for example, a Java Bean.
	*/
	<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 parameters

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

  • version: 2.0

  • postData:

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

Sample response

{
	"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 parameters

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

  • version: 1.0

  • postData:

    Field 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.

Sample response

{
	"datas":[{
		"recordId":"162992AAXKaZCdL2tDvVcWYecT9AA9630150",
		"gid":38498424,
		"dpId":15,
		"gmtCreate":1629929630203,
		"value":"20210826052504804100145",
		"uuid":"ecc8c633ef1d9ede"
	}],
	"totalCount":1
}
Field 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 Development Platform.
gmtCreate long The time when the cleaning record was created.
value String The information about the map. The value is used to parse subRecordId.
uuid String The device ID.

Query details of a historical cleaning task

Request parameters

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

  • version: 2.0

  • postData:

    {
    "devId": "xxx",
    "subRecordId": 31,
    "start":"",
    "size": 500
    }
    
    Field 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 entries to be returned in each call.

    Protocol for parsing value

    Record time
    12 digits
    Cleaning time
    3 digits
    Cleaning area
    3 digits
    subRecordId
    5 digits
    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.

Sample response

{
	"devId": "xxx",
	"startRow": "mtnva58ee6817b605ddcc6_31_1535622776561",
	"dataList": ["3e3f02403e013e3f00", "3f3f024040013f3f00"],
	"subRecordId": 31,
	"hasNext": true,
	"startTime": 1535621566,
	"endTime": 1535623017,
	"status": 2
}
Field Type Description
startRow String The value of Start passed in the next API request.
subRecordId Integer The ID of the cleaning task.
startTime String Query start time
endTime String The end time.
hasNext Boolean Specifies whether to return the next page.

Delete historical cleaning tasks

Up to 100 entries can be deleted in each call.

Request parameters

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

  • version: 1.0

  • postData:

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

    The uuid parameter in the preceding example for JSON is the unique ID of each cleaning task. This parameter is not the uuid parameter of a device but equal to the recordId parameter of a historical task.

Sample response

{
	"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.

Access to API: TuyaHomeSdk.getTransferInstance();

Data flow

Gyroscope and Visual Robot Vacuums

Subscribe to map streaming data

API description

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 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

API description

void unRegisterTransferDataListener(ITuyaDataCallback<TransferDataBean> callback);

Example

TuyaHomeSdk.getTransferInstance().unRegisterTransferDataListener(this);