diff --git a/src/blecsan.cpp b/src/blecsan.cpp index c838cd12..a708948a 100644 --- a/src/blecsan.cpp +++ b/src/blecsan.cpp @@ -13,6 +13,7 @@ https://github.com/nkolban/esp32-snippets/tree/master/BLE/scanner #include #include #include // needed for BLE_ADDR types, do not remove +#include #define BT_BD_ADDR_HEX(addr) \ addr[0], addr[1], addr[2], addr[3], addr[4], addr[5] @@ -249,6 +250,10 @@ void start_BLEscan(void) { #ifdef BLECOUNTER ESP_LOGI(TAG, "Initializing bluetooth scanner ..."); + ESP_ERROR_CHECK(esp_coex_preference_set( + (esp_coex_prefer_t) + ESP_COEX_PREFER_BALANCE)); // configure Wifi/BT coexist lib + // Initialize BT controller to allocate task and other resource. btStart(); ESP_ERROR_CHECK(esp_bluedroid_init()); @@ -268,6 +273,8 @@ void stop_BLEscan(void) { ESP_ERROR_CHECK(esp_bluedroid_disable()); ESP_ERROR_CHECK(esp_bluedroid_deinit()); btStop(); // disable & deinit bt_controller + ESP_ERROR_CHECK(esp_coex_preference_set(( + esp_coex_prefer_t)ESP_COEX_PREFER_WIFI)); // configure Wifi/BT coexist lib ESP_LOGI(TAG, "Bluetooth scanner stopped"); #endif // BLECOUNTER } // stop_BLEscan diff --git a/src/main.cpp b/src/main.cpp index 90a99992..bd5d9b01 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -149,13 +149,6 @@ void setup() { antenna_select(cfg.wifiant); #endif -// switch off bluetooth, if not compiled -#ifdef BLECOUNTER - strcat_P(features, " BLE"); -#else - bool btstop = btStop(); -#endif - // initialize battery status #ifdef HAS_BATTERY_PROBE strcat_P(features, " BATT"); @@ -173,7 +166,20 @@ void setup() { } #endif - // initialize button +// start BLE scan callback if BLE function is enabled in NVRAM configuration +// or switch off bluetooth, if not compiled +#ifdef BLECOUNTER + strcat_P(features, " BLE"); + if (cfg.blescan) { + ESP_LOGI(TAG, "Starting Bluetooth..."); + start_BLEscan(); + } else + btStop(); +#else + btStop(); +#endif + +// initialize button #ifdef HAS_BUTTON strcat_P(features, " BTN_"); #ifdef BUTTON_PULLUP @@ -291,14 +297,6 @@ void setup() { #endif #endif -// start BLE scan callback if BLE function is enabled in NVRAM configuration -#ifdef BLECOUNTER - if (cfg.blescan) { - ESP_LOGI(TAG, "Starting Bluetooth..."); - start_BLEscan(); - } -#endif - // start wifi in monitor mode and start channel rotation task on core 0 ESP_LOGI(TAG, "Starting Wifi..."); wifi_sniffer_init(); diff --git a/src/wifiscan.cpp b/src/wifiscan.cpp index 14332b49..80f159c3 100644 --- a/src/wifiscan.cpp +++ b/src/wifiscan.cpp @@ -10,8 +10,6 @@ static wifi_country_t wifi_country = {WIFI_MY_COUNTRY, WIFI_CHANNEL_MIN, WIFI_CHANNEL_MAX, 100, WIFI_COUNTRY_POLICY_MANUAL}; -esp_coex_prefer_t esp_coexist_config = ESP_COEX_PREFER_BALANCE; - typedef struct { unsigned frame_ctrl : 16; unsigned duration_id : 16; @@ -52,10 +50,8 @@ void wifi_sniffer_init(void) { // .filter_mask = WIFI_PROMIS_FILTER_MASK_MGMT}; // only MGMT frames .filter_mask = WIFI_PROMIS_FILTER_MASK_ALL}; // we use all frames - //coex_pause(); ESP_ERROR_CHECK( - esp_coex_preference_set(esp_coexist_config)); // configure Wifi/BT coexist lib - //coex_resume(); + esp_coex_preference_set((esp_coex_prefer_t) ESP_COEX_PREFER_WIFI)); // configure Wifi/BT coexist lib ESP_ERROR_CHECK(esp_wifi_init(&cfg)); // configure Wifi with cfg ESP_ERROR_CHECK(