Last Updated on : 2024-05-14 05:52:52download
This topic describes the access point (AP) to pair devices. It is a connection capability for pairing over Wi-Fi. In the pairing process, a mobile phone connects to the AP of the smart device and broadcasts the Wi-Fi credentials and pairing token over the LAN to enable the smart device to get this information for network connection and pairing. With a high success rate and good reliability, this mode adapts to 2.4 GHz and 5 GHz dual-band routers. However, users need to manually switch between the Wi-Fi bands connected to the mobile phone.
Before the AP 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 builder = ThingDeviceActiveBuilder()
.setActiveModel(ThingDeviceActiveModeEnum.AP)
.setSsid(ssid)
.setPassword(pwd)
.setToken(token)
.setTimeOut(timeout)
.setListener(object : IThingDeviceStatePauseActiveListener {
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) {
}
override fun onActivatorStatePauseCallback(stateData: PauseStateData?) {
}
})
val mThingActivatorManager = ThingActivatorCoreKit.getActiveManager().newThingActiveManager()
mThingActivatorManager.startActive(builder)
Parameter description
Parameters | Meaning |
---|---|
ssid | The name of the target Wi-Fi network. |
password | The password of the target Wi-Fi network. |
token | The information about the token. |
timeout | The timeout value, in seconds. |
activeModel | The pairing capability enum. |
listener | The callback for the result of pairing. |
onActivatorStatePauseCallback
, use IThingDeviceActiveListener
instead.onActivatorStatePauseCallback
returns the reason for the paused pairing, such as an incorrect password or router connection failure. The app can rescan for Wi-Fi networks and select one again. Then, call resumeActive
to continue pairing.When a device returns the reason for the paused pairing (such as an incorrect password or router connection failure) through onActivatorStatePauseCallback
, the app can restart the pairing process with this method.
val builder = ThingResumeActiveBuilder()
.setSsid(ssid)
.setPassword(pwd)
mThingActivatorManager.resumeActive(builder)
mThingActivatorManager.stopActive()
Is this page helpful?
YesFeedbackIs this page helpful?
YesFeedback