diff --git a/README.md b/README.md index ebb259b5..255dbd8e 100644 --- a/README.md +++ b/README.md @@ -148,27 +148,27 @@ Note: all settings are stored in NVRAM and will be reloaded when device starts. 1 = reset MAC counter to zero 2 = reset device to factory settings -0x0A set payload send cycle +0x0A set LoRaWAN payload send cycle 0 ... 255 payload send cycle in seconds/2 e.g. 120 -> payload is transmitted each 240 seconds [default] 0x0B set Wifi channel switch interval timer - 0 ... 255 timeout for scanning 1 wifi channel in seconds/100 + 0 ... 255 duration for scanning one wifi channel in seconds/100 e.g. 50 -> each channel is scanned for 0,5 seconds [default] -0x0C set BLE scan cycle timer +0x0C set Bluetooth channel switch interval timer - 0 ... 255 duration of a BLE scan cycle in seconds - e.g. 11 -> 1 cycle runs for 11 seconds [default] + 0 ... 255 duration for scanning one bluetooth channel in seconds/100 + e.g. 1 -> each channel is scanned for 10 milliseconds [default] 0x0D (NOT YET IMPLEMENTED) set BLE and WIFI vendorfilter mode 0 = disabled (use to count devices, not people) 1 = enabled [default] -0x0E set BLE scan mode +0x0E set Bluetooth scanner 0 = disabled 1 = enabled [default] @@ -194,10 +194,10 @@ device answers with it's current configuration. The configuration is a C structu byte 5: Display status (1=on, 0=off) byte 6: Counter mode (0=cyclic unconfirmed, 1=cumulative, 2=cyclic confirmed) bytes 7-8: RSSI limiter threshold value (negative) - byte 9: Payload send cycle in seconds/2 (0..255) + byte 9: Lora Payload send cycle in seconds/2 (0..255) byte 10: Wifi channel switch interval in seconds/100 (0..255) - byte 11: BLE scan cycle duration in seconds (0..255) - byte 12: BLE scan mode (1=on, 0=0ff) + byte 11: Bluetooth channel switch interval in seconds/100 (0..255) + byte 12: Bluetooth scanner status (1=on, 0=0ff) byte 13: Wifi antenna switch (0=internal, 1=external) byte 14: Vendorfilter mode (0=disabled, 1=enabled) byte 15: RGB LED luminosity (0..100 %) diff --git a/src/blecsan.cpp b/src/blecsan.cpp index 41678a2f..fdc96630 100644 --- a/src/blecsan.cpp +++ b/src/blecsan.cpp @@ -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 }; diff --git a/src/configmanager.cpp b/src/configmanager.cpp index 74c26206..808af4b6 100644 --- a/src/configmanager.cpp +++ b/src/configmanager.cpp @@ -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 diff --git a/src/main.h b/src/main.h index b9556935..f8047656 100644 --- a/src/main.h +++ b/src/main.h @@ -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 --- diff --git a/src/paxcounter.conf b/src/paxcounter.conf index 8ab4da35..4cfb4a4a 100644 --- a/src/paxcounter.conf +++ b/src/paxcounter.conf @@ -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. */ diff --git a/src/rcommand.cpp b/src/rcommand.cpp index 95ccee33..9cc533c0 100644 --- a/src/rcommand.cpp +++ b/src/rcommand.cpp @@ -9,6 +9,12 @@ #include #include +// Bluetooth specific includes +#ifdef BLECOUNTER + #include // 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) {