Scan on service UUID instead of device name (issue #10)
All checks were successful
CI / firmware (pull_request) Successful in 1m16s
CI / android (pull_request) Successful in 5s

- Replace name-based scan filter (getName() == 'SylDa_Server') with
  isAdvertisingService(SERVICE_UUID) to prevent BLE name spoofing
- Post-connect UUID verification via UUID_CHAR_UUID was already in place
- Update log messages to reflect service-UUID-based scanning
This commit is contained in:
eddy 2026-08-02 21:27:19 +02:00
commit 7bdd50b16e

View file

@ -62,7 +62,7 @@ static NimBLEAddress serverAddress;
class MyScanCallbacks : public NimBLEScanCallbacks { class MyScanCallbacks : public NimBLEScanCallbacks {
void onResult(const NimBLEAdvertisedDevice *advertisedDevice) override { void onResult(const NimBLEAdvertisedDevice *advertisedDevice) override {
if (advertisedDevice->haveName() && advertisedDevice->getName() == "SylDa_Server") { if (advertisedDevice->isAdvertisingService(NimBLEUUID(SERVICE_UUID))) {
serverAddress = advertisedDevice->getAddress(); serverAddress = advertisedDevice->getAddress();
serverFound = true; serverFound = true;
NimBLEDevice::getScan()->stop(); NimBLEDevice::getScan()->stop();
@ -234,7 +234,7 @@ void setup() {
pScan->setActiveScan(false); pScan->setActiveScan(false);
pScan->setMaxResults(0); pScan->setMaxResults(0);
bleReady = true; bleReady = true;
ESP_LOGI(TAG, "BLE: initialized, will scan for SylDa_Server"); ESP_LOGI(TAG, "BLE: initialized, scanning for service UUID");
} }
ESP_LOGI(TAG, "Setup done."); ESP_LOGI(TAG, "Setup done.");
@ -443,7 +443,7 @@ void loop() {
if (!pScan->isScanning() && scanRunnable) { if (!pScan->isScanning() && scanRunnable) {
scanRunnable = false; scanRunnable = false;
if (serverFound) { if (serverFound) {
ESP_LOGI(TAG, "BLE: found SylDa_Server, connecting..."); ESP_LOGI(TAG, "BLE: found server advertising service UUID, connecting...");
connectToServer(); connectToServer();
} }
} }