Backup Wi-Fi Networks

Last Updated on : 2024-03-15 02:58:56download

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.

Manage network settings

Query current Wi-Fi information

Initialize an object

IThingDevicePlugin devicePlugin = PluginManager.service(IThingDevicePlugin.class);
IThingWifiBackup wifiBackupManager = devicePlugin.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) {

    }
});

Query current backup Wi-Fi networks

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) {

            }
        });

Set a list of backup Wi-Fi networks

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 = ThingOSDevice.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);

Exit page and destroy listener

API description

wifiBackupManager.onDestory();

Switch between Wi-Fi networks

Switch to a new Wi-Fi network

Initialize an object

IThingDevicePlugin devicePlugin = PluginManager.service(IThingDevicePlugin.class);
IThingWifiSwitch wifiSwitchManager = devicePlugin.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) {

            }
        });

Switch to a backup Wi-Fi network

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) {

            }
        });

Exit page and destroy listener

API description

wifiSwitchManager.onDestory();