Last Updated on : 2024-06-26 09:33:28download
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
IThingWifiBackup wifiBackupManager = ThingHomeSdk.getWifiBackupManager(devId);
API description
void getCurrentWifiInfo(IThingDataCallback<CurrentWifiInfoBean> dataCallback);
Parameters
Parameter | Description |
---|---|
dataCallback | The callback. |
Example
wifiBackupManager.getCurrentWifiInfo(new IThingDataCallback<CurrentWifiInfoBean>() {
@Override
public void onSuccess(CurrentWifiInfoBean result) {
}
@Override
public void onError(String errorCode, String errorMessage) {
}
});
API description
void getBackupWifiList(IThingDataCallback<BackupWifiListInfo> dataCallback);
Parameters
Parameter | Description |
---|---|
dataCallback | The callback. |
Example
wifiBackupManager.getBackupWifiList(new IThingDataCallback<BackupWifiListInfo>() {
@Override
public void onSuccess(BackupWifiListInfo result) {
}
@Override
public void onError(String errorCode, String errorMessage) {
}
});
API description
void setBackupWifiList(List<BackupWifiBean> backupWifiList, IThingDataCallback<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 = ThingHomeSdk.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 IThingDataCallback<BackupWifiResultBean> setBackupCallback = new IThingDataCallback<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
IThingWifiSwitch wifiSwitchManager = ThingHomeSdk.getWifiSwitchManager(devId);
API description
void switchToNewWifi(String ssid, String password, IThingDataCallback<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 IThingDataCallback<SwitchWifiResultBean>() {
@Override
public void onSuccess(SwitchWifiResultBean result) {
}
@Override
public void onError(String errorCode, String errorMessage) {
}
});
API description
void switchToBackupWifi(String hash, IThingDataCallback<SwitchWifiResultBean> callback);
Parameters
Parameter | Description |
---|---|
hash | The hash value of the target Wi-Fi network. |
callback | The callback. |
Example
wifiSwitchManager.switchToBackupWifi(hash,new IThingDataCallback<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