子设备配网

更新时间:2024-05-14 02:42:15下载pdf

App 发送子设备配网指令到云端,云端进而通知网关开始配网子设备。子设备收到配网命令后通过网关向云端注册激活,成功后云端通知 App 添加设备成功。

子设备一般不具备联网能力,需要借助网关来和云端通信,网关通过 Wi-Fi 或者有线网络连云。

开始搜索

val scankey = ThingActivatorCoreKit.getScanDeviceManager().startGatewaySubDeviceSearch(
       gatewayId: String,
    millisTimeOut: Long,
    thingActivatorScanCallback: ThingActivatorScanCallback
)

参数说明

参数 说明
gwId 网关 ID
millisTimeOut 超时时间,单位为毫秒(ms)
thingActivatorScanCallback 搜索超时回调

停止搜索

ThingActivatorCoreKit.getScanDeviceManager().stopScan(scankey)

开始配网

方法一:使用搜索结果配网

val builder = ThingDeviceActiveBuilder()
            .setActiveModel(ThingDeviceActiveModeEnum.SUB)
            .setSubSearchBeans(thingActivatorScanDeviceBeans)
            .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)

参数说明

参数 说明
subSearchBeans 扫描到的设备实体列表
timeout 超时时长,单位为秒(s)
activeModel 配网能力枚举
listener 配网结果回调

方法二:子设备直接配网

val builder = ThingDeviceActiveBuilder()
            .setActiveModel(ThingDeviceActiveModeEnum.SUB)
            .setTimeOut(120)
            .setGwId(mScanBuilder.gwId)
            .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)

参数说明

参数 说明
gwid 网关 ID
timeout 超时时长,单位为秒(s)
activeModel 配网能力枚举
listener 配网结果回调

停止配网

mThingActivatorManager.stopActive()