fix: BLE scan match use indexOf instead of exact equals

Fixes timeout during binding when targetDeviceId is set but exact
string match fails due to encoding differences. Also skips devices
with no name, and logs match result for every candidate.
这个提交包含在:
Guoguo
2026-06-05 22:38:07 -07:00
父节点 e4d11d30a8
当前提交 5bce7060ac
+3 -2
查看文件
@@ -255,10 +255,11 @@ function startScan(callbacks) {
var d = devices[i]
var name = (d.name || '').toUpperCase()
var localName = (d.localName || '').toUpperCase()
if (!name && !localName) continue
console.log('[BLE] 发现设备:', d.name, '| localName:', d.localName, '| deviceId:', d.deviceId)
var matched = false
if (targetName) {
matched = name === targetName || localName === targetName
matched = name.indexOf(targetName) !== -1 || localName.indexOf(targetName) !== -1
} else {
matched = localName.indexOf('JW_') !== -1 ||
name.indexOf('JW_') !== -1 ||
@@ -266,8 +267,8 @@ function startScan(callbacks) {
name.indexOf('LIGHTMASK') !== -1 || localName.indexOf('LIGHTMASK') !== -1 ||
name.indexOf('SIMPLE PERIPHERAL') !== -1 || localName.indexOf('SIMPLE PERIPHERAL') !== -1
}
console.log('[BLE] 匹配结果:', matched, targetName ? '(精确:' + targetName + ')' : '(模糊)')
if (matched) {
console.log('[BLE] 匹配成功:', d.name, '| localName:', d.localName, targetName ? '(精确匹配)' : '(模糊匹配)')
wx.stopBluetoothDevicesDiscovery({})
if (callbacks.onFound) callbacks.onFound(d)
connect(d.deviceId, callbacks)