Bluetooth init ode changes
This commit is contained in:
parent
47579414ac
commit
664d58bb4f
@ -13,6 +13,7 @@ https://github.com/nkolban/esp32-snippets/tree/master/BLE/scanner
|
||||
#include <esp_bt_main.h>
|
||||
#include <esp_gap_ble_api.h>
|
||||
#include <esp_blufi_api.h> // needed for BLE_ADDR types, do not remove
|
||||
#include <esp_coexist.h>
|
||||
|
||||
#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
|
||||
|
30
src/main.cpp
30
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();
|
||||
|
@ -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(
|
||||
|
Loading…
Reference in New Issue
Block a user