diff --git a/src/client.cpp b/src/client.cpp index c1ebf5e..b302c20 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -76,10 +76,16 @@ static size_t ecdhNotifyLen = 0; class MyScanCallbacks : public NimBLEScanCallbacks { void onResult(const NimBLEAdvertisedDevice *advertisedDevice) override { - if (advertisedDevice->isAdvertisingService(NimBLEUUID(SERVICE_UUID))) { - serverAddress = advertisedDevice->getAddress(); - serverFound = true; - NimBLEDevice::getScan()->stop(); + if (scanning && advertisedDevice->isAdvertisingService(NimBLEUUID(SERVICE_UUID))) { + std::string mfgData = advertisedDevice->getManufacturerData(); + if (mfgData.length() >= 4) { + if (memcmp(mfgData.data(), deviceUuid, 4) == 0) { + serverAddress = advertisedDevice->getAddress(); + serverFound = true; + ESP_LOGI(TAG, "BLE: server found at %s", serverAddress.toString().c_str()); + NimBLEDevice::getScan()->stop(); + } + } } } };