bluetooth infinite scan
This commit is contained in:
parent
f79976a350
commit
ca77734039
18
README.md
18
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
|
1 = reset MAC counter to zero
|
||||||
2 = reset device to factory settings
|
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
|
0 ... 255 payload send cycle in seconds/2
|
||||||
e.g. 120 -> payload is transmitted each 240 seconds [default]
|
e.g. 120 -> payload is transmitted each 240 seconds [default]
|
||||||
|
|
||||||
0x0B set Wifi channel switch interval timer
|
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]
|
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
|
0 ... 255 duration for scanning one bluetooth channel in seconds/100
|
||||||
e.g. 11 -> 1 cycle runs for 11 seconds [default]
|
e.g. 1 -> each channel is scanned for 10 milliseconds [default]
|
||||||
|
|
||||||
0x0D (NOT YET IMPLEMENTED) set BLE and WIFI vendorfilter mode
|
0x0D (NOT YET IMPLEMENTED) set BLE and WIFI vendorfilter mode
|
||||||
|
|
||||||
0 = disabled (use to count devices, not people)
|
0 = disabled (use to count devices, not people)
|
||||||
1 = enabled [default]
|
1 = enabled [default]
|
||||||
|
|
||||||
0x0E set BLE scan mode
|
0x0E set Bluetooth scanner
|
||||||
|
|
||||||
0 = disabled
|
0 = disabled
|
||||||
1 = enabled [default]
|
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 5: Display status (1=on, 0=off)
|
||||||
byte 6: Counter mode (0=cyclic unconfirmed, 1=cumulative, 2=cyclic confirmed)
|
byte 6: Counter mode (0=cyclic unconfirmed, 1=cumulative, 2=cyclic confirmed)
|
||||||
bytes 7-8: RSSI limiter threshold value (negative)
|
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 10: Wifi channel switch interval in seconds/100 (0..255)
|
||||||
byte 11: BLE scan cycle duration in seconds (0..255)
|
byte 11: Bluetooth channel switch interval in seconds/100 (0..255)
|
||||||
byte 12: BLE scan mode (1=on, 0=0ff)
|
byte 12: Bluetooth scanner status (1=on, 0=0ff)
|
||||||
byte 13: Wifi antenna switch (0=internal, 1=external)
|
byte 13: Wifi antenna switch (0=internal, 1=external)
|
||||||
byte 14: Vendorfilter mode (0=disabled, 1=enabled)
|
byte 14: Vendorfilter mode (0=disabled, 1=enabled)
|
||||||
byte 15: RGB LED luminosity (0..100 %)
|
byte 15: RGB LED luminosity (0..100 %)
|
||||||
|
@ -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:
|
case ESP_GAP_BLE_SCAN_PARAM_SET_COMPLETE_EVT:
|
||||||
// restart scan
|
// restart scan
|
||||||
status = esp_ble_gap_start_scanning(cfg.blescantime);
|
status = esp_ble_gap_start_scanning(BLESCANTIME);
|
||||||
if (status != ESP_OK)
|
if (status != ESP_OK)
|
||||||
{
|
{
|
||||||
ESP_LOGE(TAG, "esp_ble_gap_start_scanning: rc=%d", status);
|
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
|
// evaluate scan results
|
||||||
if ( p->scan_rst.search_evt == ESP_GAP_SEARCH_INQ_CMPL_EVT) // Inquiry complete, scan is done
|
if ( p->scan_rst.search_evt == ESP_GAP_SEARCH_INQ_CMPL_EVT) // Inquiry complete, scan is done
|
||||||
{ // restart scan
|
{ // restart scan
|
||||||
status = esp_ble_gap_start_scanning (cfg.blescantime);
|
status = esp_ble_gap_start_scanning (BLESCANTIME);
|
||||||
if (status != ESP_OK)
|
if (status != ESP_OK)
|
||||||
{
|
{
|
||||||
ESP_LOGE(TAG, "esp_ble_gap_start_scanning: rc=%d", status);
|
ESP_LOGE(TAG, "esp_ble_gap_start_scanning: rc=%d", status);
|
||||||
@ -207,7 +207,7 @@ esp_err_t register_ble_functionality(void)
|
|||||||
#else
|
#else
|
||||||
.scan_filter_policy = BLE_SCAN_FILTER_ALLOW_ALL,
|
.scan_filter_policy = BLE_SCAN_FILTER_ALLOW_ALL,
|
||||||
#endif
|
#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
|
.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.rssilimit = 0; // threshold for rssilimiter, negative value!
|
||||||
cfg.sendcycle = SEND_SECS; // payload send cycle [seconds/2]
|
cfg.sendcycle = SEND_SECS; // payload send cycle [seconds/2]
|
||||||
cfg.wifichancycle = WIFI_CHANNEL_SWITCH_INTERVAL; // wifi channel switch cycle [seconds/100]
|
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.blescan = 1; // 0=disabled, 1=enabled
|
||||||
cfg.wifiant = 0; // 0=internal, 1=external (for LoPy/LoPy4)
|
cfg.wifiant = 0; // 0=internal, 1=external (for LoPy/LoPy4)
|
||||||
cfg.vendorfilter = 1; // 0=disabled, 1=enabled
|
cfg.vendorfilter = 1; // 0=disabled, 1=enabled
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
|
|
||||||
// program version - note: increment version after modifications to configData_t struct!!
|
// 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"
|
#define PROGNAME "PAXCNT"
|
||||||
|
|
||||||
//--- Declarations ---
|
//--- Declarations ---
|
||||||
|
@ -11,18 +11,18 @@
|
|||||||
|
|
||||||
// BLE scan parameters
|
// BLE scan parameters
|
||||||
#define BLESTACKSIZE 8192 // stack size for esp_bt_controller
|
#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 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] how long to wait between scans, 3 .. 10240, default 10
|
||||||
|
|
||||||
/* Note: guide for setting bluetooth parameters
|
/* Note: guide for setting bluetooth parameters
|
||||||
*
|
*
|
||||||
* |< Scan Window > |< Scan Window > |< Scan Window > |
|
* |< Scan Window > |< Scan Window > | ... |< Scan Window > |
|
||||||
* |< Scan Interval >|< Scan Interval >|< Scan Interval >|
|
* |< Scan Interval >|< Scan Interval >| ... |< Scan Interval >|
|
||||||
* |< Scan duration >|
|
* |< Scan duration >|
|
||||||
*
|
*
|
||||||
* Scan duration sets how long scanning should be going on, interrupting a wifi scan cycle.
|
* 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.
|
* 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.
|
* 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.
|
* -> Adjust these values with power consumption in mind if power is limited.
|
||||||
*/
|
*/
|
||||||
|
@ -9,6 +9,12 @@
|
|||||||
#include <lmic.h>
|
#include <lmic.h>
|
||||||
#include <hal/hal.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
|
// Local logging tag
|
||||||
static const char *TAG = "rcommand";
|
static const char *TAG = "rcommand";
|
||||||
|
|
||||||
@ -92,6 +98,25 @@ void set_wifichancycle(uint8_t val) {
|
|||||||
void set_blescantime(uint8_t val) {
|
void set_blescantime(uint8_t val) {
|
||||||
cfg.blescantime = 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 %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) {
|
void set_countmode(uint8_t val) {
|
||||||
|
Loading…
Reference in New Issue
Block a user