Last Updated on : 2023-03-23 07:12:12
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.
The robot vacuum P2P feature is developed based on the P2P capabilities of the IPC vertical category. To integrate with the robot vacuum P2P library, you must also integrate the latest version of Tuya P2P SDK.
ITuyaSweeperKitSdk iTuyaSweeperKitSdk = TuyaOptimusSdk.getManager(ITuyaSweeperKitSdk.class);
ITuyaSweeperP2P tuyaSweeperP2P = iTuyaSweeperKitSdk.getSweeperP2PInstance(devId);
API description
/**
*
* @param callback The callback that is executed when a P2P connection is created.
*/
void connectDeviceByP2P( SweeperP2PCallback callback);
Parameters
Parameter | Description |
---|---|
callback | The callback that is executed when a P2P connection is created. |
Example
tuyaSweeperP2P.connectDeviceByP2P(new SweeperP2PCallback() {
@Override
public void onSuccess() {
// The success callback.
}
@Override
public void onFailure(int i) {
// The failure callback.
}
});
API description
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.
/**
*
* @param downloadType The method to download data.
* @param callback The callback that is executed when P2P downloading is enabled.
* @param callback2 The callback for P2P data.
*/
void startObserverSweeperDataByP2P(DownloadType downloadType, SweeperP2PCallback callback, SweeperP2PDataCallback callback2);
Parameters
Parameter | Description |
---|---|
downloadType | The method to download data through P2P connections. Valid values:
|
callback | The callback that is executed when P2P downloading is enabled. |
callback2 | The callback that is executed when data is received through P2P connections. |
Parameters of SweeperP2PBean
Parameter | Description |
---|---|
type | The data type. Valid values:
|
data | The data downloaded through P2P connections. |
Example
tuyaSweeperP2P.startObserverSweeperDataByP2P(DownloadType.P2PDownloadTypeOnce, new SweeperP2PCallback() {
@Override
public void onSuccess() {
// The success callback.
}
@Override
public void onFailure(int i) {
// The failure callback.
}
}, new SweeperP2PDataCallback() {
@Override
public void receiveData(int type, @Nullable SweeperP2PBean sweeperP2PBean) {
// The callback that is executed when data is received through P2P connections. `type` indicates the type of received data.
}
@Override
public void onFailure(int i) {
// The failure callback.
}
});
Pauses data transmission through P2P channels, but retains P2P channels. You can call startObserverSweeperDataByP2P
to continue downloading data.
/**
*
* @param callback The callback that is executed when P2P downloading is disabled.
*/
void stopObserverSweeperDataByP2P(SweeperP2PCallback callback);
Parameters
Parameter | Description |
---|---|
callback | The callback that is executed when P2P downloading is disabled. |
Example
tuyaSweeperP2P.stopObserverSweeperDataByP2P(new SweeperP2PCallback() {
@Override
public void onSuccess() {
// The success callback.
}
@Override
public void onFailure(int i) {
// The failure callback.
}
});
/**
* Checks P2P connection status.
*/
boolan checkP2PActive();
Example
tuyaSweeperP2P.checkP2PActive();
Stops downloading data, destroys P2P channels, and releases the occupied memory and thread resources.
/**
*
* @param callback The callback that is executed when P2P downloading is disabled.
*/
void onDestroyP2P();
Example
tuyaSweeperP2P.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.
/**
* Stop automatic reconnection
* @param isStopReconnect Specifies whether to stop automatic reconnection. Default value: `false`.
*/
void stopReconnect(boolean isStopReconnect);
Example
tuyaSweeperP2P.stopReconnect(true);
Error code | Description |
---|---|
-9000 | The data of deviceBean is missing. |
-9001 | The required P2P SDK is not integrated. |
-9002 | The P2P connection is being created. |
-9003 | The specified device is offline. |
-9004 | Timeout 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.
Problem: The SweeperP2PCallback
API method or the SweeperP2PCallback
class is marked in red and cannot be found. The arr
file of the dependency library is found. But the following error message is returned:
// This class file was compiled with different version of Kotlin compiler and can't be decompiled.
// Current compiler ABI version is 1.1.16
// File ABI version is 1.5.1
Solution: Try to update the Kotlin version of Android Studio at Preferences > Languages & Framework > Kotlin.
Is this page helpful?
YesFeedbackIs this page helpful?
YesFeedback