Last Updated on : 2023-06-05 02:49:29download
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
Objective-C:
ThingSmartSweeperDevice *sweeper = [[ThingSmartSweeperDevice alloc] initWithDeviceId:@"devId"]
Swift:
sweeper = ThingSmartSweeperDevice.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
Objective-C:
[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:(ThingSmartSweeperP2PDownloadType)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 to invoke 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
Objective-C:
[self.sweeper startObserverSweeperDataByP2P:downloadType receiveP2PData:^(NSDictionary * _Nonnull data) {
if (data) {
NSLog(@"%@",data);
}
} failure:^(NSError * _Nullable error) {
}];
Swift:
sweeper?.startObserverSweeperData(byP2P: ThingSmartSweeperP2PDownloadType.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
Objective-C:
[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
Objective-C:
[self.sweeper onDestroyP2P];
Swift:
sweeper?.onDestroyP2P()
P2P SDK performs automatic reconnection after a session is closed in the foreground or is brought to the foreground from the background. Currently, Tuya provides the method to stop P2P automatic reconnection. Thus, you can determine when reconnection will be implemented.
- (void)connectDeviceByP2P:(BOOL)isStopReconnect success:(void (^)(void))success failure:(void (^)(NSError * _Nullable error))failure;
Example
[self.sweeper connectDeviceByP2P:NO success:^{
} failure:^(NSError * _Nullable error) {
}];
Error code | Description |
---|---|
-9000 | The device information has exceptions. |
-9001 | The SDK dependency is not added. |
-9002 | The P2P connection is being created. |
-9003 | The specified device is offline. |
-9004 | A timeout error has occurred. |
-9005 | No map files are found. |
-9006 | The P2P connection is closed. |
For more information about error codes, see the error codes of the IPC SDK.
Is this page helpful?
YesFeedbackIs this page helpful?
YesFeedback