From f9f04494faf6f7e526dbdd5e7c2fb6279b8f924b Mon Sep 17 00:00:00 2001 From: 1technophile Date: Sat, 17 Feb 2018 08:28:19 +0100 Subject: [PATCH] don't recreate callback at each scan to avoid memory consumption #173 --- ZgatewayBT.ino | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/ZgatewayBT.ino b/ZgatewayBT.ino index ea96abb..3b72c2b 100644 --- a/ZgatewayBT.ino +++ b/ZgatewayBT.ino @@ -103,7 +103,7 @@ Thanks to wolass https://github.com/wolass for suggesting me HM 10 and dinosd ht mac_adress.toCharArray(mac,mac_adress.length()+1); boolean result = process_miflora_data(-22,service_data,mac); } - } + } } }; @@ -117,7 +117,8 @@ Thanks to wolass https://github.com/wolass for suggesting me HM 10 and dinosd ht 1, /* Priority of the task */ NULL, /* Task handle. */ 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 ){ @@ -128,9 +129,9 @@ Thanks to wolass https://github.com/wolass for suggesting me HM 10 and dinosd ht while(true){ trc(taskMessage); delay(TimeBtw_Read); - BLEDevice::init(""); 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 BLEScanResults foundDevices = pBLEScan->start(Scan_duration); }