English
English
简体中文
Contact Us
Register
Log In
layoutIndex

P2P Download from Robot Vacuums

Last Updated on : 2022-07-13 06:30:49download

A robot vacuum that supports peer-to-peer (P2P) capabilities provides P2P download channels. Map data and cleaning routes are directly transmitted from the robot vacuum to the app through P2P channels. The data does not need to be uploaded to a cloud storage server for downloading. Therefore, data transmission becomes more efficient at a lower cost of cloud storage.

Get the robot vacuum object

Example

ObjC:

TuyaSmartSweeperDevice *sweeper = [[TuyaSmartSweeperDevice alloc] initWithDeviceId:@"devId"]

Swift:

sweeper = TuyaSmartSweeperDevice.init(deviceId: "devId")

Access the P2P service

- (void)connectDeviceByP2P:(void (^)(void))success
                   failure:(void (^)(NSError * _Nullable error))failure;

Parameters

Parameter Description
success The success callback.
failure The failure callback.

Example

ObjC:

[self.sweeper connectDeviceByP2P:^{

} failure:^(NSError * _Nullable error) {

}];

Swift:

sweeper?.connect(byP2P: {

}, failure: { error in

})

Enable P2P downloading

Enable file transmission after the success callback of connectDeviceByP2P. If a P2P connection is closed unexpectedly, a failure callback is executed. For more information about the error codes, see Error codes. The failure callback indicates that the device might have a network exception. To fix the problem, you can call connectDeviceByP2P to try to reconnect the device.

- (void)startObserverSweeperDataByP2P:(TuyaSmartSweeperP2PDownloadType)downloadType
                       receiveP2PData:(void (^)(NSDictionary *data))receiveP2PData
                              failure:(void (^)(NSError * _Nullable error))failure;

Parameters

Parameter Description
downloadType The method to download data through P2P connections. Valid values:
  • TuyaSmartSweeperP2PDownloadTypeOnce: The data downloading is stopped after the existing device data is downloaded. New data will not be downloaded.
  • TuyaSmartSweeperP2PDownloadTypeStill: Device data is continuously downloaded until the device automatically stops transferring data.
receiveP2PData The callback that is executed when hexadecimal data is received through P2P connections.
failure The failure callback.

Callback description

Parameter Description
type The data type. Valid values:
  • 0: map data
  • 1: cleaning route data
  • 3: navigation route data
  • -1: error data
data The data downloaded through P2P connections.

Example

ObjC:

[self.sweeper startObserverSweeperDataByP2P:downloadType receiveP2PData:^(NSDictionary * _Nonnull data) {
        if (data) {
            NSLog(@"%@",data);
        }
} failure:^(NSError * _Nullable error) {

}];

Swift:

sweeper?.startObserverSweeperData(byP2P: TuyaSmartSweeperP2PDownloadType.still, receiveP2PData: { data in

}, failure: { error in

})

Check P2P connection status

Checks P2P connection status. A successful response is returned to indicate that the device is connected as expected through a P2P channel. A failed response is returned to indicate that the P2P connection is closed unexpectedly. You can call connectDeviceByP2P to try to reconnect the device.

- (BOOL)P2PActiveCheck;

Disable P2P downloading

Pauses data transmission through P2P channels, but retains P2P channels. You can call startObserverSweeperDataByP2P to continue downloading data.

- (void)stopObserverSweeperDataByP2P:(void (^)(void))success
                             failure:(void (^)(NSError * _Nullable error))failure;

Parameters

Parameter Description
success The success callback.
failure The failure callback.

Example

ObjC:

[self.sweeper stopObserverSweeperDataByP2P:^{

} failure:^(NSError * _Nullable error) {

}];

Swift:

sweeper?.stopObserverSweeperData(byP2P: {

}, failure: { error in

})

Disable the P2P service

Stops downloading data, destroys P2P channels, and releases the occupied memory and thread resources.

Example

ObjC:

[self.sweeper onDestroyP2P];

Swift:

sweeper?.onDestroyP2P()

Error codes

Error code Description
-9000 The device information has faults.
-9001 The SDK dependency is not added.
-9002 A P2P connection is being created.
-9003 The specified device is offline.
-9004 Timeout has occurred.
-9005 No map files are found.

For more information about error codes, see the error codes of the IPC SDK.