Gyroscope and Visual Robot Vacuums

Last Updated on : 2024-06-19 09:05:32download

Sweeper SDK provides API requests and real-time channels to enable data queries.

  • Historical records and other data can be queried or deleted by common API requests.
  • The cleaning data transmitted from and to robot vacuums can be queried by the registration of listeners on real-time channels.

Common API methods

Class name Description
ThingSmartSweeperDevice The class of ‘Power by Tuya’ (PBT) robot vacuums.

Query the latest cleaning task

API description

//Streaming service 1.0
- (void)queryLatestCleanRecord:(NSString *)devId start:(NSString *)start size:(NSInteger)size complete:(void(^)(ThingSmartSweeperRecordDetail *model, NSError *error))complete;
//Streaming service 2.0
- (void)queryLatestCleanRecordV2:(NSString *)devId start:(NSString *)start size:(NSInteger)size complete:(void(^)(ThingSmartSweeperRecordDetail *model, NSError *error))complete;

Request parameters

Field name Type Description
devId String The device ID.
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. The value is 500.

Response parameters of ThingSmartSweeperRecordDetail

Field name Type Description
devId String The device ID.
startRow String The index for paged query.
dataList Array The streaming data.
subRecordId String The ID of the cleaning task.
hasNext BOOL Indicates whether the next page is included.
startTime long The start time of the queried period.
endTime long The end time of the queried period.

Sample response

{
	"devId":"6ccdd506b7186ee85avntm",
	"startRow":"mtnva58ee6817b605ddcc6_35_1535629239586",
	"dataList":[
		"373702373700",
		"383702383802373901383901383800",
		"373802373901373800",
		"373802363901363801373800",
		"373702373602373600",
		"373502373500",
		"373502373402373301363301373400",
		"363502363500",
		"363502363500"
	],
	"subRecordId":35,
	"hasNext":true,
	"startTime":1535629049,
	"endTime":1535629244,
	"status":2
}

Query historical data of cleaning tasks

API description

- (void)getHistoryCleanRecordList:(NSString *)devId offset:(NSInteger )offset limit:(NSInteger)limit startTime:(long long)startTime endTime:(long long)endTime complete:(void(^)(NSArray <ThingSmartSweeperRecordList *> *list, NSError *error))complete;

Request parameters

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 period to be queried.
endTime Long The end time of the period to be queried.

The array NSArray <ThingSmartSweeperRecordList *> *list is returned in the response. The following table describes the fields of ThingSmartSweeperRecordList.

Field name Type Description
recordId String The map ID.
gid int The home group ID.
dpId int The data point (DP) ID generated for the robot vacuum product on the Tuya Developer 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.

Sample response

{
	"recordId":"162992AAXKaZCdL2tDvVcWYecT9AA9630150",
	"gid":38498424,
	"dpId":15,
	"gmtCreate":1629929630203,
	"value":"20210826052504804100145",
	"uuid":"ecc8c633ef1d9ede"
}

Query the details of a cleaning task

API description

//Streaming service 1.0
- (void)getCleanRecordDetail:(NSString *)devId subRecordId:(NSInteger)subRecordId start:(NSString *)start size:(NSInteger)size complete:(void(^)(ThingSmartSweeperRecordDetail *model, NSError *error))complete;
//Streaming service 2.0
- (void)getCleanRecordDetailV2:(NSString *)devId subRecordId:(NSInteger)subRecordId mapId:(NSInteger)mapId datatype:(NSInteger)datatype start:(NSString *)start size:(NSInteger)size complete:(void(^)(ThingSmartSweeperRecordDetail *model, NSError *error))complete;

Request parameters

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 entries to be returned in each call. The value is 500.

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 20200319202500
300200123
  • The panel displays the timestamp when the record was reported by the 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 202003192025
003002
  • 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.

You can use the parsing method provided in the class ThingSmartSweeperRecordList.

+ (NSString *)subRecordIdObtainFromValue:(NSString *)value;

You can also follow the rules of the protocol for parsing value to parse data on your own.

Response parameters of ThingSmartSweeperRecordDetail

Field name Type Description
devId String The device ID.
startRow String The index for paged query.
dataList Array The streaming data.
subRecordId String The ID of the cleaning task.
hasNext BOOL Indicates whether the next page is included.
startTime long The start time of the queried period.
endTime long The end time of the queried period.

Sample response

{
	"devId":"6ccdd506b7186ee85avntm",
	"startRow":"mtnva58ee6817b605ddcc6_31_1535622776561",
	"dataList":[
		"3e3f02403e013e3f00",
		"3f3f024040013f3f00",
		"3f3f02403f014040013f3f00",
		"3f40024140014040013f3f024041013f41013f3f00",
		"3f3f024040014041013f41013f3f00"
	],
	"subRecordId":31,
	"hasNext":true,
	"startTime":1535621566,
	"endTime":1535623017,
	"status":2
}

Delete historical data of cleaning tasks

API description

- (void)deleteHistoryCleanRecord:(NSString *)devId recordId:(NSString *)recordId complete:(void(^)(BOOL success, NSError *error))complete;

Request parameters

Field name Type Description
devId String The device ID.
recordId String The cleaning task IDs. You can call getHistoryCleanRecordList to get the IDs.

Sample response

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

Real-time data channels

Data flow

Gyroscope and Visual Robot Vacuums

Functional description

PBT gyroscope or visual robot vacuums transmit map data through streaming channels. The ThingSmartSweeperDeviceDelegate delegate protocol is implemented to receive the callback for received map streaming data.

Class name Description
ThingSmartSweeperDevice The class of PBT robot vacuums.

Subscribe to map streaming data

API description

Subscribes to map streaming data of a robot vacuum.

- (void)subscribeDeviceDataTransfer;

Example

ObjC:

- (void)subscribeDevice {

	[self.sweeperDevice subscribeDeviceDataTransfer];
}

Swift:

func subscribeDevice() {
	sweeperDevice?.subscribeDeviceDataTransfer()
}

Unsubscribe from map streaming data

API description

Unsubscribes from map streaming data of a robot vacuum.

- (void)unsubscribeDeviceDataTransfer;

Example

ObjC:

- (void)unsubscribeDevice {

	[self.sweeperDevice unsubscribeDeviceDataTransfer];
}

Swift:

func unsubscribeDevice() {
	sweeperDevice?.unsubscribeDeviceDataTransfer()
}

Execute a streaming data callback

API description

The callback to invoke when real-time streaming data is reported by a robot vacuum.

- (void)sweeperDevice:(ThingSmartSweeperDevice *)sweeperDevice didReceiveStreamData:(NSData *)data;

Parameters

Parameter Description
sweeperDevice The instance object of ThingSmartSweeperDevice.
data The streaming data of NSData type. ~Bits 0 to 3 indicate subRecordId of a map, and ~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.

Example

ObjC:

self.sweeperDevice = [ThingSmartSweeperDevice deviceWithDeviceId:<#devId#>];
self.sweeperDevice.delegate = self;

// Implements the delegate method.
- (void)sweeperDevice:(ThingSmartSweeperDevice *)sweeperDevice didReceiveStreamData:(NSData *)data {

}

Swift:

sweeperDevice = ThingSmartSweeperDevice.init(deviceId: "your_devId")
sweeperDevice?.delegate = self

func sweeperDevice(_ sweeperDevice: ThingSmartSweeperDevice, didReceiveStreamData data: Data) {

}