Advertisement
habibalmaula10

AP MODE PAIRING FUNCTION

Oct 23rd, 2023
1,635
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 1.75 KB | None | 0 0
  1.     private fun pairApMode() {
  2.         println("pairApMode ==> SSID: $ssid, Password: $password, Token: $tokenPairing")
  3.         try {
  4.             val builder = ActivatorBuilder()
  5.                 .setSsid(ssid)
  6.                 .setContext(applicationContext)
  7.                 .setPassword(password)
  8.                 .setActivatorModel(ActivatorModelEnum.THING_AP)
  9.                 .setTimeOut(100)
  10.                 .setToken(tokenPairing)
  11.                 .setListener(object : IThingSmartActivatorListener {
  12.                     override fun onStep(step: String?, data: Any?) {
  13.                         println("onStep ==>$step $data")
  14.                     }
  15.  
  16.                     override fun onActiveSuccess(devResp: DeviceBean?) {
  17.                         val arguments: HashMap<String, String?> = HashMap()
  18.                         arguments["deviceId"] = devResp?.devId
  19.                         arguments["name"] = devResp?.name
  20.  
  21.                         methodChannel.invokeMethod("pairingSuccess", arguments)
  22.                         println("Pairing success, Connected to $deviceName")
  23.                     }
  24.  
  25.                     override fun onError(
  26.                         errorCode: String?,
  27.                         errorMsg: String?
  28.                     ) {
  29.                         println("Activate error: $errorMsg - $errorCode")
  30.                         methodChannel.invokeMethod("pairingFailed", "$errorMsg - $errorCode")
  31.                     }
  32.                 }
  33.                 )
  34.             val mTuyaActivator =
  35.                 ThingHomeSdk.getActivatorInstance().newActivator(builder)
  36.             //Start configuration
  37.             mTuyaActivator?.start()
  38.         } catch (e: Exception) {
  39.             println("pairApMode_Error: $e")
  40.         }
  41.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement