bluetooth tasking reworked
This commit is contained in:
parent
7800ce9d12
commit
9bdc7291d8
@ -224,11 +224,17 @@ esp_err_t register_ble_functionality(void)
|
||||
return ESP_OK ;
|
||||
}
|
||||
|
||||
void stop_BLEscan(void){
|
||||
ESP_LOGI(TAG, "Shutting BT Down ...");
|
||||
esp_ble_gap_register_callback(NULL);
|
||||
esp_bluedroid_disable();
|
||||
esp_bluedroid_deinit();
|
||||
esp_bt_controller_disable();
|
||||
esp_bt_controller_deinit();
|
||||
}
|
||||
|
||||
// Main start code running in its own Xtask
|
||||
void bt_loop(void * pvParameters)
|
||||
{
|
||||
configASSERT( ( ( uint32_t ) pvParameters ) == 1 ); // FreeRTOS check
|
||||
void start_BLEscan(void){
|
||||
ESP_LOGI(TAG, "Initializing bluetooth scanner ...");
|
||||
|
||||
esp_err_t status;
|
||||
|
||||
@ -277,15 +283,9 @@ void bt_loop(void * pvParameters)
|
||||
goto end;
|
||||
}
|
||||
|
||||
while(1)
|
||||
{
|
||||
vTaskDelay(10/portTICK_PERIOD_MS); // reset watchdog
|
||||
}
|
||||
|
||||
end:
|
||||
ESP_LOGI(TAG, "Terminating BT logging task");
|
||||
vTaskDelete(NULL);
|
||||
ESP_LOGI(TAG, "Bluetooth scanner initialization finished");
|
||||
|
||||
} // bt_loop
|
||||
} // start_BLEscan
|
||||
|
||||
#endif // BLECOUNTER
|
@ -583,17 +583,17 @@ wifi_sniffer_init(); // setup wifi in monitor mode and start MAC counting
|
||||
// note: do this *after* wifi has started, since gets it's seed from RF noise
|
||||
reset_salt(); // get new 16bit for salting hashes
|
||||
|
||||
// run wifi task on core 0 and lora task on core 1 and bt task on core 0
|
||||
// run wifi channel switching task on core 0 and lora lmic task on core 1 (arduino main loop runs on core 1)
|
||||
ESP_LOGI(TAG, "Starting Lora task on core 1");
|
||||
xTaskCreatePinnedToCore(lorawan_loop, "loratask", 2048, ( void * ) 1, ( 5 | portPRIVILEGE_BIT ), NULL, 1);
|
||||
|
||||
ESP_LOGI(TAG, "Starting Wifi task on core 0");
|
||||
xTaskCreatePinnedToCore(sniffer_loop, "wifisniffer", 2048, ( void * ) 1, 1, NULL, 0);
|
||||
|
||||
// start BLE scan callback if BLE function is enabled in NVRAM configuration
|
||||
#ifdef BLECOUNTER
|
||||
if (cfg.blescan) { // start BLE task only if BLE function is enabled in NVRAM configuration
|
||||
ESP_LOGI(TAG, "Starting Bluetooth task on core 0");
|
||||
xTaskCreatePinnedToCore(bt_loop, "btscan", 4096, ( void * ) 1, 1, NULL, 0);
|
||||
if (cfg.blescan) {
|
||||
start_BLEscan();
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -41,4 +41,7 @@ void wifi_sniffer_set_channel(uint8_t channel);
|
||||
void wifi_sniffer_packet_handler(void *buff, wifi_promiscuous_pkt_type_t type);
|
||||
|
||||
// defined in blescan.cpp
|
||||
void bt_loop(void *ignore);
|
||||
#ifdef BLECOUNTER
|
||||
void start_BLEscan(void);
|
||||
void stop_BLEscan(void);
|
||||
#endif
|
@ -7,13 +7,13 @@
|
||||
|
||||
// set this to include BLE counting and vendor filter functions
|
||||
#define VENDORFILTER 1 // comment out if you want to count things, not people
|
||||
#define BLECOUNTER 1 // comment out if you don't want BLE count
|
||||
#define BLECOUNTER 1 // comment out if you don't want BLE count, saves power & memory
|
||||
|
||||
// BLE scan parameters
|
||||
#define BLESTACKSIZE 8192 // stack size for esp_bt_controller
|
||||
#define BLESCANTIME 0 // [seconds] scan duration, 0 means infinite [default], see note below
|
||||
#define BLESCANWINDOW 10 // [milliseconds] scan window, see below, 3 .. 10240, default 10
|
||||
#define BLESCANINTERVAL 10 // [milliseconds] how long to wait between scans, 3 .. 10240, default 10
|
||||
#define BLESCANINTERVAL 10 // [milliseconds] scan interval, see below, 3 .. 10240, default 10
|
||||
|
||||
/* Note: guide for setting bluetooth parameters
|
||||
*
|
||||
@ -25,6 +25,7 @@
|
||||
* Scan window sets how much of the interval should be occupied by scanning. Should be >= BLESCANINTERVAL.
|
||||
* Scan interval is how long scanning should be done on each channel. BLE uses 3 channels for advertising.
|
||||
* -> Adjust these values with power consumption in mind if power is limited.
|
||||
* -> Scan interval can be changed during runtime by remote comammand.
|
||||
*/
|
||||
|
||||
// WiFi scan parameters
|
||||
|
@ -9,12 +9,6 @@
|
||||
#include <lmic.h>
|
||||
#include <hal/hal.h>
|
||||
|
||||
// Bluetooth specific includes
|
||||
#ifdef BLECOUNTER
|
||||
#include <esp_gap_ble_api.h> // needed for switching interval parameter by rcommand
|
||||
esp_err_t register_ble_functionality(void); // defined in blescan.cpp
|
||||
#endif
|
||||
|
||||
// Local logging tag
|
||||
static const char *TAG = "rcommand";
|
||||
|
||||
@ -97,25 +91,14 @@ void set_wifichancycle(uint8_t val) {
|
||||
|
||||
void set_blescantime(uint8_t val) {
|
||||
cfg.blescantime = val;
|
||||
ESP_LOGI(TAG, "Remote command: set BLE scan time to %d seconds", cfg.blescantime);
|
||||
ESP_LOGI(TAG, "Remote command: set BLE scan time to %.1f seconds", cfg.blescantime/float(100));
|
||||
#ifdef BLECOUNTER
|
||||
|
||||
// stop scan
|
||||
ESP_LOGI(TAG, "Stopping BLE scan");
|
||||
if (esp_ble_gap_stop_scanning() != ESP_OK)
|
||||
ESP_LOGE(TAG, "Stopping BLE scan failed");
|
||||
|
||||
// modify parameters
|
||||
ESP_LOGI(TAG, "Re-register BLE functionality");
|
||||
if (register_ble_functionality() != ESP_OK)
|
||||
ESP_LOGE(TAG, "Re-register BLE functionality failed");
|
||||
|
||||
// restart scan
|
||||
ESP_LOGI(TAG, "Restarting BLE scan");
|
||||
if (esp_ble_gap_start_scanning(BLESCANTIME) != ESP_OK)
|
||||
ESP_LOGE(TAG, "Restarting BLE scan failed");
|
||||
|
||||
|
||||
// stop & restart BLE scan task to apply new parameter
|
||||
if (cfg.blescan)
|
||||
{
|
||||
stop_BLEscan();
|
||||
start_BLEscan();
|
||||
}
|
||||
#endif
|
||||
};
|
||||
|
||||
@ -167,14 +150,20 @@ void set_loraadr(uint8_t val) {
|
||||
};
|
||||
|
||||
void set_blescan(uint8_t val) {
|
||||
ESP_LOGI(TAG, "Remote command: set BLE scan mode to %s", val ? "on" : "off");
|
||||
ESP_LOGI(TAG, "Remote command: set BLE scanner to %s", val ? "on" : "off");
|
||||
switch (val) {
|
||||
case 0:
|
||||
cfg.blescan = 0;
|
||||
macs_ble = 0; // clear BLE counter
|
||||
#ifdef BLECOUNTER
|
||||
stop_BLEscan();
|
||||
#endif
|
||||
break;
|
||||
default:
|
||||
cfg.blescan = 1;
|
||||
#ifdef BLECOUNTER
|
||||
start_BLEscan();
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user