Last Updated on : 2023-05-22 06:38:30download
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.
Example
ObjC:
TuyaSmartSweeperDevice *sweeper = [[TuyaSmartSweeperDevice alloc] initWithDeviceId:@"devId"]
Swift:
sweeper = TuyaSmartSweeperDevice.init(deviceId: "devId")
- (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 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:
|
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:
|
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
})
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;
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
})
Stops downloading data, destroys P2P channels, and releases the occupied memory and thread resources.
Example
ObjC:
[self.sweeper onDestroyP2P];
Swift:
sweeper?.onDestroyP2P()
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.
Is this page helpful?
YesFeedbackIs this page helpful?
YesFeedback