Last Updated on : 2025-05-26 02:11:37download
For combo devices running TuyaOS v3.10.0 or later, the SDK enables devices to proactively scan for nearby Wi-Fi networks. This feature offers the following advantages:
Example
ThingActivatorCoreKit.getScanDeviceManager().startBlueToothDeviceSearch(
60 * 1000,
arrayListOf(ScanType.SINGLE),
object: ThingActivatorScanCallback {
override fun deviceFound(scanBean: ThingActivatorScanDeviceBean) {
// After the device is discovered, check if the feature to get the list of Wi-Fi networks is supported
if (scanBean.isSupportObtainWifiListBeforeActive()) {
// Supported
}
}
override fun deviceRepeat(scanBean: ThingActivatorScanDeviceBean) {
}
override fun deviceUpdate(scanBean: ThingActivatorScanDeviceBean) {
}
override fun scanFailure(failureBean: ThingActivatorScanFailureBean) {
}
override fun scanFinish() {
}
}
)
Parameters
Parameter | Description |
---|---|
millisTimeOut | The search timeout value, in milliseconds. Recommended value: 60,000 ms. |
scanTypeList | SINGLE : Scan with a Bluetooth low energy device. |
thingActivatorScanCallback | The callback for the result of scanning. |
Request parameters
data class WifiInfoRequestBean(
var size: Int = 10, // The expected number of Wi-Fi networks to be returned
var timeout: Long = 5000L, // The device scanning timeout, in milliseconds
var uuid: String = "", // The UUID of the specified Bluetooth device
var spaceId: Long = -1, // The home ID
var modeEnum: ThingDeviceActiveModeEnum = ThingDeviceActiveModeEnum.BLE_WIFI,
var scanDeviceBean: ThingActivatorScanDeviceBean? = null // The device object passed during pre-pairing queries
)
Example
val wifiReqBean = WifiInfoRequestBean().apply {
uuid = thingActivatorScanDeviceBean.uniqueId
size = 10
timeout = 5000L
modeEnum = ThingDeviceActiveModeEnum.BLE_WIFI
scanDeviceBean = thingActivatorScanDeviceBean
}
ThingActivatorCoreKit.getActiveManager().newThingActiveManager().requestWifiList(
wifiReqBean,
object : IResultResponse<List<ThingActiveWifiInfoBean>> {
override fun onError(errorCode: String?, errorMessage: String?) {
//Failed to get the list of Wi-Fi networks
}
override fun onSuccess(result: List<ThingActiveWifiInfoBean>) {
// Got the list of Wi-Fi networks successfully
}
}
)
After obtaining the list of Wi-Fi networks, users can choose a desired network and proceed with pairing.
val activeManager = ThingActivatorCoreKit.getActiveManager().newThingActiveManager()
activeManager.startActive(ThingDeviceActiveBuilder().apply {
activeModel = ThingDeviceActiveModeEnum.BLE_WIFI
ssid = "WiFi SSID"
password = "WiFi Password"
timeOut = 120
relationId = homeId
listener = object : IThingDeviceActiveListener {
override fun onActiveSuccess(deviceBean: DeviceBean) {
// Pairing was successful
}
override fun onActiveError(errorBean: ThingDeviceActiveErrorBean) {
// Pairing failed
}
override fun onActiveLimited(limitBean: ThingDeviceActiveLimitBean) {
}
override fun onBind(devId: String) {
}
override fun onFind(devId: String) {
}
}
})
isSupportObtainWifiListBeforeActive()
.Before pairing, using this feature to get supported Wi-Fi networks can significantly improve pairing success rates. This feature is recommended as the preferred approach for combo pairing scenarios.
Error code | Error message | Suggestions |
---|---|---|
DEVICE_WIFI_SCAN_FAILED | Wi-Fi scanning failed. | Check if the device is working properly. You can try to scan again. |
DEVICE_NOT_SUPPORT | The device does not support this feature. | Confirm whether the device is running TuyaOS v3.10.0 or later. |
DEVICE_TIMEOUT | A timeout error has occurred. | Increase the timeout parameter value appropriately and try again. |
Is this page helpful?
YesFeedbackIs this page helpful?
YesFeedback