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);
}
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?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
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.