Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tuya/tuya-android-backup-wifi-sample-kotlin
https://github.com/tuya/tuya-android-backup-wifi-sample-kotlin
tuya
Last synced: 13 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/tuya/tuya-android-backup-wifi-sample-kotlin
- Owner: tuya
- Created: 2021-03-15T03:08:34.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2021-03-16T08:43:09.000Z (almost 4 years ago)
- Last Synced: 2024-11-12T14:24:55.969Z (2 months ago)
- Topics: tuya
- Language: Kotlin
- Homepage:
- Size: 126 KB
- Stars: 0
- Watchers: 15
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Device standby network
[中文版](README_zh.md) |[English](README.md)
The standby network is to save the WiFi and password to the device. When the device is currently connected to WIFI and there is no network, the device can fetch the saved WIFI by itself. You can also actively switch through the app. The device standby network case is provided here.
## Features
- Gets the current network of the device
- Switching device network
- Get and set up the standby network### Gets the current network of the device
```
wifiBackup = TuyaHomeSdk.getWifiBackupManager(deviceId)wifiBackup?.getCurrentWifiInfo(object : ITuyaDataCallback {
override fun onSuccess(result: CurrentWifiInfoBean) {
}override fun onError(errorCode: String, errorMessage: String) {
}
})
//Be careful to destroy wifiBackup
wifiBackup?.onDestroy()```
**Declaration**
Parameters | Description
---|---
ssid | WiFi ssid
signal | Signal strength
network | Distinguish between wired network and WiFi, with 0 for WiFi and 1 for Wired
version | version
hash | Network data hash value, used to distinguish networks### Gets a list of standby WiFi existing on the current device
```
wifiBackupManager = TuyaHomeSdk.getWifiBackupManager(devId)
wifiBackupManager?.getBackupWifiList(object : ITuyaDataCallback {
override fun onSuccess(result: BackupWifiListInfo) {
}override fun onError(errorCode: String, errorMessage: String) {
}
})
//Be careful to destroy wifiBackupManager
wifiBackupManager?.onDestroy()
```
**Declaration**Parameters | Description
---|---
maxNum | The maximum number of alternate networks that can be set up
backupList | Backup network of device### Generate the hash data of WiFi information
Used to compare the hash of the standby network to determine whether the network has been added
```
val hash = SHA256Util.getBase64Hash(dev?.getLocalKey() + ssid + pwd)
```### Add backup network and switch
```
wifiSwitchManager?.switchToNewWifi(ssid, pwd, object : ITuyaDataCallback {
override fun onSuccess(result: SwitchWifiResultBean?) {
}override fun onError(errorCode: String, errorMessage: String) {
}
}
)
wifiBackupManager?.onDestroy()
```### Switch to the standby network
```
wifiSwitchManager?.switchToBackupWifi(hash, object : ITuyaDataCallback {
override fun onSuccess(result: SwitchWifiResultBean?) {
}override fun onError(errorCode: String, errorMessage: String) {
}
}
)
wifiBackupManager?.onDestroy()
```### Set up standby network
Note that alternate networks can be added or removed using this method
```
wifiBackup = TuyaHomeSdk.getWifiBackupManager(devId)
wifiBackup?.setBackupWifiList(backupWifiBeans, object : ITuyaDataCallback {
override fun onSuccess(result: BackupWifiResultBean) {
}override fun onError(errorCode: String, errorMessage: String) {
}
})
wifiBackup?.onDestroy()```
**Declaration**
Parameters | Description
---|---
List backupWifiList | Alternate network list
ITuyaDataCallback dataCallback | Set up the alternate network callback