Skip to content

Commit 7249646

Browse files
author
archurtan
committed
修复集贤蓝牙辅助配网失败的问题
Change-Id: I1c8595352110ec33e6aea623ab19bb998cb5ebe7
1 parent 4f0e5f1 commit 7249646

File tree

2 files changed

+16
-10
lines changed
  • app/src/main/java/com/tencent/iot/explorer/link/mvp/model

2 files changed

+16
-10
lines changed

app/src/main/java/com/tencent/iot/explorer/link/mvp/model/ConnectModel.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ class ConnectModel(view: ConnectView) : ParentModel<ConnectView>(view), MyCallba
158158
return@launch // 设置成功则直接退出
159159
}
160160
}
161-
bleFailed("request device info failed")
161+
bleFailed("set wifi mode failed")
162162
}
163163
}
164164

sdk/explorer-link-android/src/main/java/com/tencent/iot/explorer/link/core/link/service/BleConfigService.kt

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import android.bluetooth.le.ScanSettings
88
import android.content.Context
99
import android.os.Build
1010
import android.text.TextUtils
11-
import android.util.Log
1211
import androidx.annotation.RequiresApi
1312
import com.alibaba.fastjson.JSON
1413
import com.tencent.iot.explorer.link.core.link.entity.*
@@ -24,6 +23,7 @@ import kotlin.collections.ArrayList
2423
import kotlin.collections.HashMap
2524
import kotlin.experimental.xor
2625

26+
2727
class BleConfigService private constructor() {
2828

2929
private val TAG = this.javaClass.simpleName
@@ -370,7 +370,9 @@ class BleConfigService private constructor() {
370370
}
371371
override fun onCharacteristicWrite(gatt: BluetoothGatt?, characteristic: BluetoothGattCharacteristic?, status: Int) {}
372372
override fun onCharacteristicRead(gatt: BluetoothGatt?, characteristic: BluetoothGattCharacteristic?, status: Int) {}
373-
override fun onServicesDiscovered(gatt: BluetoothGatt?, status: Int) {}
373+
override fun onServicesDiscovered(gatt: BluetoothGatt?, status: Int) {
374+
enableCharacteristicNotificationWithUUid(gatt, "FFF0")
375+
}
374376
override fun onMtuChanged(gatt: BluetoothGatt?, mtu: Int, status: Int) {
375377
connetionListener?.onMtuChanged(mtu, status)
376378
}
@@ -408,11 +410,21 @@ class BleConfigService private constructor() {
408410
if (service.uuid.toString().substring(4, 8).toUpperCase().equals(serviceUuid)) {
409411
for (characteristic in service.characteristics) {
410412
if (characteristic.uuid.toString().substring(4, 8).toUpperCase().equals("FFE3")) {
411-
return connection.setCharacteristicNotification(characteristic, true)
413+
val success = connection.setCharacteristicNotification(characteristic, true)
414+
if (success) {
415+
val descriptorList = characteristic.descriptors
416+
if (descriptorList != null && descriptorList.size > 0) {
417+
for (descriptor in descriptorList) {
418+
descriptor.value = BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE
419+
connection.writeDescriptor(descriptor)
420+
}
421+
}
422+
}
412423
}
413424
}
414425
}
415426
}
427+
return true
416428
}
417429
return false
418430
}
@@ -460,12 +472,10 @@ class BleConfigService private constructor() {
460472
}
461473

462474
fun requestConnectWifi(connection: BluetoothGatt?): Boolean {
463-
if (!enableCharacteristicNotification(connection)) return false
464475
return setCharacteristicValue(connection, ByteArray(1){0xE3.toByte()})
465476
}
466477

467478
fun requestDevInfo(connection: BluetoothGatt?): Boolean {
468-
if (!enableCharacteristicNotification(connection)) return false
469479
currentConnectBleDevice?.let {
470480
if (it.type == 1) {
471481
L.e("纯蓝牙协议流程中,不支持调用该接口")
@@ -476,22 +486,18 @@ class BleConfigService private constructor() {
476486
}
477487

478488
fun setWifiMode(connection: BluetoothGatt?, mode: BleDeviceWifiMode): Boolean {
479-
if (!enableCharacteristicNotification(connection)) return false
480489
var byteArr = ByteArray(2)
481490
byteArr[0] = 0xE1.toByte()
482491
byteArr[1] = mode.getValue()
483492
return setCharacteristicValue(connection, byteArr)
484493
}
485494

486495
fun sendWifiInfo(connection: BluetoothGatt?, bleDeviceWifiInfo: BleDeviceWifiInfo): Boolean {
487-
if (!enableCharacteristicNotification(connection)) return false
488496
return setCharacteristicValue(connection, bleDeviceWifiInfo.formatByteArr())
489497
}
490498

491499
fun configToken(connection: BluetoothGatt?, token: String): Boolean {
492500
if (TextUtils.isEmpty(token)) return false
493-
if (!enableCharacteristicNotification(connection)) return false
494-
495501
var byteArr = ByteArray(3 + token.toByteArray().size)
496502
byteArr[0] = 0xE4.toByte()
497503
byteArr[1] = (token.toByteArray().size / Math.pow(2.0, 8.0).toInt()).toByte()

0 commit comments

Comments
 (0)