Last Updated on : 2024-06-24 09:16:09download
This topic describes the device pairing in Wi-Fi AP mode.
Before the pairing process, the SDK must get a pairing token from the cloud in the networked state. The token is valid for 10 minutes and expires immediately after the device is paired.
API description
Get the pairing token.
ThingOSActivator.deviceActivator().getActivatorToken(final long gid, final IThingActivatorGetToken activatorGetToken);
Parameter description
Parameter | Description |
---|---|
gid | The relation ID of the area to which the device belongs. See Get Area Relation ID. |
activatorGetToken | The callback. |
Example
ThingOSActivator.deviceActivator().getActivatorToken(gid,
new IThingActivatorGetToken() {
@Override
public void onSuccess(String token) {
}
@Override
public void onFailure(String s, String s1) {
}
});
Example
ActivatorBuilder builder = new ActivatorBuilder()
.setContext(context)
.setSsid(ssid)
.setPassword(password)
.setActivatorModel(ActivatorModelEnum.TY_AP)
.setTimeOut(timeout)
.setToken(token)
.setListener(new IThingSmartActivatorListener() {
@Override
public void onError(String errorCode, String errorMsg) {
}
@Override
public void onActiveSuccess(DeviceBean devResp) {
}
@Override
public void onStep(String step, Object data) {
}
}
));
Parameter description
Parameter | Description |
---|---|
token | The activation key. |
context | The context passed to the activity. |
ssid | The name of the home Wi-Fi network the paired device is connected to. |
password | The password of the home Wi-Fi network the paired device is connected to. |
activatorModel | The pairing mode. It is set to ActivatorModelEnum.TY_AP for Wi-Fi AP mode. |
timeout | The pairing timeout, defaulting to 100 , in seconds. |
IThingActivator mTuyaActivator = ThingOSActivator.deviceActivator().newActivator(builder);
// Start pairing.
mTuyaActivator.start();
// Stop pairing.
mTuyaActivator.stop();
// Destroy the cache and listeners when exiting the page.
mTuyaActivator.onDestroy();
Is this page helpful?
YesFeedbackIs this page helpful?
YesFeedback