diff --git a/OpenMQTTGateway.ino b/OpenMQTTGateway.ino index ec025a7..e429302 100644 --- a/OpenMQTTGateway.ino +++ b/OpenMQTTGateway.ino @@ -587,10 +587,10 @@ void loop() } #endif #ifdef ZgatewayBT - #ifndef ESP32 - if(BTtoMQTT()) - trc(F("BTtoMQTT OK")); - #endif + #ifndef multiCore + if(BTtoMQTT()) + trc(F("BTtoMQTT OK")); + #endif #endif #ifdef ZgatewayRFM69 if(RFM69toMQTT()) diff --git a/User_config.h b/User_config.h index 7da9f50..7ee5848 100644 --- a/User_config.h +++ b/User_config.h @@ -175,6 +175,9 @@ const byte subnet[] = { 255, 255, 255, 0 }; //ip adress //variables to avoid duplicates #define time_avoid_duplicate 3000 // if you want to avoid duplicate mqtt message received set this to > 0, the value is the time in milliseconds during which we don't publish duplicates +//uncomment to use multicore function of ESP32 for BLE +//#define multiCore + #define TimeBetweenReadingSYS 30000 // time between system readings (like memory) /*-------------------ACTIVATE TRACES----------------------*/ #define TRACE 1 // 0= trace off 1 = trace on diff --git a/ZgatewayBT.ino b/ZgatewayBT.ino index 4402e7b..50cf28a 100644 --- a/ZgatewayBT.ino +++ b/ZgatewayBT.ino @@ -40,6 +40,9 @@ Thanks to wolass https://github.com/wolass for suggesting me HM 10 and dinosd ht #include #include + //Time used to wait for an interval before resending BLE infos + unsigned long timeBLE= 0; + //core on which the BLE detection task will run static int taskCore = 0; @@ -108,6 +111,7 @@ Thanks to wolass https://github.com/wolass for suggesting me HM 10 and dinosd ht }; void setupBT(){ + #ifdef multiCore // we setup a task with priority one to avoid conflict with other gateways xTaskCreatePinnedToCore( coreTask, /* Function to implement the task */ @@ -117,9 +121,13 @@ 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 multicore ESP32 setup done ")); + #elif + trc(F("ZgatewayBT singlecore ESP32 setup done ")); + #endif } - + + #ifdef multiCore void coreTask( void * pvParameters ){ String taskMessage = "BT Task running on core "; @@ -136,6 +144,22 @@ Thanks to wolass https://github.com/wolass for suggesting me HM 10 and dinosd ht BLEScanResults foundDevices = pBLEScan->start(Scan_duration); } } + #elif + boolean BTtoMQTT(){ + unsigned long now = millis(); + if (now > (timeBLE + TimeBtw_Read)) {//retriving value of temperature and humidity of the box from DHT every xUL + timeBLE = now; + BLEDevice::init(""); + BLEScan* pBLEScan = BLEDevice::getScan(); //create new scan + MyAdvertisedDeviceCallbacks myCallbacks; + pBLEScan->setAdvertisedDeviceCallbacks(&myCallbacks); + pBLEScan->setActiveScan(true); //active scan uses more power, but get results faster + BLEScanResults foundDevices = pBLEScan->start(Scan_duration); + return true; + } + return false; + } + #endif #else // arduino or ESP8266 working with HM10/11 diff --git a/tests/Test_config.h b/tests/Test_config.h index 9d7bdce..7eb874d 100644 --- a/tests/Test_config.h +++ b/tests/Test_config.h @@ -168,6 +168,9 @@ const byte subnet[] = { 255, 255, 255, 0 }; //ip adress //variables to avoid duplicates #define time_avoid_duplicate 3000 // if you want to avoid duplicate mqtt message received set this to > 0, the value is the time in milliseconds during which we don't publish duplicates +//uncomment to use multicore function of ESP32 for BLE +#define multiCore + #define TimeBetweenReadingSYS 30000 // time between system readings (like memory) /*-------------------ACTIVATE TRACES----------------------*/ #define TRACE 1 // 0= trace off 1 = trace on