BLE scan only gets the name of some devices the first scan?

PeterAndersson
Posts: 2
Joined: Mon Jun 03, 2019 8:42 pm

BLE scan only gets the name of some devices the first scan?

Postby PeterAndersson » Sat Jan 25, 2020 3:21 pm

I have the following code:

Code: Select all

    #include <Arduino.h>
    #include <BLEDevice.h>
    #include <BLEAdvertisedDevice.h>
    
    static void log(String message)
    {
      Serial.println(message);
    }
    
    const char* deviceName = "BLEScanner";
    BLEScan* pBLEScan;
    
    void setup() {
      Serial.begin(115200);
    
      log("Setup!");
    
      BLEDevice::init(deviceName);
      pBLEScan = BLEDevice::getScan(); //create new scan
      pBLEScan->setActiveScan(true); //active scan uses more power, but get results faster
      pBLEScan->setInterval(100);
      pBLEScan->setWindow(99);  // less or equal setInterval value
    
    }
    
    void loop() {
      log("Listing BLE Sensors");
      BLEScanResults foundSensors = pBLEScan->start(30, false);
      int count = foundSensors.getCount();
      for (int i = 0; i < count; i++) {
        BLEAdvertisedDevice bleSensor = foundSensors.getDevice(i);
        String sensorName = bleSensor.getName().c_str();
        String address = bleSensor.getAddress().toString().c_str();
    
        log("Find" + address + " " + sensorName);
    
      }
      log("Sleeping");
      sleep(10);
    }
And when I run it I get the following output:
Setup!
Listing BLE Sensors
Find00:09:b0:09:e7:ca
Find41:59:8f:07:ec:96
Findac:5d:5c:e1:72:89 LM0845
Findc4:7c:8d:6a:36:cf Flower care
Findc4:7c:8d:6a:45:6b Flower care
Findc4:7c:8d:6a:46:2c Flower care
Findde:d5:2a:8e:1e:fd Tile
Sleeping
Listing BLE Sensors
Find00:09:b0:09:e7:ca
Find41:59:8f:07:ec:96
Findac:5d:5c:e1:72:89
Findc4:7c:8d:6a:36:cf
Findc4:7c:8d:6a:45:6b
Findc4:7c:8d:6a:46:2c
Findde:d5:2a:8e:1e:fd Tile
Sleeping
Listing BLE Sensors
Find00:09:b0:09:e7:ca
Find41:59:8f:07:ec:96
Findac:5d:5c:e1:72:89
Findc4:7c:8d:6a:36:cf
Findc4:7c:8d:6a:45:6b
Findc4:7c:8d:6a:46:2c
Findde:d5:2a:8e:1e:fd Tile
... and so on
For some reason i only get the names of some of the devices the first time, is this a known error and what can be done about it?

I have tried to put a **pBLEScan->clearResults();** before i start a scan but that did not help..

I have a Adafruit esp32 feather if that helps.

orteip94
Posts: 1
Joined: Wed Apr 08, 2020 4:08 pm

Re: BLE scan only gets the name of some devices the first scan?

Postby orteip94 » Wed Apr 08, 2020 4:15 pm

I have the same problem. I am trying in every way to solve it but I only get the name at the first scan.
the MAC is always visible, but every time I do a scan only the first time
I get the name, the following times NULL.

Code: Select all

void scanArea()
{
  Serial.print("\n#############################################################");
  Serial.print("\n###### My Address MAC BLE: ");
  Serial.print(MyMAC);
  Serial.print("\n#############################################################");
  pBLEScan = BLEDevice::getScan();
  pBLEScan->setActiveScan(true);  
  BLEScanResults results = pBLEScan->start(1); 
  Serial.println("\n-----------------------------Device--------------------------------");
  
  for (int i = 0; i < results.getCount(); i++) 
  {
    Serial.println("\n_______________________________________________________________________");
    BLEAdvertisedDevice device = results.getDevice(i);
    Serial.print("\nDevice Address ");
    Serial.print(i + 1);
    Serial.print(": ");
    MAC = device.getAddress().toString().c_str();
    Serial.print(MAC);
    Serial.print(" | Rssi: ");
    Rssi_device = device.getRSSI();
    Serial.print(Rssi_device);
    Name = device.getName().c_str();
    Serial.print(" | Nome Device: ");
    Serial.print(Name);
    Manufacturer = device.getManufacturerData().c_str();
    Serial.print(" | Manufacturer Device: ");
    Serial.print(Manufacturer);
}
}
This is a BIG PROBLEM FOR ME!

Who is online

Users browsing this forum: No registered users and 31 guests