BLE low power mode and settings optimization (#902)

* BLE low power mode and settings optimization
-low power mode settings example
-take into account parameters following #891
-add esp32dev-ble-cont for door/window sensor listening

* Disable WDT during scan

* update esp32 arduino framework
This commit is contained in:
Florian authored and GitHub committed 2021-03-25 18:53:47 -05:00
1 parent 863a56b389
commit b9151bb6ac
3 files changed
+47 -7

No files matched your search

+6 -5
View File
@@ -617,19 +617,20 @@ class MyAdvertisedDeviceCallbacks : public BLEAdvertisedDeviceCallbacks {
* BLEscan used to retrieve BLE advertized data from devices without connection
*/
void BLEscan() {
TIMERG0.wdt_wprotect = TIMG_WDT_WKEY_VALUE;
TIMERG0.wdt_feed = 1;
TIMERG0.wdt_wprotect = 0;
disableCore0WDT();
Log.notice(F("Scan begin" CR));
BLEDevice::init("");
BLEScan* pBLEScan = BLEDevice::getScan(); //create new scan
BLEScan* pBLEScan = BLEDevice::getScan();
MyAdvertisedDeviceCallbacks myCallbacks;
pBLEScan->setAdvertisedDeviceCallbacks(&myCallbacks);
pBLEScan->setActiveScan(true); //active scan uses more power, but get results faster
pBLEScan->setActiveScan(ActiveBLEScan);
pBLEScan->setInterval(BLEScanInterval);
pBLEScan->setWindow(BLEScanWindow);
BLEScanResults foundDevices = pBLEScan->start(Scan_duration / 1000, false);
scanCount++;
Log.notice(F("Found %d devices, scan number %d end deinit controller" CR), foundDevices.getCount(), scanCount);
BLEDevice::deinit(true);
enableCore0WDT();
}
/**
+10 -1
View File
@@ -48,7 +48,16 @@ bool bleConnect = AttemptBLECOnnect;
#define MinimumRSSI -100 //default minimum rssi value, all the devices below -90 will not be reported
#ifndef Scan_duration
# define Scan_duration 10000 //define the time for a scan --WARNING-- changing this value can lead to instability on ESP32
# define Scan_duration 10000 //define the time for a scan
#endif
#ifndef BLEScanInterval
# define BLEScanInterval 52 // How often the scan occurs / switches channels; in milliseconds,
#endif
#ifndef BLEScanWindow
# define BLEScanWindow 30 // How long to scan during the interval; in milliseconds.
#endif
#ifndef ActiveBLEScan
# define ActiveBLEScan true // Set active scanning, this will get more data from the advertiser.
#endif
#ifndef ScanBeforeConnect
# define ScanBeforeConnect 10 //define number of scans before connecting to BLE devices (ESP32 only, minimum 1)
+31 -1
View File
@@ -40,6 +40,7 @@ extra_configs =
;default_envs = esp32dev-weatherstation
;default_envs = esp32dev-ir
;default_envs = esp32dev-ble
;default_envs = esp32dev-ble-cont
;default_envs = esp32feather-ble
;default_envs = esp32-lolin32lite-ble
;default_envs = esp32-olimex-gtw-ble-eth
@@ -135,7 +136,7 @@ monitor_speed = 115200
[com]
esp8266_platform = espressif8266@2.6.3
esp32_platform = espressif32@3.0.0
esp32_platform = espressif32@3.1.1
atmelavr_platform = atmelavr@3.2.0
[com-esp]
@@ -338,6 +339,23 @@ build_flags =
'-DLED_RECEIVE_ON=0'
'-DGateway_Name="OpenMQTTGateway_ESP32_BLE"'
[env:esp32dev-ble-cont]
platform = ${com.esp32_platform}
board = esp32dev
board_build.partitions = min_spiffs.csv
lib_deps =
${com-esp.lib_deps}
${libraries.ble}
build_flags =
${com-esp.build_flags}
'-DZgatewayBT="BT"'
'-DLED_RECEIVE=2'
'-DLED_RECEIVE_ON=0'
'-DGateway_Name="OpenMQTTGateway_ESP32_BLE_C"'
'-DTimeBtwRead=0'
'-DScan_duration=1000'
'-DAttemptBLECOnnect=false'
[env:esp32feather-ble]
platform = ${com.esp32_platform}
board = featheresp32
@@ -365,6 +383,17 @@ build_flags =
'-DLED_RECEIVE=22'
'-DLED_RECEIVE_ON=0'
'-DGateway_Name="OpenMQTTGateway_LOLIN32LITE_BLE"'
;; Low power parameters, uncomment and fill credentials
; '-DDEFAULT_LOW_POWER_MODE=0'
; '-DTimeBtwRead=550000'
; '-DAttemptBLECOnnect=false'
; '-DActiveBLEScan=false'
; '-DESPWifiManualSetup=true'
; '-DMQTT_USER="lolin-esp32"'
; '-DMQTT_PASS="your_password"'
; '-DMQTT_SERVER="192.168.1.17"'
; '-Dwifi_ssid="WIFI_SSID"'
; '-Dwifi_password="WIFI_PASSWORD"'
[env:esp32-olimex-gtw-ble-eth]
platform = ${com.esp32_platform}
@@ -535,6 +564,7 @@ build_flags =
# https://www.thethingsnetwork.org/forum/t/big-esp32-sx127x-topic-part-3/18436
platform = ${com.esp32_platform}
board = ttgo-t-beam
board_build.partitions = min_spiffs.csv
lib_deps =
${com-esp.lib_deps}
${libraries.ble}