Add device UUID prefix to BLE scan response and filter in scan callback
All checks were successful
CI / build (push) Successful in 1m6s
All checks were successful
CI / build (push) Successful in 1m6s
ESP32 server: include 4-byte device UUID prefix as manufacturer data (company 0xFFFF) in BLE scan response, allowing pre-connection filtering. Android: check manufacturer data in ScanCallback.onScanResult before connecting. Skips devices with non-matching UUID prefix, preventing wasted connections to wrong SylDa devices. Backward compatible with old firmware (proceeds if no manufacturer data present).
This commit is contained in:
parent
290ce0a027
commit
3cd4a6211d
3 changed files with 67 additions and 56 deletions
|
|
@ -89,6 +89,19 @@ class BleRelayManager(
|
|||
Log.d(TAG, "Skipping already-tried device $address")
|
||||
return
|
||||
}
|
||||
val scanRecord = result.scanRecord
|
||||
val storedUuid = deviceUuid
|
||||
if (scanRecord != null && storedUuid != null) {
|
||||
val mfgData = scanRecord.getManufacturerSpecificData(0xFFFF)
|
||||
if (mfgData != null && mfgData.size >= 4) {
|
||||
val advPrefix = mfgData.copyOf(4)
|
||||
val storedPrefix = storedUuid.copyOf(4)
|
||||
if (!advPrefix.contentEquals(storedPrefix)) {
|
||||
Log.d(TAG, "Skipping non-matching UUID prefix ($address)")
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
stopScan()
|
||||
connectToDevice(device)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue