bluetooth infinite scan
This commit is contained in:
1 parent
f79976a350
commit
ca77734039
6 files changed
+45
-20
No files matched your search
+3
-3
@@ -100,7 +100,7 @@ static void gap_callback_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_pa
|
||||
{
|
||||
case ESP_GAP_BLE_SCAN_PARAM_SET_COMPLETE_EVT:
|
||||
// restart scan
|
||||
status = esp_ble_gap_start_scanning(cfg.blescantime);
|
||||
status = esp_ble_gap_start_scanning(BLESCANTIME);
|
||||
if (status != ESP_OK)
|
||||
{
|
||||
ESP_LOGE(TAG, "esp_ble_gap_start_scanning: rc=%d", status);
|
||||
@@ -111,7 +111,7 @@ static void gap_callback_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_pa
|
||||
// evaluate scan results
|
||||
if ( p->scan_rst.search_evt == ESP_GAP_SEARCH_INQ_CMPL_EVT) // Inquiry complete, scan is done
|
||||
{ // restart scan
|
||||
status = esp_ble_gap_start_scanning (cfg.blescantime);
|
||||
status = esp_ble_gap_start_scanning (BLESCANTIME);
|
||||
if (status != ESP_OK)
|
||||
{
|
||||
ESP_LOGE(TAG, "esp_ble_gap_start_scanning: rc=%d", status);
|
||||
@@ -207,7 +207,7 @@ esp_err_t register_ble_functionality(void)
|
||||
#else
|
||||
.scan_filter_policy = BLE_SCAN_FILTER_ALLOW_ALL,
|
||||
#endif
|
||||
.scan_interval = (uint16_t) (BLESCANINTERVAL / 0.625), // Time = N * 0.625 msec
|
||||
.scan_interval = (uint16_t) (cfg.blescantime * 10 / 0.625), // Time = N * 0.625 msec
|
||||
.scan_window = (uint16_t) (BLESCANWINDOW / 0.625) // Time = N * 0.625 msec
|
||||
};
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ void defaultConfig() {
|
||||
cfg.rssilimit = 0; // threshold for rssilimiter, negative value!
|
||||
cfg.sendcycle = SEND_SECS; // payload send cycle [seconds/2]
|
||||
cfg.wifichancycle = WIFI_CHANNEL_SWITCH_INTERVAL; // wifi channel switch cycle [seconds/100]
|
||||
cfg.blescantime = BLESCANTIME; // BLE scan cycle duration [seconds]
|
||||
cfg.blescantime = BLESCANINTERVAL / 10; // BT channel scan cycle duration [seconds/100], default 1 (= 10ms)
|
||||
cfg.blescan = 1; // 0=disabled, 1=enabled
|
||||
cfg.wifiant = 0; // 0=internal, 1=external (for LoPy/LoPy4)
|
||||
cfg.vendorfilter = 1; // 0=disabled, 1=enabled
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
|
||||
// program version - note: increment version after modifications to configData_t struct!!
|
||||
#define PROGVERSION "1.3.42" // use max 10 chars here!
|
||||
#define PROGVERSION "1.3.5" // use max 10 chars here!
|
||||
#define PROGNAME "PAXCNT"
|
||||
|
||||
//--- Declarations ---
|
||||
|
||||
+6
-6
@@ -11,18 +11,18 @@
|
||||
|
||||
// BLE scan parameters
|
||||
#define BLESTACKSIZE 8192 // stack size for esp_bt_controller
|
||||
#define BLESCANTIME 11 // [seconds] scan duration, see note below
|
||||
#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
|
||||
|
||||
/* Note: guide for setting bluetooth parameters
|
||||
*
|
||||
* |< Scan Window > |< Scan Window > |< Scan Window > |
|
||||
* |< Scan Interval >|< Scan Interval >|< Scan Interval >|
|
||||
* |< Scan duration >|
|
||||
* |< Scan Window > |< Scan Window > | ... |< Scan Window > |
|
||||
* |< Scan Interval >|< Scan Interval >| ... |< Scan Interval >|
|
||||
* |< Scan duration >|
|
||||
*
|
||||
* Scan duration sets how long scanning should be going on, interrupting a wifi scan cycle.
|
||||
* Scan window sets how much of the interval should be occupied by scanning.
|
||||
* Scan duration sets how long scanning should be going on, before starting a new scan cycle. 0 means infinite (default).
|
||||
* 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.
|
||||
*/
|
||||
|
||||
@@ -9,6 +9,12 @@
|
||||
#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";
|
||||
|
||||
@@ -92,6 +98,25 @@ 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);
|
||||
#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");
|
||||
|
||||
|
||||
#endif
|
||||
};
|
||||
|
||||
void set_countmode(uint8_t val) {
|
||||
|
||||
Reference in new issue
Block a user