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
|
|
@ -445,10 +445,16 @@ void setup() {
|
|||
|
||||
NimBLEAdvertising *pAdvertising = NimBLEDevice::getAdvertising();
|
||||
pAdvertising->setName("SylDa_Server");
|
||||
pAdvertising->addServiceUUID(SERVICE_UUID);
|
||||
|
||||
NimBLEAdvertisementData scanResp;
|
||||
scanResp.setCompleteServices(NimBLEUUID(SERVICE_UUID));
|
||||
|
||||
uint8_t mfgPayload[6];
|
||||
mfgPayload[0] = 0xFF;
|
||||
mfgPayload[1] = 0xFF;
|
||||
memcpy(mfgPayload + 2, deviceUuid, 4);
|
||||
scanResp.setManufacturerData(std::string((char*)mfgPayload, 6));
|
||||
|
||||
pAdvertising->setScanResponseData(scanResp);
|
||||
pAdvertising->enableScanResponse(true);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue