蓝牙设备配网

更新时间:2024-05-14 02:47:12下载pdf

蓝牙设备配网包含蓝牙设备搜索和配网,其中蓝牙设备包含蓝牙单点、蓝牙 Mesh、双模设备、beacon 等类型。

蓝牙类型

蓝牙类型 说明 设备应用示例
蓝牙单点 蓝牙设备与手机一对一连接单点设备(蓝牙或低功耗蓝牙) 体脂秤、手环、温控器、电动牙刷、门锁等
蓝牙 Mesh 蓝牙技术联盟发布的蓝牙拓扑通信 一路、二路、五路等灯泡、插座、传感器等子设备
双模设备 一些多协议设备也会使用到蓝牙技术,例如同时具备 Wi-Fi 能力和蓝牙能力的 双模设备 蓝牙 Mesh 网关、IPC 设备、新版多协议 Wi-Fi 设备等
蓝牙 Beacon 蓝牙 Beacon 是建立在低功耗蓝牙协议基础上的一种广播协议 灯、风扇、遥控器、体脂秤等设备

开始搜索

val scanKey = ThingActivatorCoreKit.getScanDeviceManager().startBlueToothDeviceSearch(
        millisTimeOut: Long,
        scanTypeList: List<ScanType>,
        thingActivatorScanCallback: ThingActivatorScanCallback
    )

参数说明

参数 说明
scanTypeList
  • SINGLE
  • MESH
  • SIG_MESH
  • SINGLE_QR
  • THING_BEACON
millisTimeOut 超时时间,单位为毫秒(ms)
thingActivatorScanCallback 搜索超时回调

ScanType 详解

ScanType 枚举 可搜到的设备类型
SINGLE 点对点蓝牙设备:
  • ThingDeviceBlueActiveTypeEnum.SINGLE_BLE
  • ThingDeviceBlueActiveTypeEnum.BLE_WIFI
  • ThingDeviceBlueActiveTypeEnum.MULT_MODE
SIG_MESH 蓝牙 Mesh 设备:ThingDeviceBlueActiveTypeEnum.SIGMESH_SUB
THING_BEACON 蓝牙 Beacon 设备:ThingDeviceBlueActiveTypeEnum.BEACON

停止搜索

ThingActivatorCoreKit.getScanDeviceManager().stopScan()

开始配网

SINGLE_BLE

val builder = ThingDeviceActiveBuilder()
        builder.thingActivatorScanDeviceBean = thingActivatorScanDeviceBean
        builder.timeout = 120L
        builder.relationId = relationId
        builder.activeModel = ThingDeviceActiveModeEnum.SINGLE_BLE
        builder.listener = object : IThingDeviceActiveListener {
            override fun onActiveError(errorBean: ThingDeviceActiveErrorBean) {

            }

            override fun onActiveLimited(limitBean: ThingDeviceActiveLimitBean) {

            }

            override fun onActiveSuccess(deviceBean: DeviceBean) {

            }

            override fun onBind(devId: String) {

            }

            override fun onFind(devId: String) {

            }

        }

val activeManager = ThingActivatorCoreKit.getActiveManager().newThingActiveManager()
activeManager.startActive(builder)

参数说明

参数 说明
thingActivatorScanDeviceBean 搜索到的对应设备
relationId 家庭维度 ID
timeout 配网超时时长,单位为秒(s)
activeModel 配网能力枚举
listener 配网结果回调

BLE_WIFI 和 MULT_MODE

val builder = ThingDeviceActiveBuilder()
        builder.thingActivatorScanDeviceBean = thingActivatorScanDeviceBean
        builder.timeout = 120L
        builder.relationId = relationId
        builder.ssid = ssid
        builder.password = password
        builder.activeModel = ThingDeviceActiveModeEnum.BLE_WIFI
        builder.listener = 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 activeManager = ThingActivatorCoreKit.getActiveManager().newThingActiveManager()
activeManager.startActive(builder)

参数说明

参数 说明
thingActivatorScanDeviceBean 搜索到的对应设备
relationId 家庭维度 ID
ssid Wi-Fi 名称
password Wi-Fi 密码
timeout 配网超时时长,单位为秒(s)
activeModel 配网能力枚举
listener 配网结果回调
  • 如果您不需要监听 onActivatorStatePauseCallback 逻辑,可以使用原有的 IThingDeviceActiveListener 接口即可。
  • onActivatorStatePauseCallback 是用来得到双模设备配网暂停状态,会返回对应密码错误或者连接路由器失败。您可以重新扫描 Wi-Fi 列表并选择。再次调用 resumeActive 方法继续配网该蓝牙设备。

恢复配网

部分新蓝牙双模设备会通过 onActivatorStatePauseCallback 方法返回 Wi-Fi 密码错误,以及路由器连接失败等信息。您可以用过该方法后,调用 ThingResumeActiveBuilder 继续设备配网。

val builder = ThingResumeActiveBuilder(uuid)

activeManager.resumeActive(builder)

参数说明

resumeType 枚举 说明
RESUME_TYPE_WIFI 继续 Wi-Fi 配网
RESUME_TYPE_BLE 蓝色兜底配网

SIGMESH_SUB

val builder = ThingDeviceActiveBuilder()
        builder.meshSearchBeans = meshSearchBeanList
        builder.timeout = 120L
        builder.relationId = relationId
        builder.currentMeshBean = currentMeshBean
        builder.activeModel = ThingDeviceActiveModeEnum.SIGMESH_SUB
        builder.listener = object : IThingDeviceActiveListener {
            override fun onActiveError(errorBean: ThingDeviceActiveErrorBean) {

            }

            override fun onActiveLimited(limitBean: ThingDeviceActiveLimitBean) {

            }

            override fun onActiveSuccess(deviceBean: DeviceBean) {

            }

            override fun onBind(devId: String) {

            }

            override fun onFind(devId: String) {

            }

        }

val activeManager = ThingActivatorCoreKit.getActiveManager().newThingActiveManager()
activeManager.startActive(builder)

参数说明

参数 说明
meshSearchBeans 搜索到的对应设备列表
relationId 家庭维度 ID
timeout 配网超时时长,单位为秒(s)
activeModel 配网能力枚举
currentMeshBean 当前蓝牙 Mesh 网络
listener 配网结果回调

关于蓝牙 Mesh 网络的更多信息,查看 初始化蓝牙 Mesh 网络

BEACON

val builder = ThingDeviceActiveBuilder()
        builder.meshSearchBeans = meshSearchBeanList
        builder.timeout = 120L
        builder.relationId = relationId
        builder.activeModel = ThingDeviceActiveModeEnum.BEACON
        builder.listener = object : IThingDeviceActiveListener {
            override fun onActiveError(errorBean: ThingDeviceActiveErrorBean) {

            }

            override fun onActiveLimited(limitBean: ThingDeviceActiveLimitBean) {

            }

            override fun onActiveSuccess(deviceBean: DeviceBean) {

            }

            override fun onBind(devId: String) {

            }

            override fun onFind(devId: String) {

            }

        }

val activeManager = ThingActivatorCoreKit.getActiveManager().newThingActiveManager()

activeManager.startActive(builder)

activeManager.stopActive()

activeManager.stop(thingActivatorScanDeviceBean.uniqueId)

参数说明

参数 说明
meshSearchBeans 搜索到的对应设备列表
relationId 家庭维度 ID
timeout 配网超时时长,单位为秒(s)
activeModel 配网能力枚举
listener 配网结果回调

停止配网

activeManager.stopActive()