don't recreate callback at each scan to avoid memory consumption

#173
This commit is contained in:
1technophile committed 2018-02-17 08:28:19 +01:00
1 parent f9ddb05c65
commit f9f04494fa
1 file changed
+3 -2
+3 -2
View File
@@ -118,6 +118,7 @@ Thanks to wolass https://github.com/wolass for suggesting me HM 10 and dinosd ht
NULL, /* Task handle. */ NULL, /* Task handle. */
taskCore); /* Core where the task should run */ taskCore); /* Core where the task should run */
trc(F("ZgatewayBT ESP32 setup done ")); trc(F("ZgatewayBT ESP32 setup done "));
BLEDevice::init("");
} }
void coreTask( void * pvParameters ){ void coreTask( void * pvParameters ){
@@ -128,9 +129,9 @@ Thanks to wolass https://github.com/wolass for suggesting me HM 10 and dinosd ht
while(true){ while(true){
trc(taskMessage); trc(taskMessage);
delay(TimeBtw_Read); delay(TimeBtw_Read);
BLEDevice::init("");
BLEScan* pBLEScan = BLEDevice::getScan(); //create new scan BLEScan* pBLEScan = BLEDevice::getScan(); //create new scan
pBLEScan->setAdvertisedDeviceCallbacks(new MyAdvertisedDeviceCallbacks()); MyAdvertisedDeviceCallbacks myCallbacks;
pBLEScan->setAdvertisedDeviceCallbacks(&myCallbacks);
pBLEScan->setActiveScan(true); //active scan uses more power, but get results faster pBLEScan->setActiveScan(true); //active scan uses more power, but get results faster
BLEScanResults foundDevices = pBLEScan->start(Scan_duration); BLEScanResults foundDevices = pBLEScan->start(Scan_duration);
} }