Last Updated on : 2024-05-14 03:30:05download
This topic describes pairing a device using the Wi-Fi EZ mode, also known as Wi-Fi Easy Connect or SmartConfig. In the pairing process, a mobile phone connects to the router and broadcasts the Wi-Fi credentials and pairing token to enable the smart device to get this information for connection and pairing. It is easy-to-use, but has compatibility requirements for mobile phones and routers. The success rate is lower than that of AP mode.
Before the pairing process, the app must get a pairing token from the cloud in the networked state. The token is valid for 10 minutes and expires immediately after the device is paired. A new token must be generated if the device needs to be paired again.
ThingActivatorDeviceCoreKit.getActivatorInstance()
.getActivatorToken(spaceId,IThingActivatorGetToken)
Parameter description
Parameters | Description |
---|---|
spaceId | The ID of the home with which the device is bound. |
callback | The callback for the result. |
val scankey = ThingActivatorCoreKit.getScanDeviceManager().startEzDeviceSearch(
context: Context,
ssid: String,
pwd: String? = "",
token: String,
millisTimeOut: Long,
thingActivatorScanCallback: ThingActivatorScanCallback
)
Parameter description
Parameters | Description |
---|---|
context | The context. |
ssid | The name of the target Wi-Fi network. |
pwd | The password of the target Wi-Fi network. |
token | The information of the token. |
millisTimeOut | The timeout value, in milliseconds. |
thingActivatorScanCallback | The search timeout callback. |
ThingActivatorCoreKit.getScanDeviceManager().stopScan(scankey)
val builder = ThingDeviceActiveBuilder()
.setActiveModel(ThingDeviceActiveModeEnum.EZ) //Device pairing mode enum.
.setActivatorScanDeviceBean(thingActivatorScanDeviceBean)
.setTimeOut(timeout)
.setListener(object : IThingDeviceActiveListener {
override fun onFind(devId: String) {
}
override fun onBind(devId: String) {
}
override fun onActiveSuccess(deviceBean: DeviceBean) {
}
override fun onActiveError(errorBean: ThingDeviceActiveErrorBean) {
}
override fun onActiveLimited(limitBean: ThingDeviceActiveLimitBean) {
}
})
val activeManager = ThingActivatorCoreKit.getActiveManager().newThingActiveManager()
activeManager.startActive(builder)
Parameter description
Parameters | Description |
---|---|
activatorScanDeviceBean | The discovered device. |
timeout | The timeout value, in seconds. |
activeModel | The pairing capability enum. |
listener | The callback for the result of pairing. |
val builder = ThingDeviceActiveBuilder()
.setActiveModel(ThingDeviceActiveModeEnum.EZ)
.setSsid(ssid)
.setPassword(pwd)
.setToken(token)
.setTimeOut(timeout)
.setListener(object : IThingDeviceActiveListener {
override fun onFind(devId: String) {
}
override fun onBind(devId: String) {
}
override fun onActiveSuccess(deviceBean: DeviceBean) {
}
override fun onActiveError(errorBean: ThingDeviceActiveErrorBean) {
}
override fun onActiveLimited(limitBean: ThingDeviceActiveLimitBean) {
}
})
val activeManager = ThingActivatorCoreKit.getActiveManager().newThingActiveManager()
activeManager.startActive(builder)
Parameter description
Parameters | Description |
---|---|
ssid | The name of the target Wi-Fi network. |
password | The password of the target Wi-Fi network. |
token | The information of the token. |
timeout | The timeout value, in seconds. |
activeModel | The pairing capability enum. |
listener | The callback for the result of pairing. |
// Stop pairing.
activeManager.stopActive()
Is this page helpful?
YesFeedbackIs this page helpful?
YesFeedback