Last Updated on : 2023-03-09 08:17:40
To ensure network security, Wi-Fi passwords might be regularly changed. If backup Wi-Fi networks are unavailable, all smart devices connected to the Wi-Fi network must be paired again after the Wi-Fi password is changed. If you predefine multiple Wi-Fi passwords to create backup Wi-Fi networks, the system automatically switches to backup Wi-Fi networks and reconnects to the smart devices. They do not need to be paired again.
You can call deviceBean.getDevAttribute() & (1 << 12)
to check whether a specific device supports backup Wi-Fi networks. Valid values: 1
means that they are supported and 0
means that they are not supported.
Initialize an object
ITuyaWifiBackup wifiBackupManager = TuyaHomeSdk.getWifiBackupManager(devId);
API description
void getCurrentWifiInfo(ITuyaDataCallback<CurrentWifiInfoBean> dataCallback);
Parameters
Parameter | Description |
---|---|
dataCallback | The callback. |
Example
wifiBackupManager.getCurrentWifiInfo(new ITuyaDataCallback<CurrentWifiInfoBean>() {
@Override
public void onSuccess(CurrentWifiInfoBean result) {
}
@Override
public void onError(String errorCode, String errorMessage) {
}
});
API description
void getBackupWifiList(ITuyaDataCallback<BackupWifiListInfo> dataCallback);
Parameters
Parameter | Description |
---|---|
dataCallback | The callback. |
Example
wifiBackupManager.getBackupWifiList(new ITuyaDataCallback<BackupWifiListInfo>() {
@Override
public void onSuccess(BackupWifiListInfo result) {
}
@Override
public void onError(String errorCode, String errorMessage) {
}
});
API description
void setBackupWifiList(List<BackupWifiBean> backupWifiList, ITuyaDataCallback<BackupWifiResultBean> dataCallback);
Parameters
Parameter | Description |
---|---|
backupWifiList | The bean of backup Wi-Fi networks. |
dataCallback | The callback. |
Example
ArrayList<BackupWifiBean> backupWifiList = new ArrayList<>();
// Adds a backup Wi-Fi network and sets its password.
BackupWifiBean backupWifiBean = new BackupWifiBean();
backupWifiBean.ssid = "test1";
backupWifiBean.passwd = "12345678";
backupWifiList.add(backupWifiBean);
// Sets a hash value for an existing backup Wi-Fi network.
String ssid="test2";
String pwd="123123";
DeviceBean dev = TuyaHomeSdk.getDataInstance().getDeviceBean(devId);
String hashStr=SHA256Util.getBase64Hash(dev.getLocalKey() + ssid + pwd);
BackupWifiBean backupWifiBean2 = new BackupWifiBean();
backupWifiBean2.ssid = "test2";
backupWifiBean2.hash = hashStr;
backupWifiList.add(backupWifiBean2);
final ITuyaDataCallback<BackupWifiResultBean> setBackupCallback = new ITuyaDataCallback<BackupWifiResultBean>() {
@Override
public void onSuccess(BackupWifiResultBean result) {
}
@Override
public void onError(String errorCode, String errorMessage) {
}
};
wifiBackupManager.setBackupWifiList(backupWifiList, setBackupCallback);
API description
wifiBackupManager.onDestory();
Initialize an object
ITuyaWifiSwitch wifiSwitchManager = TuyaHomeSdk.getWifiSwitchManager(devId);
API description
void switchToNewWifi(String ssid, String password, ITuyaDataCallback<SwitchWifiResultBean> callback);
Parameters
Parameter | Description |
---|---|
ssid | The name of the target Wi-Fi network. |
password | The password of the target Wi-Fi network. |
callback | The callback. |
Example
wifiSwitchManager.switchToNewWifi(String ssid, String password, new ITuyaDataCallback<SwitchWifiResultBean>() {
@Override
public void onSuccess(SwitchWifiResultBean result) {
}
@Override
public void onError(String errorCode, String errorMessage) {
}
});
API description
void switchToBackupWifi(String hash, ITuyaDataCallback<SwitchWifiResultBean> callback);
Parameters
Parameter | Description |
---|---|
hash | The hash value of the target Wi-Fi network. |
callback | The callback. |
Example
wifiSwitchManager.switchToBackupWifi(hash,new ITuyaDataCallback<SwitchWifiResultBean>() {
@Override
public void onSuccess(SwitchWifiResultBean result) {
}
@Override
public void onError(String errorCode, String errorMessage) {
}
});
API description
wifiSwitchManager.onDestory();
Is this page helpful?
YesFeedbackIs this page helpful?
YesFeedback