From 48c9b1d61197a53fa2007a09d97c4e48406af57b Mon Sep 17 00:00:00 2001 From: Charles Date: Fri, 13 Apr 2018 14:00:12 +0200 Subject: [PATCH 01/45] removed some compile files --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index f7a1e196..a535321a 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,5 @@ src/loraconf.h .vscode/*.db .vscode/.browse.c_cpp.db* +.clang_complete +.gcc-flags.json From e91b6be5dd50984511c746168178641ef0d1e809 Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Sat, 14 Apr 2018 17:52:30 +0200 Subject: [PATCH 02/45] macsniff.cpp: removed some BLExxx.h --- src/macsniff.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/macsniff.cpp b/src/macsniff.cpp index 624dcba3..08e79d8c 100644 --- a/src/macsniff.cpp +++ b/src/macsniff.cpp @@ -4,9 +4,9 @@ #ifdef BLECOUNTER #include - #include - #include - #include + //#include + //#include + //#include #endif #ifdef VENDORFILTER From 71957108db701eca9268a49fc71f995b79af04ec Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Sat, 14 Apr 2018 18:23:20 +0200 Subject: [PATCH 03/45] fixed BLE lib to v0.4.9 --- platformio.ini | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/platformio.ini b/platformio.ini index 329190a2..dc173f25 100644 --- a/platformio.ini +++ b/platformio.ini @@ -26,7 +26,7 @@ monitor_baud = 115200 upload_speed = 921600 lib_deps = U8g2 - ESP32 BLE Arduino@>=0.4.9 + ESP32 BLE Arduino@0.4.9 build_flags = ;set log level, we need build_flag for this, otherwise we can't use ESP_LOGx in arduino framework -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_INFO @@ -53,7 +53,7 @@ upload_speed = 921600 ;upload_port = COM15 lib_deps = U8g2 - ESP32 BLE Arduino@>=0.4.9 + ESP32 BLE Arduino@0.4.9 build_flags = ;set log level, we need build_flag for this, otherwise we can't use ESP_LOGx in arduino framework -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_INFO @@ -79,7 +79,7 @@ monitor_baud = 115200 upload_speed = 921600 lib_deps = U8g2 - ESP32 BLE Arduino@>=0.4.9 + ESP32 BLE Arduino@0.4.9 build_flags = ;set log level, we need build_flag for this, otherwise we can't use ESP_LOGx in arduino framework -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_INFO @@ -104,7 +104,7 @@ monitor_baud = 115200 upload_speed = 921600 lib_deps = U8g2@>2.21.7 - ESP32 BLE Arduino@>=0.4.9 + ESP32 BLE Arduino@0.4.9 SmartLeds build_flags = ;set log level, we need build_flag for this, otherwise we can't use ESP_LOGx in arduino framework @@ -130,7 +130,7 @@ monitor_baud = 115200 upload_speed = 921600 lib_deps = U8g2@>2.21.7 - ESP32 BLE Arduino@>=0.4.9 + ESP32 BLE Arduino@0.4.9 SmartLeds build_flags = ;set log level, we need build_flag for this, otherwise we can't use ESP_LOGx in arduino framework @@ -156,7 +156,7 @@ monitor_baud = 115200 upload_speed = 256000 lib_deps = U8g2 - ESP32 BLE Arduino@>=0.4.9 + ESP32 BLE Arduino@0.4.9 SmartLeds build_flags = ;set log level, we need build_flag for this, otherwise we can't use ESP_LOGx in arduino framework @@ -182,7 +182,7 @@ monitor_baud = 115200 upload_speed = 921600 lib_deps = U8g2 - ESP32 BLE Arduino@>=0.4.9 + ESP32 BLE Arduino@0.4.9 SmartLeds build_flags = ;set log level, we need build_flag for this, otherwise we can't use ESP_LOGx in arduino framework From 116197f63242bd099105d953a28ae0e197fb54ed Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Sat, 14 Apr 2018 19:22:29 +0200 Subject: [PATCH 04/45] blescan.cpp created --- platformio.ini | 4 +- src/blecsan.cpp | 313 ++++++++++++++++++++++++++++++++++++++++++++++++ src/globals.h | 2 +- src/main.cpp | 9 +- src/main.h | 2 +- 5 files changed, 325 insertions(+), 5 deletions(-) create mode 100644 src/blecsan.cpp diff --git a/platformio.ini b/platformio.ini index dc173f25..7f05eab7 100644 --- a/platformio.ini +++ b/platformio.ini @@ -10,9 +10,9 @@ ; ---> SELECT TARGET PLATFORM HERE! <--- [platformio] -env_default = heltec_wifi_lora_32 +;env_default = heltec_wifi_lora_32 ;env_default = ttgov1 -;env_default = ttgov2 +env_default = ttgov2 ;env_default = lopy ;env_default = lopy4 ;env_default = lolin32lite_lora diff --git a/src/blecsan.cpp b/src/blecsan.cpp new file mode 100644 index 00000000..29924507 --- /dev/null +++ b/src/blecsan.cpp @@ -0,0 +1,313 @@ +/* code snippets taken from +https://github.com/nkolban/esp32-snippets/tree/master/BLE/scanner +*/ + +// Basic Config +#include "globals.h" + +// Bluetooth specific includes +#include +#include +#include + +#define BT_BD_ADDR_STR "%02x:%02x:%02x:%02x:%02x:%02x" +#define BT_BD_ADDR_HEX(addr) addr[0], addr[1], addr[2], addr[3], addr[4], addr[5] + +// Prototypes +static const char *bt_event_type_to_string(uint32_t eventType); +static const char *bt_gap_search_event_type_to_string(uint32_t searchEvt); +static const char *bt_addr_t_to_string(esp_ble_addr_type_t type); +static const char *bt_dev_type_to_string(esp_bt_dev_type_t type); +static void gap_callback_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *param); + +// local Tag for logging +static const char *TAG = "paxcnt"; + +static void gap_callback_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *param) +{ + ESP_LOGD(TAG, "Received a GAP event: %s", bt_event_type_to_string(event)); + esp_ble_gap_cb_param_t *p = (esp_ble_gap_cb_param_t *)param; + + esp_err_t status; + + + switch (event) + { + case ESP_GAP_BLE_SCAN_PARAM_SET_COMPLETE_EVT: + { + ESP_LOGD(TAG, "status: %d", p->scan_param_cmpl.status); + + // This procedure keep the device scanning the peer device which advertising on the air. + status = esp_ble_gap_start_scanning(BLESCANTIME); + if (status != ESP_OK) + { + ESP_LOGE(TAG, "esp_ble_gap_start_scanning: rc=%d", status); + } + } + break; + + case ESP_GAP_BLE_SCAN_START_COMPLETE_EVT: + { + //scan start complete event to indicate scan start successfully or failed + if (param->scan_start_cmpl.status != ESP_BT_STATUS_SUCCESS) + { + ESP_LOGE(TAG, "Scan start failed"); + } + } + break; + + case ESP_GAP_BLE_SCAN_RESULT_EVT: + { + + ESP_LOGI(TAG, "Device address (bda): %02x:%02x:%02x:%02x:%02x:%02x", BT_BD_ADDR_HEX(p->scan_rst.bda)); + ESP_LOGI(TAG, "Device type : %s", bt_dev_type_to_string(p->scan_rst.dev_type)); + ESP_LOGI(TAG, "Search_evt : %s", bt_gap_search_event_type_to_string(p->scan_rst.search_evt)); + ESP_LOGI(TAG, "Addr_type : %s", bt_addr_t_to_string(p->scan_rst.ble_addr_type)); + ESP_LOGI(TAG, "RSSI : %d", p->scan_rst.rssi); + ESP_LOGI(TAG, "Flag : %d", p->scan_rst.flag); + + //bit 0 (OFF) LE Limited Discoverable Mode + //bit 1 (OFF) LE General Discoverable Mode + //bit 2 (ON) BR/EDR Not Supported + //bit 3 (OFF) Simultaneous LE and BR/EDR to Same Device Capable (controller) + //bit 4 (OFF) Simultaneous LE and BR/EDR to Same Device Capable (Host) + + ESP_LOGI(TAG, "num_resps : %d", p->scan_rst.num_resps); + + if ( p->scan_rst.search_evt == ESP_GAP_SEARCH_INQ_CMPL_EVT) + { + // Scan is done. + + // The next 5 codelines automatically restarts the scan. + status = esp_ble_gap_start_scanning (BLESCANTIME); + if (status != ESP_OK) + { + ESP_LOGE(TAG, "esp_ble_gap_start_scanning: rc=%d", status); + } + + return; + } + + + if (p->scan_rst.search_evt == ESP_GAP_SEARCH_INQ_RES_EVT) + { + + // you can search for elements in the payload using the + // function esp_ble_resolve_adv_data() + // + // Like this, that scans for the "Complete name" (looking inside the payload buffer) + + uint8_t len; + uint8_t *data = esp_ble_resolve_adv_data(p->scan_rst.ble_adv, ESP_BLE_AD_TYPE_NAME_CMPL, &len); + ESP_LOGD(TAG, "len: %d, %.*s", len, len, data); + + } + ESP_LOGI(TAG, ""); + + } + break; + + case ESP_GAP_BLE_SCAN_STOP_COMPLETE_EVT: + { + if (param->scan_stop_cmpl.status != ESP_BT_STATUS_SUCCESS) + { + ESP_LOGE(TAG, "Scan stop failed"); + } + else + { + ESP_LOGI(TAG, "Stop scan successfully"); + } + } + + case ESP_GAP_BLE_ADV_STOP_COMPLETE_EVT: + { + if (param->adv_stop_cmpl.status != ESP_BT_STATUS_SUCCESS) + { + ESP_LOGE(TAG, "Adv stop failed"); + } + else + { + ESP_LOGI(TAG, "Stop adv successfully"); + } + } + break; + + + default: + break; + } +} // gap_callback_handler + +static const char *bt_dev_type_to_string(esp_bt_dev_type_t type) { + switch(type) { + case ESP_BT_DEVICE_TYPE_BREDR: + return "ESP_BT_DEVICE_TYPE_BREDR"; + case ESP_BT_DEVICE_TYPE_BLE: + return "ESP_BT_DEVICE_TYPE_BLE"; + case ESP_BT_DEVICE_TYPE_DUMO: + return "ESP_BT_DEVICE_TYPE_DUMO"; + default: + return "Unknown"; + } +} // bt_dev_type_to_string + +static const char *bt_addr_t_to_string(esp_ble_addr_type_t type) { + switch(type) { + case BLE_ADDR_TYPE_PUBLIC: + return "BLE_ADDR_TYPE_PUBLIC"; + case BLE_ADDR_TYPE_RANDOM: + return "BLE_ADDR_TYPE_RANDOM"; + case BLE_ADDR_TYPE_RPA_PUBLIC: + return "BLE_ADDR_TYPE_RPA_PUBLIC"; + case BLE_ADDR_TYPE_RPA_RANDOM: + return "BLE_ADDR_TYPE_RPA_RANDOM"; + default: + return "Unknown addr_t"; + } +} // bt_addr_t_to_string + +static const char *bt_gap_search_event_type_to_string(uint32_t searchEvt) { + switch(searchEvt) { + case ESP_GAP_SEARCH_INQ_RES_EVT: + return "ESP_GAP_SEARCH_INQ_RES_EVT"; + case ESP_GAP_SEARCH_INQ_CMPL_EVT: + return "ESP_GAP_SEARCH_INQ_CMPL_EVT"; + case ESP_GAP_SEARCH_DISC_RES_EVT: + return "ESP_GAP_SEARCH_DISC_RES_EVT"; + case ESP_GAP_SEARCH_DISC_BLE_RES_EVT: + return "ESP_GAP_SEARCH_DISC_BLE_RES_EVT"; + case ESP_GAP_SEARCH_DISC_CMPL_EVT: + return "ESP_GAP_SEARCH_DISC_CMPL_EVT"; + case ESP_GAP_SEARCH_DI_DISC_CMPL_EVT: + return "ESP_GAP_SEARCH_DI_DISC_CMPL_EVT"; + case ESP_GAP_SEARCH_SEARCH_CANCEL_CMPL_EVT: + return "ESP_GAP_SEARCH_SEARCH_CANCEL_CMPL_EVT"; + default: + return "Unknown event type"; + } +} // bt_gap_search_event_type_to_string + +/* + * Convert a BT GAP event type to a string representation. + */ +static const char *bt_event_type_to_string(uint32_t eventType) { + switch(eventType) { + case ESP_GAP_BLE_ADV_DATA_SET_COMPLETE_EVT: + return "ESP_GAP_BLE_ADV_DATA_SET_COMPLETE_EVT"; + case ESP_GAP_BLE_SCAN_PARAM_SET_COMPLETE_EVT: + return "ESP_GAP_BLE_SCAN_PARAM_SET_COMPLETE_EVT"; + case ESP_GAP_BLE_SCAN_RESULT_EVT: + return "ESP_GAP_BLE_SCAN_RESULT_EVT"; + case ESP_GAP_BLE_SCAN_RSP_DATA_SET_COMPLETE_EVT: + return "ESP_GAP_BLE_SCAN_RSP_DATA_SET_COMPLETE_EVT"; + default: + return "Unknown event type"; + } +} // bt_event_type_to_string + + + +esp_err_t register_ble_functionality(void) +{ + esp_err_t status; + + ESP_LOGI(TAG, "Register GAP callback"); + + // This function is called to occur gap event, such as scan result. + //register the scan callback function to the gap module + status = esp_ble_gap_register_callback(gap_callback_handler); + if (status != ESP_OK) + { + ESP_LOGE(TAG, "esp_ble_gap_register_callback: rc=%d", status); + return ESP_FAIL; + } + + static esp_ble_scan_params_t ble_scan_params = + { + .scan_type = BLE_SCAN_TYPE_PASSIVE, + .own_addr_type = BLE_ADDR_TYPE_PUBLIC, + .scan_filter_policy = BLE_SCAN_FILTER_ALLOW_ALL, + .scan_interval = (uint16_t) (BLESCANINTERVAL / 0.625), // Time = N * 0.625 msec + .scan_window = (uint16_t) (BLESCANWINDOW / 0.625) // Time = N * 0.625 msec + }; + + ESP_LOGI(TAG, "Set GAP scan parameters"); + + // This function is called to set scan parameters. + status = esp_ble_gap_set_scan_params(&ble_scan_params); + if (status != ESP_OK) + { + ESP_LOGE(TAG, "esp_ble_gap_set_scan_params: rc=%d", status); + return ESP_FAIL; + } + + + ESP_LOGD(TAG, "We have registered what we need!"); + + return ESP_OK ; +} + + +// Main start code running in its own Xtask +void bt_loop(void *ignore) +{ + esp_err_t status; + + ESP_LOGI(TAG, "Enabling Bluetooth Controller"); + + // Initialize BT controller to allocate task and other resource. + esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT(); + if (esp_bt_controller_init(&bt_cfg) != ESP_OK) + { + ESP_LOGE(TAG, "Bluetooth controller initialize failed"); + goto end; + } + + // Enable BT controller + if (esp_bt_controller_enable(ESP_BT_MODE_BTDM) != ESP_OK) + { + ESP_LOGE(TAG, "Bluetooth controller enable failed"); + goto end; + } + + ESP_LOGI(TAG, "Bluetooth Controller Enabled"); + + ESP_LOGI(TAG, "Init Bluetooth stack"); + + // Init and alloc the resource for bluetooth, must be prior to every bluetooth stuff + status = esp_bluedroid_init(); + if (status != ESP_OK) + { + ESP_LOGE(TAG, "%s init bluetooth failed\n", __func__); + goto end; + } + + // Enable bluetooth, must after esp_bluedroid_init() + status = esp_bluedroid_enable(); + if (status != ESP_OK) + { + ESP_LOGE(TAG, "%s enable bluetooth failed\n", __func__); + goto end; + } + + ESP_LOGI(TAG, "Bluetooth stack initialized"); + + ESP_LOGI(TAG, "Register BLE functionality"); + status = register_ble_functionality(); + if (status != ESP_OK) + { + ESP_LOGE(TAG, "Register BLE functionality failed"); + goto end; + } + + while(1) + { + vTaskDelay(1000); + yield(); + } + +end: + ESP_LOGI(TAG, "Terminating BT logging task"); + vTaskDelete(NULL); + +} // bt_loop \ No newline at end of file diff --git a/src/globals.h b/src/globals.h index 396f7fa9..25b8d333 100644 --- a/src/globals.h +++ b/src/globals.h @@ -57,5 +57,5 @@ extern std::set macs; #ifdef BLECOUNTER extern int scanTime; - extern std::set bles; + extern std::set bles; #endif diff --git a/src/main.cpp b/src/main.cpp index 518e81ad..8728dbc9 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -253,6 +253,9 @@ void wifi_sniffer_init(void); 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); + // Sniffer Task void sniffer_loop(void * pvParameters) { @@ -513,12 +516,16 @@ salt_reset(); // get new 16bit for salting hashes xTaskCreatePinnedToCore(lorawan_loop, "loratask", 2048, ( void * ) 1, ( 5 | portPRIVILEGE_BIT ), NULL, 0); ESP_LOGI(TAG, "Starting Wifi task on core 0"); xTaskCreatePinnedToCore(wifi_sniffer_loop, "wifisniffer", 4096, ( void * ) 1, 1, NULL, 0); + ESP_LOGI(TAG, "Starting Bluetooth task on core 0"); + xTaskCreatePinnedToCore(bt_loop, "btscan", 2048, NULL, 5, NULL, 0); // to come here: code for switching off core 1 -#else // run wifi task on core 0 and lora task on core 1 +#else // run wifi task on core 0 and lora task on core 1 and bt task 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", 4096, ( void * ) 1, 1, NULL, 0); + ESP_LOGI(TAG, "Starting Bluetooth task on core 1"); + xTaskCreatePinnedToCore(bt_loop, "btscan", 2048, NULL, 5, NULL, 1); #endif // Finally: kickoff first sendjob and join, then send initial payload "0000" diff --git a/src/main.h b/src/main.h index 305bd81a..a532af16 100644 --- a/src/main.h +++ b/src/main.h @@ -9,7 +9,7 @@ // 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 // BLE scan parameters #define BLESCANCYCLE 2 // BLE scan once after each wifi scans From c57e7b75f445289dd1a044a2dc7d966f1896bd62 Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Sat, 14 Apr 2018 20:22:58 +0200 Subject: [PATCH 05/45] completely reworked BLE scan --- LICENSE | 8 ++-- platformio.ini | 28 ------------ src/blecsan.cpp | 37 ++++++++++++++- src/macsniff.cpp | 117 ++++++++++++----------------------------------- src/macsniff.h | 3 -- src/main.cpp | 39 ++++++++-------- src/main.h | 4 +- 7 files changed, 90 insertions(+), 146 deletions(-) diff --git a/LICENSE b/LICENSE index 82a5eca3..aa52acab 100644 --- a/LICENSE +++ b/LICENSE @@ -228,13 +228,13 @@ under this Licence: Most source files in this repository are made available under the Eclipse Public License v1.0. The examples which use a more liberal license. Some of the AES code is available under the LGPL. Refer to each individual source file for more details." ------------------------------------------------------------------------------------------------ -blecount.cpp +blescan.cpp -Parts of blecount.cpp were derived or taken from +Parts of blescan.cpp were derived or taken from nkolban esp32 snippets -BLE Scan -https://github.com/nkolban/esp32-snippets/tree/master/cpp_utils/tests/BLETests/Arduino/BLE_scan +BLE GAP DUMP +https://github.com/nkolban/esp32-snippets/tree/master/BLE/scanner under this Licence: diff --git a/platformio.ini b/platformio.ini index 7f05eab7..f5faf74d 100644 --- a/platformio.ini +++ b/platformio.ini @@ -26,15 +26,11 @@ monitor_baud = 115200 upload_speed = 921600 lib_deps = U8g2 - ESP32 BLE Arduino@0.4.9 build_flags = ;set log level, we need build_flag for this, otherwise we can't use ESP_LOGx in arduino framework -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_INFO ; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_VERBOSE ; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_NONE -;needed for ESP32 BLE Ardunio v0.4.9 - -fexceptions - -std=c++11 ;override lora settings from LMiC library in lmic/config.h and use main.h instead -D_lmic_config_h_ -Dheltec_wifi_lora_32 @@ -53,15 +49,11 @@ upload_speed = 921600 ;upload_port = COM15 lib_deps = U8g2 - ESP32 BLE Arduino@0.4.9 build_flags = ;set log level, we need build_flag for this, otherwise we can't use ESP_LOGx in arduino framework -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_INFO ; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_VERBOSE ; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_NONE -;needed for ESP32 BLE Ardunio v0.4.9 - -fexceptions - -std=c++11 ;override lora settings from LMiC library in lmic/config.h and use main.h instead -Dttgov1 -D_lmic_config_h_ @@ -79,15 +71,11 @@ monitor_baud = 115200 upload_speed = 921600 lib_deps = U8g2 - ESP32 BLE Arduino@0.4.9 build_flags = ;set log level, we need build_flag for this, otherwise we can't use ESP_LOGx in arduino framework -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_INFO ; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_VERBOSE ; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_NONE -;needed for ESP32 BLE Ardunio v0.4.9 - -fexceptions - -std=c++11 ;override lora settings from LMiC library in lmic/config.h and use main.h instead -D_lmic_config_h_ -Dttgov2 @@ -104,16 +92,12 @@ monitor_baud = 115200 upload_speed = 921600 lib_deps = U8g2@>2.21.7 - ESP32 BLE Arduino@0.4.9 SmartLeds build_flags = ;set log level, we need build_flag for this, otherwise we can't use ESP_LOGx in arduino framework -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_INFO ; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_VERBOSE ; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_NONE -;needed for ESP32 BLE Ardunio v0.4.9 - -fexceptions - -std=c++11 ;override lora settings from LMiC library in lmic/config.h and use main.h instead -Dlopy -D_lmic_config_h_ @@ -130,16 +114,12 @@ monitor_baud = 115200 upload_speed = 921600 lib_deps = U8g2@>2.21.7 - ESP32 BLE Arduino@0.4.9 SmartLeds build_flags = ;set log level, we need build_flag for this, otherwise we can't use ESP_LOGx in arduino framework -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_INFO ; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_VERBOSE ; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_NONE -;needed for ESP32 BLE Ardunio v0.4.9 - -fexceptions - -std=c++11 ;override lora settings from LMiC library in lmic/config.h and use main.h instead -D_lmic_config_h_ -Dlopy4 @@ -156,16 +136,12 @@ monitor_baud = 115200 upload_speed = 256000 lib_deps = U8g2 - ESP32 BLE Arduino@0.4.9 SmartLeds build_flags = ;set log level, we need build_flag for this, otherwise we can't use ESP_LOGx in arduino framework -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_INFO ; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_VERBOSE ; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_NONE -;needed for ESP32 BLE Ardunio v0.4.9 - -fexceptions - -std=c++11 ;override lora settings from LMiC library in lmic/config.h and use main.h instead -D_lmic_config_h_ -Dlolin32lite_lora @@ -182,16 +158,12 @@ monitor_baud = 115200 upload_speed = 921600 lib_deps = U8g2 - ESP32 BLE Arduino@0.4.9 SmartLeds build_flags = ;set log level, we need build_flag for this, otherwise we can't use ESP_LOGx in arduino framework -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_INFO ; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_VERBOSE ; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_NONE -;needed for ESP32 BLE Ardunio v0.4.9 - -fexceptions - -std=c++11 ;override lora settings from LMiC library in lmic/config.h and use main.h instead -D_lmic_config_h_ -Dlolin32_lora diff --git a/src/blecsan.cpp b/src/blecsan.cpp index 29924507..51dab5c5 100644 --- a/src/blecsan.cpp +++ b/src/blecsan.cpp @@ -1,3 +1,5 @@ +#ifdef BLECOUNTER + /* code snippets taken from https://github.com/nkolban/esp32-snippets/tree/master/BLE/scanner */ @@ -10,6 +12,9 @@ https://github.com/nkolban/esp32-snippets/tree/master/BLE/scanner #include #include +// defined in macsniff.cpp +bool mac_add(uint8_t *paddr, int8_t rssi, bool sniff_type); + #define BT_BD_ADDR_STR "%02x:%02x:%02x:%02x:%02x:%02x" #define BT_BD_ADDR_HEX(addr) addr[0], addr[1], addr[2], addr[3], addr[4], addr[5] @@ -21,7 +26,7 @@ static const char *bt_dev_type_to_string(esp_bt_dev_type_t type); static void gap_callback_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *param); // local Tag for logging -static const char *TAG = "paxcnt"; +static const char *TAG = "bt_loop"; static void gap_callback_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *param) { @@ -74,6 +79,32 @@ static void gap_callback_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_pa ESP_LOGI(TAG, "num_resps : %d", p->scan_rst.num_resps); + /* to be done here: + #ifdef VENDORFILTER + + filter BLE devices using their advertisements to get filter alternative to vendor OUI + if vendorfiltering is on, we ... + - want to count: mobile phones and tablets + - don't want to count: beacons, peripherals (earphones, headsets, printers), cars and machines + see + https://github.com/nkolban/ESP32_BLE_Arduino/blob/master/src/BLEAdvertisedDevice.cpp + + http://www.libelium.com/products/meshlium/smartphone-detection/ + + https://www.question-defense.com/2013/01/12/bluetooth-cod-bluetooth-class-of-deviceclass-of-service-explained + + https://www.bluetooth.com/specifications/assigned-numbers/baseband + + "The Class of Device (CoD) in case of Bluetooth which allows us to differentiate the type of + device (smartphone, handsfree, computer, LAN/network AP). With this parameter we can + differentiate among pedestrians and vehicles." + + #endif + */ + + // add this device and show new count total if it was not previously added + mac_add((uint8_t *) p->scan_rst.bda, p->scan_rst.rssi, MAC_SNIFF_BLE); + if ( p->scan_rst.search_evt == ESP_GAP_SEARCH_INQ_CMPL_EVT) { // Scan is done. @@ -310,4 +341,6 @@ end: ESP_LOGI(TAG, "Terminating BT logging task"); vTaskDelete(NULL); -} // bt_loop \ No newline at end of file +} // bt_loop + +#endif // BLECOUNTER \ No newline at end of file diff --git a/src/macsniff.cpp b/src/macsniff.cpp index 08e79d8c..0664f179 100644 --- a/src/macsniff.cpp +++ b/src/macsniff.cpp @@ -2,13 +2,6 @@ // Basic Config #include "globals.h" -#ifdef BLECOUNTER - #include - //#include - //#include - //#include -#endif - #ifdef VENDORFILTER #include #include @@ -20,7 +13,6 @@ static const char *TAG = "macsniff"; static wifi_country_t wifi_country = {.cc=WIFI_MY_COUNTRY, .schan=WIFI_CHANNEL_MIN, .nchan=WIFI_CHANNEL_MAX, .policy=WIFI_COUNTRY_POLICY_MANUAL}; -uint16_t currentScanDevice = 0; uint16_t salt; uint16_t salt_reset(void) { @@ -46,31 +38,41 @@ bool mac_add(uint8_t *paddr, int8_t rssi, bool sniff_type) { if ( (sniff_type==MAC_SNIFF_BLE) || std::find(vendors.begin(), vendors.end(), vendor2int) != vendors.end() ) { #endif - // salt and hash MAC, and if new unique one, store identifier in container and increment counter on display - // https://en.wikipedia.org/wiki/MAC_Address_Anonymization + // salt and hash MAC, and if new unique one, store identifier in container and increment counter on display + // https://en.wikipedia.org/wiki/MAC_Address_Anonymization - addr2int += (uint32_t) salt; // add 16-bit salt to pseudo MAC - snprintf(buff, sizeof(buff), "%08X", addr2int); // convert unsigned 32-bit salted MAC to 8 digit hex string - hashedmac = rokkit(&buff[3], 5); // hash MAC last string value, use 5 chars to fit hash in uint16_t container - auto newmac = macs.insert(hashedmac); // add hashed MAC to total container if new unique - added = newmac.second ? true:false; // true if hashed MAC is unique in container + addr2int += (uint32_t) salt; // add 16-bit salt to pseudo MAC + snprintf(buff, sizeof(buff), "%08X", addr2int); // convert unsigned 32-bit salted MAC to 8 digit hex string + hashedmac = rokkit(&buff[3], 5); // hash MAC last string value, use 5 chars to fit hash in uint16_t container + auto newmac = macs.insert(hashedmac); // add hashed MAC to total container if new unique + added = newmac.second ? true:false; // true if hashed MAC is unique in container - // Insert only if it was not found on global count - if (added) { - if (sniff_type == MAC_SNIFF_WIFI ) { - rgb_set_color(COLOR_GREEN); - wifis.insert(hashedmac); // add hashed MAC to wifi container if new unique - } - #ifdef BLECOUNTER + // Insert only if it was not found on global count + if (added) { + + char buff[16]; + snprintf(buff, sizeof(buff), "PAX:%-4d", (int) macs.size()); // convert 16-bit MAC counter to decimal counter value + u8x8.draw2x2String(0, 0, buff); // display number on unique macs total Wifi + BLE + + if (sniff_type == MAC_SNIFF_WIFI ) { + rgb_set_color(COLOR_GREEN); + wifis.insert(hashedmac); // add hashed MAC to wifi container + u8x8.setCursor(0,4); + u8x8.printf("WIFI: %-4d", (int) wifis.size()); + } + #ifdef BLECOUNTER else if (sniff_type == MAC_SNIFF_BLE ) { rgb_set_color(COLOR_MAGENTA); - bles.insert(hashedmac); // add hashed MAC to BLE container if new unique + bles.insert(hashedmac); // add hashed MAC to BLE container + u8x8.setCursor(0,3); + u8x8.printf("BLE: %-4d", (int) bles.size()); } - #endif - // Not sure user will have time to see the LED - // TBD do light off further in the code - rgb_set_color(COLOR_NONE); - } + #endif + + // Not sure user will have time to see the LED + // TBD do light off further in the code + rgb_set_color(COLOR_NONE); + } ESP_LOGI(TAG, "%s RSSI %ddBi -> MAC %s -> Hash %04X -> WiFi:%d BLE:%d %s", sniff_type==MAC_SNIFF_WIFI ? "WiFi":"BLE ", @@ -94,65 +96,6 @@ bool mac_add(uint8_t *paddr, int8_t rssi, bool sniff_type) { return added; // function returns bool if a new and unique Wifi or BLE mac was counted (true) or not (false) } -#ifdef BLECOUNTER - -class MyAdvertisedDeviceCallbacks: public BLEAdvertisedDeviceCallbacks { - void onResult(BLEAdvertisedDevice advertisedDevice) { - int lastcount = (int) macs.size(); - uint8_t *p = (uint8_t *) advertisedDevice.getAddress().getNative(); - - /* to be done here: - #ifdef VENDORFILTER - - filter BLE devices using their advertisements to get filter alternative to vendor OUI - if vendorfiltering is on, we ... - - want to count: mobile phones and tablets - - don't want to count: beacons, peripherals (earphones, headsets, printers), cars and machines - see - https://github.com/nkolban/ESP32_BLE_Arduino/blob/master/src/BLEAdvertisedDevice.cpp - - http://www.libelium.com/products/meshlium/smartphone-detection/ - - https://www.question-defense.com/2013/01/12/bluetooth-cod-bluetooth-class-of-deviceclass-of-service-explained - - https://www.bluetooth.com/specifications/assigned-numbers/baseband - - "The Class of Device (CoD) in case of Bluetooth which allows us to differentiate the type of - device (smartphone, handsfree, computer, LAN/network AP). With this parameter we can - differentiate among pedestrians and vehicles." - - #endif - */ - - // Current devices seen on this scan session - currentScanDevice++; - u8x8.setCursor(11,3); - u8x8.printf("%-4d", currentScanDevice); - // add this device and show new count total if it was not previously added - if ( mac_add(p, advertisedDevice.getRSSI(), MAC_SNIFF_BLE) ) { - char buff[16]; - snprintf(buff, sizeof(buff), "PAX:%-4d", (int) macs.size()); // convert 16-bit MAC counter to decimal counter value - u8x8.draw2x2String(0, 0, buff); // display number on unique macs total Wifi + BLE - } - } -}; - -void BLECount() { - ESP_LOGI(TAG, "BLE scan started"); - currentScanDevice = 0; // Set 0 seen device on this scan session - u8x8.drawString(0,3,"Scanning->"); - BLEDevice::init(""); // we don't want to be seen by a name - BLEScanResults foundDevices; // instance for getting count - BLEScan* pBLEScan = BLEDevice::getScan(); //create new scan - pBLEScan->setAdvertisedDeviceCallbacks(new MyAdvertisedDeviceCallbacks()); - pBLEScan->setActiveScan(false); // An active scan would mean that we will wish unneeeded scan responses - pBLEScan->setWindow(BLESCANWINDOW); - pBLEScan->setInterval(BLESCANINTERVAL); - pBLEScan->start(cfg.blescantime); // note: this is a blocking call - ESP_LOGI(TAG, "BLE scan done, seen %d device(s)", foundDevices.getCount()); -} -#endif - void wifi_sniffer_init(void) { wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT(); cfg.nvs_enable = 0; // we don't need any wifi settings from NVRAM diff --git a/src/macsniff.h b/src/macsniff.h index 9fa2496b..441ab157 100644 --- a/src/macsniff.h +++ b/src/macsniff.h @@ -19,10 +19,7 @@ typedef struct { uint8_t payload[0]; /* network data ended with 4 bytes csum (CRC32) */ } wifi_ieee80211_packet_t; -extern uint16_t currentScanDevice; - uint16_t salt_reset(void); -void BLECount(); void wifi_sniffer_init(void); void wifi_sniffer_set_channel(uint8_t channel); void wifi_sniffer_packet_handler(void *buff, wifi_promiscuous_pkt_type_t type); diff --git a/src/main.cpp b/src/main.cpp index 8728dbc9..e44c0cd4 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -215,9 +215,7 @@ void lorawan_loop(void * pvParameters) { void antenna_select(const int8_t _ant); #endif -#ifdef BLECOUNTER - void BLECount(void); -#else +#ifndef BLECOUNTER bool btstop = btStop(); #endif @@ -276,19 +274,7 @@ void sniffer_loop(void * pvParameters) { snprintf(buff, sizeof(buff), "PAX:%d", (int) macs.size()); // convert 16-bit MAC counter to decimal counter value u8x8.draw2x2String(0, 0, buff); // display number on unique macs total - - #ifdef BLECOUNTER - // We just state out of BLE scanning - u8x8.setCursor(0,3); - if (currentScanDevice) { - u8x8.printf("BLE: %-4d %-4d", (int) bles.size(), currentScanDevice); - } else { - u8x8.printf("BLE: %-4d", (int) bles.size()); - } - #endif - - u8x8.setCursor(0,4); - u8x8.printf("WIFI: %-4d", (int) wifis.size()); + u8x8.setCursor(11,4); u8x8.printf("ch:%02i", channel); u8x8.setCursor(0,5); @@ -340,12 +326,14 @@ void sniffer_loop(void * pvParameters) { } // end of send data cycle else { + /* #ifdef BLECOUNTER if (nloop % (WIFI_CHANNEL_MAX * cfg.blescancycle) == 0 ) // once after cfg.blescancycle Wifi scans, do a BLE scan if (cfg.blescan) { // execute BLE count if BLE function is enabled BLECount(); // start BLE scan, this is a blocking call } #endif + */ } // end of channel rotation loop } // end of infinite wifi scan loop } @@ -493,6 +481,13 @@ void setup() { // initialize display init_display(PROGNAME, PROGVERSION); u8x8.setPowerSave(!cfg.screenon); // set display off if disabled + u8x8.draw2x2String(0, 0, "PAX:0"); + u8x8.setCursor(0,4); + u8x8.printf("WIFI: 0"); + #ifdef BLECOUNTER + u8x8.setCursor(0,3); + u8x8.printf("BLE: 0"); + #endif u8x8.setCursor(0,5); u8x8.printf(!cfg.rssilimit ? "RLIM: off" : "RLIM: %d", cfg.rssilimit); u8x8.drawString(0,6,"Join Wait "); @@ -516,16 +511,20 @@ salt_reset(); // get new 16bit for salting hashes xTaskCreatePinnedToCore(lorawan_loop, "loratask", 2048, ( void * ) 1, ( 5 | portPRIVILEGE_BIT ), NULL, 0); ESP_LOGI(TAG, "Starting Wifi task on core 0"); xTaskCreatePinnedToCore(wifi_sniffer_loop, "wifisniffer", 4096, ( void * ) 1, 1, NULL, 0); - ESP_LOGI(TAG, "Starting Bluetooth task on core 0"); - xTaskCreatePinnedToCore(bt_loop, "btscan", 2048, NULL, 5, NULL, 0); + #ifdef BLECOUNTER + ESP_LOGI(TAG, "Starting Bluetooth task on core 0"); + xTaskCreatePinnedToCore(bt_loop, "btscan", 2048, NULL, 5, NULL, 0); + #endif // to come here: code for switching off core 1 #else // run wifi task on core 0 and lora task on core 1 and bt task 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", 4096, ( void * ) 1, 1, NULL, 0); - ESP_LOGI(TAG, "Starting Bluetooth task on core 1"); - xTaskCreatePinnedToCore(bt_loop, "btscan", 2048, NULL, 5, NULL, 1); + #ifdef BLECOUNTER + ESP_LOGI(TAG, "Starting Bluetooth task on core 1"); + xTaskCreatePinnedToCore(bt_loop, "btscan", 2048, NULL, 5, NULL, 1); + #endif #endif // Finally: kickoff first sendjob and join, then send initial payload "0000" diff --git a/src/main.h b/src/main.h index a532af16..f7273bdd 100644 --- a/src/main.h +++ b/src/main.h @@ -1,7 +1,7 @@ #pragma once // program version - note: increment version after modifications to configData_t struct!! -#define PROGVERSION "1.2.95" // use max 10 chars here! +#define PROGVERSION "1.2.96" // use max 10 chars here! #define PROGNAME "PAXCNT" // Verbose enables serial output @@ -9,7 +9,7 @@ // 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 // BLE scan parameters #define BLESCANCYCLE 2 // BLE scan once after each wifi scans From d4c4f5b5328ccbb6ad84c90977ef65bc13808779 Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Sat, 14 Apr 2018 20:33:33 +0200 Subject: [PATCH 06/45] further fixes for refactoring BLE scan --- README.md | 14 +++++--------- src/configmanager.cpp | 12 ------------ src/globals.h | 1 - src/main.cpp | 24 +++++++++--------------- src/main.h | 2 +- src/rcommand.cpp | 7 +------ 6 files changed, 16 insertions(+), 44 deletions(-) diff --git a/README.md b/README.md index d5eb5b90..37890cc9 100644 --- a/README.md +++ b/README.md @@ -163,10 +163,7 @@ Note: all settings are stored in NVRAM and will be reloaded when device starts. 0 ... 255 duration of a BLE scan cycle in seconds e.g. 15 -> 1 cycle runs for 15 seconds [default] -0x0D set BLE scan cycle frequency - - run BLE scan once after 0 ... 255 full wifi scans - e.g. 2 -> BLE scan runs once after each 2nd wifi scan [default] +0x0D (unused) 0x0E set BLE scan mode @@ -197,11 +194,10 @@ device answers with it's current configuration. The configuration is a C structu byte 9: Wifi scan cycle duration 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 frequency, do once after (0..255) full wifi scans - byte 13: BLE scan mode (1=on, 0=0ff) - byte 14: Wifi antenna switch (0=internal, 1=external) - byte 15: RGB LED luminosity (0..100 %) - bytes 16-25: Software version (ASCII format) + byte 12: BLE scan mode (1=on, 0=0ff) + byte 13: Wifi antenna switch (0=internal, 1=external) + byte 14: RGB LED luminosity (0..100 %) + bytes 15-24: Software version (ASCII format) 0x81 get device uptime diff --git a/src/configmanager.cpp b/src/configmanager.cpp index 6227109e..6df43b4a 100644 --- a/src/configmanager.cpp +++ b/src/configmanager.cpp @@ -28,7 +28,6 @@ void defaultConfig() { cfg.wifiscancycle = SEND_SECS; // wifi scan cycle [seconds/2] cfg.wifichancycle = WIFI_CHANNEL_SWITCH_INTERVAL; // wifi channel switch cycle [seconds/100] cfg.blescantime = BLESCANTIME; // BLE scan cycle duration [seconds] - cfg.blescancycle = BLESCANCYCLE; // do a BLE scan after [BLESCANCYCLE] full Wifi scan cycles cfg.blescan = 1; // 0=disabled, 1=enabled cfg.wifiant = 0; // 0=internal, 1=external (for LoPy/LoPy4) cfg.rgblum = RGBLUMINOSITY; // RGB Led luminosity (0..100%) @@ -108,9 +107,6 @@ void saveConfig() { if( nvs_get_i8(my_handle, "blescantime", &flash8) != ESP_OK || flash8 != cfg.blescantime ) nvs_set_i8(my_handle, "blescantime", cfg.blescantime); - if( nvs_get_i8(my_handle, "blescancycle", &flash8) != ESP_OK || flash8 != cfg.blescancycle ) - nvs_set_i8(my_handle, "blescancycle", cfg.blescancycle); - if( nvs_get_i8(my_handle, "blescanmode", &flash8) != ESP_OK || flash8 != cfg.blescan ) nvs_set_i8(my_handle, "blescanmode", cfg.blescan); @@ -260,14 +256,6 @@ void loadConfig() { saveConfig(); } - if( nvs_get_i8(my_handle, "blescancycle", &flash8) == ESP_OK ) { - cfg.blescancycle = flash8; - ESP_LOGI(TAG, "blescancycle = %i", flash8); - } else { - ESP_LOGI(TAG, "BLEscancycle set to default %i", cfg.blescancycle); - saveConfig(); - } - if( nvs_get_i8(my_handle, "blescanmode", &flash8) == ESP_OK ) { cfg.blescan = flash8; ESP_LOGI(TAG, "BLEscanmode = %i", flash8); diff --git a/src/globals.h b/src/globals.h index 25b8d333..dc3b96fb 100644 --- a/src/globals.h +++ b/src/globals.h @@ -33,7 +33,6 @@ typedef struct { int8_t wifiscancycle; // wifi scan cycle [seconds/2] int8_t wifichancycle; // wifi channel switch cycle [seconds/100] int8_t blescantime; // BLE scan cycle duration [seconds] - int8_t blescancycle; // BLE scan frequency, once after [blescancycle] full wifi scans int8_t blescan; // 0=disabled, 1=enabled int8_t wifiant; // 0=internal, 1=external (for LoPy/LoPy4) int8_t rgblum; // RGB Led luminosity (0..100%) diff --git a/src/main.cpp b/src/main.cpp index e44c0cd4..1ee423e4 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -325,17 +325,7 @@ void sniffer_loop(void * pvParameters) { } } // end of send data cycle - else { - /* - #ifdef BLECOUNTER - if (nloop % (WIFI_CHANNEL_MAX * cfg.blescancycle) == 0 ) // once after cfg.blescancycle Wifi scans, do a BLE scan - if (cfg.blescan) { // execute BLE count if BLE function is enabled - BLECount(); // start BLE scan, this is a blocking call - } - #endif - */ - } // end of channel rotation loop - } // end of infinite wifi scan loop + } // end of infinite wifi channel rotation loop } /* end wifi specific parts ------------------------------------------------------------ */ @@ -512,8 +502,10 @@ salt_reset(); // get new 16bit for salting hashes ESP_LOGI(TAG, "Starting Wifi task on core 0"); xTaskCreatePinnedToCore(wifi_sniffer_loop, "wifisniffer", 4096, ( void * ) 1, 1, NULL, 0); #ifdef BLECOUNTER - ESP_LOGI(TAG, "Starting Bluetooth task on core 0"); - xTaskCreatePinnedToCore(bt_loop, "btscan", 2048, NULL, 5, NULL, 0); + if (cfg.blescan) { // start BLE task only if BLE function is enabled in NVRAM configuration + ESP_LOGI(TAG, "Starting Bluetooth task on core 1"); + xTaskCreatePinnedToCore(bt_loop, "btscan", 2048, NULL, 5, NULL, 0); + } #endif // to come here: code for switching off core 1 #else // run wifi task on core 0 and lora task on core 1 and bt task on core 1 @@ -522,8 +514,10 @@ salt_reset(); // get new 16bit for salting hashes ESP_LOGI(TAG, "Starting Wifi task on core 0"); xTaskCreatePinnedToCore(sniffer_loop, "wifisniffer", 4096, ( void * ) 1, 1, NULL, 0); #ifdef BLECOUNTER - ESP_LOGI(TAG, "Starting Bluetooth task on core 1"); - xTaskCreatePinnedToCore(bt_loop, "btscan", 2048, NULL, 5, NULL, 1); + if (cfg.blescan) { // start BLE task only if BLE function is enabled in NVRAM configuration + ESP_LOGI(TAG, "Starting Bluetooth task on core 1"); + xTaskCreatePinnedToCore(bt_loop, "btscan", 2048, NULL, 5, NULL, 1); + } #endif #endif diff --git a/src/main.h b/src/main.h index f7273bdd..85644298 100644 --- a/src/main.h +++ b/src/main.h @@ -1,7 +1,7 @@ #pragma once // program version - note: increment version after modifications to configData_t struct!! -#define PROGVERSION "1.2.96" // use max 10 chars here! +#define PROGVERSION "1.2.97" // use max 10 chars here! #define PROGNAME "PAXCNT" // Verbose enables serial output diff --git a/src/rcommand.cpp b/src/rcommand.cpp index b99fe35f..32099f57 100644 --- a/src/rcommand.cpp +++ b/src/rcommand.cpp @@ -110,11 +110,6 @@ void set_blescantime(int val) { ESP_LOGI(TAG, "Remote command: set BLE scan time to %i seconds", cfg.blescantime); }; -void set_blescancycle(int val) { - cfg.blescancycle = val; - ESP_LOGI(TAG, "Remote command: set BLE scan cycle to %i", cfg.blescancycle); -}; - void set_countmode(int val) { switch (val) { case 0: // cyclic unconfirmed @@ -251,7 +246,7 @@ cmd_t table[] = { {0x0a, set_wifiscancycle, true}, {0x0b, set_wifichancycle, true}, {0x0c, set_blescantime, true}, - {0x0d, set_blescancycle, true}, + {0x0d, set_noop, false}, {0x0e, set_blescan, true}, {0x0f, set_wifiant, true}, {0x10, set_rgblum, true}, From 5f3401519942f7a2be553269f27076f9201024e0 Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Sat, 14 Apr 2018 20:51:44 +0200 Subject: [PATCH 07/45] blescan.cpp: code sanitization --- src/blecsan.cpp | 25 ++++--------------------- 1 file changed, 4 insertions(+), 21 deletions(-) diff --git a/src/blecsan.cpp b/src/blecsan.cpp index 51dab5c5..e4caf769 100644 --- a/src/blecsan.cpp +++ b/src/blecsan.cpp @@ -264,17 +264,6 @@ esp_err_t register_ble_functionality(void) ESP_LOGI(TAG, "Set GAP scan parameters"); - // This function is called to set scan parameters. - status = esp_ble_gap_set_scan_params(&ble_scan_params); - if (status != ESP_OK) - { - ESP_LOGE(TAG, "esp_ble_gap_set_scan_params: rc=%d", status); - return ESP_FAIL; - } - - - ESP_LOGD(TAG, "We have registered what we need!"); - return ESP_OK ; } @@ -283,10 +272,9 @@ esp_err_t register_ble_functionality(void) void bt_loop(void *ignore) { esp_err_t status; - - ESP_LOGI(TAG, "Enabling Bluetooth Controller"); // Initialize BT controller to allocate task and other resource. + ESP_LOGI(TAG, "Enabling Bluetooth Controller..."); esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT(); if (esp_bt_controller_init(&bt_cfg) != ESP_OK) { @@ -300,12 +288,9 @@ void bt_loop(void *ignore) ESP_LOGE(TAG, "Bluetooth controller enable failed"); goto end; } - - ESP_LOGI(TAG, "Bluetooth Controller Enabled"); - - ESP_LOGI(TAG, "Init Bluetooth stack"); // Init and alloc the resource for bluetooth, must be prior to every bluetooth stuff + ESP_LOGI(TAG, "Init Bluetooth stack..."); status = esp_bluedroid_init(); if (status != ESP_OK) { @@ -321,9 +306,7 @@ void bt_loop(void *ignore) goto end; } - ESP_LOGI(TAG, "Bluetooth stack initialized"); - - ESP_LOGI(TAG, "Register BLE functionality"); + ESP_LOGI(TAG, "Register BLE functionality..."); status = register_ble_functionality(); if (status != ESP_OK) { @@ -333,7 +316,7 @@ void bt_loop(void *ignore) while(1) { - vTaskDelay(1000); + vTaskDelay(500); yield(); } From af0f26f4e804b6165cbf9c9fc349b3bd76c9e9c7 Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Sat, 14 Apr 2018 21:00:36 +0200 Subject: [PATCH 08/45] !REPAIR! of broken blescan.cpp --- src/blecsan.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/blecsan.cpp b/src/blecsan.cpp index e4caf769..65e58416 100644 --- a/src/blecsan.cpp +++ b/src/blecsan.cpp @@ -263,6 +263,14 @@ esp_err_t register_ble_functionality(void) }; ESP_LOGI(TAG, "Set GAP scan parameters"); + + // This function is called to set scan parameters. + status = esp_ble_gap_set_scan_params(&ble_scan_params); + if (status != ESP_OK) + { + ESP_LOGE(TAG, "esp_ble_gap_set_scan_params: rc=%d", status); + return ESP_FAIL; + } return ESP_OK ; } @@ -316,7 +324,7 @@ void bt_loop(void *ignore) while(1) { - vTaskDelay(500); + vTaskDelay(1000); yield(); } From ed8334d3e823d13fcfba63bf57ae0a2ddcec09db Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Sat, 14 Apr 2018 21:02:49 +0200 Subject: [PATCH 09/45] blescan.cpp: bt_loop speedup --- src/blecsan.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/blecsan.cpp b/src/blecsan.cpp index 65e58416..495f6e32 100644 --- a/src/blecsan.cpp +++ b/src/blecsan.cpp @@ -324,7 +324,7 @@ void bt_loop(void *ignore) while(1) { - vTaskDelay(1000); + vTaskDelay(500); yield(); } From f903a930c471cd94dd50168dcbe4e0bf4e4c76a5 Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Sat, 14 Apr 2018 21:20:45 +0200 Subject: [PATCH 10/45] !REPAIR! some more was broken in blescan.cpp --- platformio.ini | 6 +++--- src/blecsan.cpp | 3 +++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/platformio.ini b/platformio.ini index f5faf74d..faeb47a2 100644 --- a/platformio.ini +++ b/platformio.ini @@ -10,9 +10,9 @@ ; ---> SELECT TARGET PLATFORM HERE! <--- [platformio] -;env_default = heltec_wifi_lora_32 +env_default = heltec_wifi_lora_32 ;env_default = ttgov1 -env_default = ttgov2 +;env_default = ttgov2 ;env_default = lopy ;env_default = lopy4 ;env_default = lolin32lite_lora @@ -23,7 +23,7 @@ platform = espressif32 board = heltec_wifi_lora_32 framework = arduino monitor_baud = 115200 -upload_speed = 921600 +upload_speed = 115200 lib_deps = U8g2 build_flags = diff --git a/src/blecsan.cpp b/src/blecsan.cpp index 495f6e32..a37fdb8f 100644 --- a/src/blecsan.cpp +++ b/src/blecsan.cpp @@ -11,6 +11,8 @@ https://github.com/nkolban/esp32-snippets/tree/master/BLE/scanner #include #include #include +#include +#include // defined in macsniff.cpp bool mac_add(uint8_t *paddr, int8_t rssi, bool sniff_type); @@ -23,6 +25,7 @@ static const char *bt_event_type_to_string(uint32_t eventType); static const char *bt_gap_search_event_type_to_string(uint32_t searchEvt); static const char *bt_addr_t_to_string(esp_ble_addr_type_t type); static const char *bt_dev_type_to_string(esp_bt_dev_type_t type); +static const char *btsig_gap_type(uint32_t gap_type); static void gap_callback_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *param); // local Tag for logging From 666d2e0e32ce1ef3d482ed28d0f7992f8ac09bb2 Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Sat, 14 Apr 2018 21:42:30 +0200 Subject: [PATCH 11/45] fixes blescan.cpp & update readme.md --- README.md | 12 ++++++------ src/blecsan.cpp | 6 ++---- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 37890cc9..8979eb04 100644 --- a/README.md +++ b/README.md @@ -36,15 +36,15 @@ Hardware dependent settings (pinout etc.) are stored in board files in /hal dire Power consumption: -- Heltec ~650mW -- TTGOv1 ~650mW -- TTGOv2 ~670mW -- LoPy with expansion board: ~530mW -- LoPy pure, without expansion board: ~460mW +- Heltec ~720mW +- TTGOv1 TBD +- TTGOv2 ~990mW +- LoPy with expansion board: ~690mW +- LoPy pure, without expansion board: TBD - LoLin32 with [LoraNode32 shield](https://github.com/hallard/LoLin32-Lora): TBD - LoLin32 Lite with [LoraNode32-Lite shield](https://github.com/hallard/LoLin32-Lite-Lora): TBD -These results where metered with software version 1.2.0 during active wifi scan, no LoRa TX’ing, OLED display off, 5V USB powered. +These results where metered with software version 1.2.97 while continuously scanning wifi and ble, no LoRa TX’ing, OLED display (if present) on, 5V USB powered. # Building diff --git a/src/blecsan.cpp b/src/blecsan.cpp index a37fdb8f..69cbf5c3 100644 --- a/src/blecsan.cpp +++ b/src/blecsan.cpp @@ -14,18 +14,16 @@ https://github.com/nkolban/esp32-snippets/tree/master/BLE/scanner #include #include +#define BT_BD_ADDR_HEX(addr) addr[0], addr[1], addr[2], addr[3], addr[4], addr[5] + // defined in macsniff.cpp bool mac_add(uint8_t *paddr, int8_t rssi, bool sniff_type); -#define BT_BD_ADDR_STR "%02x:%02x:%02x:%02x:%02x:%02x" -#define BT_BD_ADDR_HEX(addr) addr[0], addr[1], addr[2], addr[3], addr[4], addr[5] - // Prototypes static const char *bt_event_type_to_string(uint32_t eventType); static const char *bt_gap_search_event_type_to_string(uint32_t searchEvt); static const char *bt_addr_t_to_string(esp_ble_addr_type_t type); static const char *bt_dev_type_to_string(esp_bt_dev_type_t type); -static const char *btsig_gap_type(uint32_t gap_type); static void gap_callback_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *param); // local Tag for logging From 4f8bb26fc079b24bed8ed0d4bb2ba5c2f41c009f Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Sun, 15 Apr 2018 00:51:28 +0200 Subject: [PATCH 12/45] blescan.cpp optimization --- platformio.ini | 7 +- src/blecsan.cpp | 194 ++++++++++++++++++++++++++---------------------- 2 files changed, 108 insertions(+), 93 deletions(-) diff --git a/platformio.ini b/platformio.ini index faeb47a2..4024a9f5 100644 --- a/platformio.ini +++ b/platformio.ini @@ -28,9 +28,10 @@ lib_deps = U8g2 build_flags = ;set log level, we need build_flag for this, otherwise we can't use ESP_LOGx in arduino framework - -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_INFO + -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_INFO ; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_VERBOSE ; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_NONE +; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_DEBUG ;override lora settings from LMiC library in lmic/config.h and use main.h instead -D_lmic_config_h_ -Dheltec_wifi_lora_32 @@ -135,7 +136,7 @@ framework = arduino monitor_baud = 115200 upload_speed = 256000 lib_deps = - U8g2 + U8g2@>2.21.7 SmartLeds build_flags = ;set log level, we need build_flag for this, otherwise we can't use ESP_LOGx in arduino framework @@ -157,7 +158,7 @@ framework = arduino monitor_baud = 115200 upload_speed = 921600 lib_deps = - U8g2 + U8g2@>2.21.7 SmartLeds build_flags = ;set log level, we need build_flag for this, otherwise we can't use ESP_LOGx in arduino framework diff --git a/src/blecsan.cpp b/src/blecsan.cpp index 69cbf5c3..0372c12f 100644 --- a/src/blecsan.cpp +++ b/src/blecsan.cpp @@ -16,6 +16,9 @@ https://github.com/nkolban/esp32-snippets/tree/master/BLE/scanner #define BT_BD_ADDR_HEX(addr) addr[0], addr[1], addr[2], addr[3], addr[4], addr[5] +// local Tag for logging +static const char *TAG = "bt_loop"; + // defined in macsniff.cpp bool mac_add(uint8_t *paddr, int8_t rssi, bool sniff_type); @@ -24,24 +27,20 @@ static const char *bt_event_type_to_string(uint32_t eventType); static const char *bt_gap_search_event_type_to_string(uint32_t searchEvt); static const char *bt_addr_t_to_string(esp_ble_addr_type_t type); static const char *bt_dev_type_to_string(esp_bt_dev_type_t type); -static void gap_callback_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *param); +static const char *btsig_gap_type(uint32_t gap_type); -// local Tag for logging -static const char *TAG = "bt_loop"; static void gap_callback_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *param) { ESP_LOGD(TAG, "Received a GAP event: %s", bt_event_type_to_string(event)); esp_ble_gap_cb_param_t *p = (esp_ble_gap_cb_param_t *)param; - esp_err_t status; - switch (event) { case ESP_GAP_BLE_SCAN_PARAM_SET_COMPLETE_EVT: { - ESP_LOGD(TAG, "status: %d", p->scan_param_cmpl.status); + ESP_LOGD(TAG, "Start Scan, status: %d", p->scan_param_cmpl.status); // This procedure keep the device scanning the peer device which advertising on the air. status = esp_ble_gap_start_scanning(BLESCANTIME); @@ -51,16 +50,6 @@ static void gap_callback_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_pa } } break; - - case ESP_GAP_BLE_SCAN_START_COMPLETE_EVT: - { - //scan start complete event to indicate scan start successfully or failed - if (param->scan_start_cmpl.status != ESP_BT_STATUS_SUCCESS) - { - ESP_LOGE(TAG, "Scan start failed"); - } - } - break; case ESP_GAP_BLE_SCAN_RESULT_EVT: { @@ -80,91 +69,71 @@ static void gap_callback_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_pa ESP_LOGI(TAG, "num_resps : %d", p->scan_rst.num_resps); - /* to be done here: - #ifdef VENDORFILTER - - filter BLE devices using their advertisements to get filter alternative to vendor OUI - if vendorfiltering is on, we ... - - want to count: mobile phones and tablets - - don't want to count: beacons, peripherals (earphones, headsets, printers), cars and machines - see - https://github.com/nkolban/ESP32_BLE_Arduino/blob/master/src/BLEAdvertisedDevice.cpp - - http://www.libelium.com/products/meshlium/smartphone-detection/ - - https://www.question-defense.com/2013/01/12/bluetooth-cod-bluetooth-class-of-deviceclass-of-service-explained - - https://www.bluetooth.com/specifications/assigned-numbers/baseband - - "The Class of Device (CoD) in case of Bluetooth which allows us to differentiate the type of - device (smartphone, handsfree, computer, LAN/network AP). With this parameter we can - differentiate among pedestrians and vehicles." - - #endif - */ - - // add this device and show new count total if it was not previously added - mac_add((uint8_t *) p->scan_rst.bda, p->scan_rst.rssi, MAC_SNIFF_BLE); - - if ( p->scan_rst.search_evt == ESP_GAP_SEARCH_INQ_CMPL_EVT) - { - // Scan is done. - - // The next 5 codelines automatically restarts the scan. + 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 (BLESCANTIME); if (status != ESP_OK) { ESP_LOGE(TAG, "esp_ble_gap_start_scanning: rc=%d", status); } - return; } - - if (p->scan_rst.search_evt == ESP_GAP_SEARCH_INQ_RES_EVT) + if (p->scan_rst.search_evt == ESP_GAP_SEARCH_INQ_RES_EVT) // Inquiry result for a peer device { + #ifdef VENDORFILTER + if ( (p->scan_rst.ble_addr_type == BLE_ADDR_TYPE_PUBLIC) || + (p->scan_rst.ble_addr_type == BLE_ADDR_TYPE_RPA_PUBLIC) + ) + { + #endif + + // add this device and show new count total if it was not previously added + mac_add((uint8_t *) p->scan_rst.bda, p->scan_rst.rssi, MAC_SNIFF_BLE); + + #ifdef VENDORFILTER + } + else + { + ESP_LOGI(TAG, "BLE device filtered"); + } + #endif + + + /* to be improved in vendorfilter if: + // you can search for elements in the payload using the // function esp_ble_resolve_adv_data() // // Like this, that scans for the "Complete name" (looking inside the payload buffer) - - uint8_t len; - uint8_t *data = esp_ble_resolve_adv_data(p->scan_rst.ble_adv, ESP_BLE_AD_TYPE_NAME_CMPL, &len); - ESP_LOGD(TAG, "len: %d, %.*s", len, len, data); - + // uint8_t len; + // uint8_t *data = esp_ble_resolve_adv_data(p->scan_rst.ble_adv, ESP_BLE_AD_TYPE_NAME_CMPL, &len); + + filter BLE devices using their advertisements to get filter alternative to vendor OUI + if vendorfiltering is on, we ... + - want to count: mobile phones and tablets + - don't want to count: beacons, peripherals (earphones, headsets, printers), cars and machines + see + https://github.com/nkolban/ESP32_BLE_Arduino/blob/master/src/BLEAdvertisedDevice.cpp + + http://www.libelium.com/products/meshlium/smartphone-detection/ + + https://www.question-defense.com/2013/01/12/bluetooth-cod-bluetooth-class-of-deviceclass-of-service-explained + + https://www.bluetooth.com/specifications/assigned-numbers/baseband + + "The Class of Device (CoD) in case of Bluetooth which allows us to differentiate the type of + device (smartphone, handsfree, computer, LAN/network AP). With this parameter we can + differentiate among pedestrians and vehicles." + + */ + } - ESP_LOGI(TAG, ""); - + } break; - case ESP_GAP_BLE_SCAN_STOP_COMPLETE_EVT: - { - if (param->scan_stop_cmpl.status != ESP_BT_STATUS_SUCCESS) - { - ESP_LOGE(TAG, "Scan stop failed"); - } - else - { - ESP_LOGI(TAG, "Stop scan successfully"); - } - } - - case ESP_GAP_BLE_ADV_STOP_COMPLETE_EVT: - { - if (param->adv_stop_cmpl.status != ESP_BT_STATUS_SUCCESS) - { - ESP_LOGE(TAG, "Adv stop failed"); - } - else - { - ESP_LOGI(TAG, "Stop adv successfully"); - } - } - break; - - default: break; } @@ -237,7 +206,51 @@ static const char *bt_event_type_to_string(uint32_t eventType) { } } // bt_event_type_to_string - +static const char *btsig_gap_type(uint32_t gap_type) { + switch (gap_type) + { + case 0x01: return "Flags"; + case 0x02: return "Incomplete List of 16-bit Service Class UUIDs"; + case 0x03: return "Complete List of 16-bit Service Class UUIDs"; + case 0x04: return "Incomplete List of 32-bit Service Class UUIDs"; + case 0x05: return "Complete List of 32-bit Service Class UUIDs"; + case 0x06: return "Incomplete List of 128-bit Service Class UUIDs"; + case 0x07: return "Complete List of 128-bit Service Class UUIDs"; + case 0x08: return "Shortened Local Name"; + case 0x09: return "Complete Local Name"; + case 0x0A: return "Tx Power Level"; + case 0x0D: return "Class of Device"; + case 0x0E: return "Simple Pairing Hash C/C-192"; + case 0x0F: return "Simple Pairing Randomizer R/R-192"; + case 0x10: return "Device ID/Security Manager TK Value"; + case 0x11: return "Security Manager Out of Band Flags"; + case 0x12: return "Slave Connection Interval Range"; + case 0x14: return "List of 16-bit Service Solicitation UUIDs"; + case 0x1F: return "List of 32-bit Service Solicitation UUIDs"; + case 0x15: return "List of 128-bit Service Solicitation UUIDs"; + case 0x16: return "Service Data - 16-bit UUID"; + case 0x20: return "Service Data - 32-bit UUID"; + case 0x21: return "Service Data - 128-bit UUID"; + case 0x22: return "LE Secure Connections Confirmation Value"; + case 0x23: return "LE Secure Connections Random Value"; + case 0x24: return "URI"; + case 0x25: return "Indoor Positioning"; + case 0x26: return "Transport Discovery Data"; + case 0x17: return "Public Target Address"; + case 0x18: return "Random Target Address"; + case 0x19: return "Appearance"; + case 0x1A: return "Advertising Interval"; + case 0x1B: return "LE Bluetooth Device Address"; + case 0x1C: return "LE Role"; + case 0x1D: return "Simple Pairing Hash C-256"; + case 0x1E: return "Simple Pairing Randomizer R-256"; + case 0x3D: return "3D Information Data"; + case 0xFF: return "Manufacturer Specific Data"; + + default: + return "Unknown type"; + } +} esp_err_t register_ble_functionality(void) { @@ -258,9 +271,10 @@ esp_err_t register_ble_functionality(void) { .scan_type = BLE_SCAN_TYPE_PASSIVE, .own_addr_type = BLE_ADDR_TYPE_PUBLIC, - .scan_filter_policy = BLE_SCAN_FILTER_ALLOW_ALL, - .scan_interval = (uint16_t) (BLESCANINTERVAL / 0.625), // Time = N * 0.625 msec - .scan_window = (uint16_t) (BLESCANWINDOW / 0.625) // Time = N * 0.625 msec + .scan_filter_policy = BLE_SCAN_FILTER_ALLOW_UND_RPA_DIR, + // .scan_filter_policy = BLE_SCAN_FILTER_ALLOW_ALL, + .scan_interval = (uint16_t) (BLESCANINTERVAL / 0.625), // Time = N * 0.625 msec + .scan_window = (uint16_t) (BLESCANWINDOW / 0.625) // Time = N * 0.625 msec }; ESP_LOGI(TAG, "Set GAP scan parameters"); @@ -283,7 +297,7 @@ void bt_loop(void *ignore) esp_err_t status; // Initialize BT controller to allocate task and other resource. - ESP_LOGI(TAG, "Enabling Bluetooth Controller..."); + ESP_LOGI(TAG, "Enabling Bluetooth Controller"); esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT(); if (esp_bt_controller_init(&bt_cfg) != ESP_OK) { @@ -299,7 +313,7 @@ void bt_loop(void *ignore) } // Init and alloc the resource for bluetooth, must be prior to every bluetooth stuff - ESP_LOGI(TAG, "Init Bluetooth stack..."); + ESP_LOGI(TAG, "Init Bluetooth stack"); status = esp_bluedroid_init(); if (status != ESP_OK) { @@ -315,7 +329,7 @@ void bt_loop(void *ignore) goto end; } - ESP_LOGI(TAG, "Register BLE functionality..."); + ESP_LOGI(TAG, "Register BLE functionality"); status = register_ble_functionality(); if (status != ESP_OK) { From e4afdf6c779115f2964c33f3fc5f16e857979192 Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Sun, 15 Apr 2018 01:04:39 +0200 Subject: [PATCH 13/45] blescan.cpp optimization --- src/blecsan.cpp | 22 +--------------------- 1 file changed, 1 insertion(+), 21 deletions(-) diff --git a/src/blecsan.cpp b/src/blecsan.cpp index 0372c12f..3b853595 100644 --- a/src/blecsan.cpp +++ b/src/blecsan.cpp @@ -23,16 +23,13 @@ static const char *TAG = "bt_loop"; bool mac_add(uint8_t *paddr, int8_t rssi, bool sniff_type); // Prototypes -static const char *bt_event_type_to_string(uint32_t eventType); static const char *bt_gap_search_event_type_to_string(uint32_t searchEvt); static const char *bt_addr_t_to_string(esp_ble_addr_type_t type); static const char *bt_dev_type_to_string(esp_bt_dev_type_t type); static const char *btsig_gap_type(uint32_t gap_type); - static void gap_callback_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *param) { - ESP_LOGD(TAG, "Received a GAP event: %s", bt_event_type_to_string(event)); esp_ble_gap_cb_param_t *p = (esp_ble_gap_cb_param_t *)param; esp_err_t status; @@ -53,7 +50,6 @@ static void gap_callback_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_pa case ESP_GAP_BLE_SCAN_RESULT_EVT: { - ESP_LOGI(TAG, "Device address (bda): %02x:%02x:%02x:%02x:%02x:%02x", BT_BD_ADDR_HEX(p->scan_rst.bda)); ESP_LOGI(TAG, "Device type : %s", bt_dev_type_to_string(p->scan_rst.dev_type)); ESP_LOGI(TAG, "Search_evt : %s", bt_gap_search_event_type_to_string(p->scan_rst.search_evt)); @@ -189,23 +185,6 @@ static const char *bt_gap_search_event_type_to_string(uint32_t searchEvt) { } // bt_gap_search_event_type_to_string /* - * Convert a BT GAP event type to a string representation. - */ -static const char *bt_event_type_to_string(uint32_t eventType) { - switch(eventType) { - case ESP_GAP_BLE_ADV_DATA_SET_COMPLETE_EVT: - return "ESP_GAP_BLE_ADV_DATA_SET_COMPLETE_EVT"; - case ESP_GAP_BLE_SCAN_PARAM_SET_COMPLETE_EVT: - return "ESP_GAP_BLE_SCAN_PARAM_SET_COMPLETE_EVT"; - case ESP_GAP_BLE_SCAN_RESULT_EVT: - return "ESP_GAP_BLE_SCAN_RESULT_EVT"; - case ESP_GAP_BLE_SCAN_RSP_DATA_SET_COMPLETE_EVT: - return "ESP_GAP_BLE_SCAN_RSP_DATA_SET_COMPLETE_EVT"; - default: - return "Unknown event type"; - } -} // bt_event_type_to_string - static const char *btsig_gap_type(uint32_t gap_type) { switch (gap_type) { @@ -251,6 +230,7 @@ static const char *btsig_gap_type(uint32_t gap_type) { return "Unknown type"; } } +*/ esp_err_t register_ble_functionality(void) { From 342f135d41e3d0683219d65bb62cc439f7054b1a Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Sun, 15 Apr 2018 01:21:13 +0200 Subject: [PATCH 14/45] main.h: removed BLESCANCYCLE --- src/main.h | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main.h b/src/main.h index 85644298..f33f7894 100644 --- a/src/main.h +++ b/src/main.h @@ -12,7 +12,6 @@ #define BLECOUNTER 1 // comment out if you don't want BLE count // BLE scan parameters -#define BLESCANCYCLE 2 // BLE scan once after each wifi scans #define BLESCANTIME 11 // [seconds] scan duration, 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 From 0b0dc9c02b42c9584e1a3fae46d1a358c3971702 Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Sun, 15 Apr 2018 12:12:06 +0200 Subject: [PATCH 15/45] v1.2.98 --- README.md | 16 ++- platformio.ini | 10 +- src/blecsan.cpp | 263 ++++++++++++++++++------------------------ src/configmanager.cpp | 12 ++ src/globals.h | 1 + src/macsniff.cpp | 12 +- src/main.cpp | 4 +- src/main.h | 2 +- src/rcommand.cpp | 10 +- 9 files changed, 161 insertions(+), 169 deletions(-) diff --git a/README.md b/README.md index 8979eb04..ceac836d 100644 --- a/README.md +++ b/README.md @@ -102,10 +102,10 @@ Multiple command/parameter pairs can be concatenated and sent in one single payl Note: all settings are stored in NVRAM and will be reloaded when device starts. To reset device to factory settings press button (if device has one), or send remote command 09 02 09 00 unconfirmed(!) once. -0x01 set Wifi scan RSSI limit +0x01 set scan RSSI limit - 1 ... 255 used for wifi scan radius (greater values increase wifi scan radius, values 50...110 make sense) - 0 = Wifi rssi limiter disabled [default] + 1 ... 255 used for wifi and bluetooth scan radius (greater values increase scan radius, values 50...110 make sense) + 0 = RSSI limiter disabled [default] 0x02 set counter mode @@ -163,7 +163,10 @@ Note: all settings are stored in NVRAM and will be reloaded when device starts. 0 ... 255 duration of a BLE scan cycle in seconds e.g. 15 -> 1 cycle runs for 15 seconds [default] -0x0D (unused) +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 @@ -196,8 +199,9 @@ device answers with it's current configuration. The configuration is a C structu byte 11: BLE scan cycle duration in seconds (0..255) byte 12: BLE scan mode (1=on, 0=0ff) byte 13: Wifi antenna switch (0=internal, 1=external) - byte 14: RGB LED luminosity (0..100 %) - bytes 15-24: Software version (ASCII format) + byte 14: Vendorfilter mode (0=disabled, 1=enabled) + byte 15: RGB LED luminosity (0..100 %) + bytes 16-25: Software version (ASCII format) 0x81 get device uptime diff --git a/platformio.ini b/platformio.ini index 4024a9f5..0d028868 100644 --- a/platformio.ini +++ b/platformio.ini @@ -10,9 +10,9 @@ ; ---> SELECT TARGET PLATFORM HERE! <--- [platformio] -env_default = heltec_wifi_lora_32 +;env_default = heltec_wifi_lora_32 ;env_default = ttgov1 -;env_default = ttgov2 +env_default = ttgov2 ;env_default = lopy ;env_default = lopy4 ;env_default = lolin32lite_lora @@ -55,6 +55,7 @@ build_flags = -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_INFO ; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_VERBOSE ; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_NONE +; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_DEBUG ;override lora settings from LMiC library in lmic/config.h and use main.h instead -Dttgov1 -D_lmic_config_h_ @@ -77,6 +78,7 @@ build_flags = -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_INFO ; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_VERBOSE ; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_NONE +; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_DEBUG ;override lora settings from LMiC library in lmic/config.h and use main.h instead -D_lmic_config_h_ -Dttgov2 @@ -99,6 +101,7 @@ build_flags = -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_INFO ; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_VERBOSE ; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_NONE +; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_DEBUG ;override lora settings from LMiC library in lmic/config.h and use main.h instead -Dlopy -D_lmic_config_h_ @@ -121,6 +124,7 @@ build_flags = -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_INFO ; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_VERBOSE ; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_NONE +; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_DEBUG ;override lora settings from LMiC library in lmic/config.h and use main.h instead -D_lmic_config_h_ -Dlopy4 @@ -143,6 +147,7 @@ build_flags = -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_INFO ; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_VERBOSE ; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_NONE +; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_DEBUG ;override lora settings from LMiC library in lmic/config.h and use main.h instead -D_lmic_config_h_ -Dlolin32lite_lora @@ -165,6 +170,7 @@ build_flags = -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_INFO ; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_VERBOSE ; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_NONE +; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_DEBUG ;override lora settings from LMiC library in lmic/config.h and use main.h instead -D_lmic_config_h_ -Dlolin32_lora diff --git a/src/blecsan.cpp b/src/blecsan.cpp index 3b853595..df3287bf 100644 --- a/src/blecsan.cpp +++ b/src/blecsan.cpp @@ -23,130 +23,9 @@ static const char *TAG = "bt_loop"; bool mac_add(uint8_t *paddr, int8_t rssi, bool sniff_type); // Prototypes -static const char *bt_gap_search_event_type_to_string(uint32_t searchEvt); static const char *bt_addr_t_to_string(esp_ble_addr_type_t type); -static const char *bt_dev_type_to_string(esp_bt_dev_type_t type); static const char *btsig_gap_type(uint32_t gap_type); - -static void gap_callback_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *param) -{ - esp_ble_gap_cb_param_t *p = (esp_ble_gap_cb_param_t *)param; - esp_err_t status; - - switch (event) - { - case ESP_GAP_BLE_SCAN_PARAM_SET_COMPLETE_EVT: - { - ESP_LOGD(TAG, "Start Scan, status: %d", p->scan_param_cmpl.status); - - // This procedure keep the device scanning the peer device which advertising on the air. - status = esp_ble_gap_start_scanning(BLESCANTIME); - if (status != ESP_OK) - { - ESP_LOGE(TAG, "esp_ble_gap_start_scanning: rc=%d", status); - } - } - break; - - case ESP_GAP_BLE_SCAN_RESULT_EVT: - { - ESP_LOGI(TAG, "Device address (bda): %02x:%02x:%02x:%02x:%02x:%02x", BT_BD_ADDR_HEX(p->scan_rst.bda)); - ESP_LOGI(TAG, "Device type : %s", bt_dev_type_to_string(p->scan_rst.dev_type)); - ESP_LOGI(TAG, "Search_evt : %s", bt_gap_search_event_type_to_string(p->scan_rst.search_evt)); - ESP_LOGI(TAG, "Addr_type : %s", bt_addr_t_to_string(p->scan_rst.ble_addr_type)); - ESP_LOGI(TAG, "RSSI : %d", p->scan_rst.rssi); - ESP_LOGI(TAG, "Flag : %d", p->scan_rst.flag); - - //bit 0 (OFF) LE Limited Discoverable Mode - //bit 1 (OFF) LE General Discoverable Mode - //bit 2 (ON) BR/EDR Not Supported - //bit 3 (OFF) Simultaneous LE and BR/EDR to Same Device Capable (controller) - //bit 4 (OFF) Simultaneous LE and BR/EDR to Same Device Capable (Host) - - ESP_LOGI(TAG, "num_resps : %d", p->scan_rst.num_resps); - - 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 (BLESCANTIME); - if (status != ESP_OK) - { - ESP_LOGE(TAG, "esp_ble_gap_start_scanning: rc=%d", status); - } - return; - } - - if (p->scan_rst.search_evt == ESP_GAP_SEARCH_INQ_RES_EVT) // Inquiry result for a peer device - { - - #ifdef VENDORFILTER - if ( (p->scan_rst.ble_addr_type == BLE_ADDR_TYPE_PUBLIC) || - (p->scan_rst.ble_addr_type == BLE_ADDR_TYPE_RPA_PUBLIC) - ) - { - #endif - - // add this device and show new count total if it was not previously added - mac_add((uint8_t *) p->scan_rst.bda, p->scan_rst.rssi, MAC_SNIFF_BLE); - - #ifdef VENDORFILTER - } - else - { - ESP_LOGI(TAG, "BLE device filtered"); - } - #endif - - - /* to be improved in vendorfilter if: - - // you can search for elements in the payload using the - // function esp_ble_resolve_adv_data() - // - // Like this, that scans for the "Complete name" (looking inside the payload buffer) - // uint8_t len; - // uint8_t *data = esp_ble_resolve_adv_data(p->scan_rst.ble_adv, ESP_BLE_AD_TYPE_NAME_CMPL, &len); - - filter BLE devices using their advertisements to get filter alternative to vendor OUI - if vendorfiltering is on, we ... - - want to count: mobile phones and tablets - - don't want to count: beacons, peripherals (earphones, headsets, printers), cars and machines - see - https://github.com/nkolban/ESP32_BLE_Arduino/blob/master/src/BLEAdvertisedDevice.cpp - - http://www.libelium.com/products/meshlium/smartphone-detection/ - - https://www.question-defense.com/2013/01/12/bluetooth-cod-bluetooth-class-of-deviceclass-of-service-explained - - https://www.bluetooth.com/specifications/assigned-numbers/baseband - - "The Class of Device (CoD) in case of Bluetooth which allows us to differentiate the type of - device (smartphone, handsfree, computer, LAN/network AP). With this parameter we can - differentiate among pedestrians and vehicles." - - */ - - } - - } - break; - - default: - break; - } -} // gap_callback_handler - -static const char *bt_dev_type_to_string(esp_bt_dev_type_t type) { - switch(type) { - case ESP_BT_DEVICE_TYPE_BREDR: - return "ESP_BT_DEVICE_TYPE_BREDR"; - case ESP_BT_DEVICE_TYPE_BLE: - return "ESP_BT_DEVICE_TYPE_BLE"; - case ESP_BT_DEVICE_TYPE_DUMO: - return "ESP_BT_DEVICE_TYPE_DUMO"; - default: - return "Unknown"; - } -} // bt_dev_type_to_string +static void gap_callback_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *param); static const char *bt_addr_t_to_string(esp_ble_addr_type_t type) { switch(type) { @@ -163,28 +42,6 @@ static const char *bt_addr_t_to_string(esp_ble_addr_type_t type) { } } // bt_addr_t_to_string -static const char *bt_gap_search_event_type_to_string(uint32_t searchEvt) { - switch(searchEvt) { - case ESP_GAP_SEARCH_INQ_RES_EVT: - return "ESP_GAP_SEARCH_INQ_RES_EVT"; - case ESP_GAP_SEARCH_INQ_CMPL_EVT: - return "ESP_GAP_SEARCH_INQ_CMPL_EVT"; - case ESP_GAP_SEARCH_DISC_RES_EVT: - return "ESP_GAP_SEARCH_DISC_RES_EVT"; - case ESP_GAP_SEARCH_DISC_BLE_RES_EVT: - return "ESP_GAP_SEARCH_DISC_BLE_RES_EVT"; - case ESP_GAP_SEARCH_DISC_CMPL_EVT: - return "ESP_GAP_SEARCH_DISC_CMPL_EVT"; - case ESP_GAP_SEARCH_DI_DISC_CMPL_EVT: - return "ESP_GAP_SEARCH_DI_DISC_CMPL_EVT"; - case ESP_GAP_SEARCH_SEARCH_CANCEL_CMPL_EVT: - return "ESP_GAP_SEARCH_SEARCH_CANCEL_CMPL_EVT"; - default: - return "Unknown event type"; - } -} // bt_gap_search_event_type_to_string - -/* static const char *btsig_gap_type(uint32_t gap_type) { switch (gap_type) { @@ -229,9 +86,107 @@ static const char *btsig_gap_type(uint32_t gap_type) { default: return "Unknown type"; } -} -*/ - +} // btsig_gap_type + + +static void gap_callback_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *param) +{ + esp_ble_gap_cb_param_t *p = (esp_ble_gap_cb_param_t *)param; + esp_err_t status; + + ESP_LOGD(tag, "BT payload sniffed -> type: 0x%.2x -> %s", *p->scan_rst.ble_adv, btsig_gap_type(*p->scan_rst.ble_adv)); + + + switch (event) + { + case ESP_GAP_BLE_SCAN_PARAM_SET_COMPLETE_EVT: + { // restart scan + status = esp_ble_gap_start_scanning(BLESCANTIME); + if (status != ESP_OK) + { + ESP_LOGE(TAG, "esp_ble_gap_start_scanning: rc=%d", status); + } + } + break; + + case ESP_GAP_BLE_SCAN_RESULT_EVT: + { + 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 (BLESCANTIME); + if (status != ESP_OK) + { + ESP_LOGE(TAG, "esp_ble_gap_start_scanning: rc=%d", status); + } + return; + } + + if (p->scan_rst.search_evt == ESP_GAP_SEARCH_INQ_RES_EVT) // Inquiry result for a peer device + { // evaluate sniffed packet + ESP_LOGD(TAG, "Device address (bda): %02x:%02x:%02x:%02x:%02x:%02x", BT_BD_ADDR_HEX(p->scan_rst.bda)); + ESP_LOGD(TAG, "Addr_type : %s", bt_addr_t_to_string(p->scan_rst.ble_addr_type)); + ESP_LOGD(TAG, "RSSI : %d", p->scan_rst.rssi); + + if (!( cfg.rssilimit == 0 ) || (p->scan_rst.rssi > cfg.rssilimit )) { // rssi is negative value + ESP_LOGI(TAG, "BLTH RSSI %d -> ignoring (limit: %d)", p->scan_rst.rssi, cfg.rssilimit); + break; + } + + #ifdef VENDORFILTER + + if (p->scan_rst.ble_addr_type == BLE_ADDR_TYPE_RANDOM) goto skip; + if (p->scan_rst.ble_addr_type == BLE_ADDR_TYPE_RPA_RANDOM) goto skip; + + #endif + + // add this device and show new count total if it was not previously added + mac_add((uint8_t *) p->scan_rst.bda, p->scan_rst.rssi, MAC_SNIFF_BLE); + break; + + skip: + ESP_LOGD(TAG, "BT device filtered"); + break; + + + /* to be improved in vendorfilter if: + + // you can search for elements in the payload using the + // function esp_ble_resolve_adv_data() + // + // Like this, that scans for the "Complete name" (looking inside the payload buffer) + // uint8_t len; + // uint8_t *data = esp_ble_resolve_adv_data(p->scan_rst.ble_adv, ESP_BLE_AD_TYPE_NAME_CMPL, &len); + + filter BLE devices using their advertisements to get filter alternative to vendor OUI + if vendorfiltering is on, we ... + - want to count: mobile phones and tablets + - don't want to count: beacons, peripherals (earphones, headsets, printers), cars and machines + see + https://github.com/nkolban/ESP32_BLE_Arduino/blob/master/src/BLEAdvertisedDevice.cpp + + http://www.libelium.com/products/meshlium/smartphone-detection/ + + https://www.question-defense.com/2013/01/12/bluetooth-cod-bluetooth-class-of-deviceclass-of-service-explained + + https://www.bluetooth.com/specifications/assigned-numbers/baseband + + "The Class of Device (CoD) in case of Bluetooth which allows us to differentiate the type of + device (smartphone, handsfree, computer, LAN/network AP). With this parameter we can + differentiate among pedestrians and vehicles." + + */ + + } + + } + break; + + default: + break; + } +} // gap_callback_handler + + esp_err_t register_ble_functionality(void) { esp_err_t status; @@ -250,14 +205,20 @@ esp_err_t register_ble_functionality(void) static esp_ble_scan_params_t ble_scan_params = { .scan_type = BLE_SCAN_TYPE_PASSIVE, - .own_addr_type = BLE_ADDR_TYPE_PUBLIC, - .scan_filter_policy = BLE_SCAN_FILTER_ALLOW_UND_RPA_DIR, - // .scan_filter_policy = BLE_SCAN_FILTER_ALLOW_ALL, + .own_addr_type = BLE_ADDR_TYPE_RANDOM, + + #ifdef VENDORFILTER + .scan_filter_policy = BLE_SCAN_FILTER_ALLOW_WLIST_PRA_DIR, + // ADV_IND, ADV_NONCONN_IND, ADV_SCAN_IND packets are used for broadcasting + // data in broadcast applications (e.g., Beacons), so we don't want them in vendorfilter mode + #else + .scan_filter_policy = BLE_SCAN_FILTER_ALLOW_ALL, + #endif .scan_interval = (uint16_t) (BLESCANINTERVAL / 0.625), // Time = N * 0.625 msec .scan_window = (uint16_t) (BLESCANWINDOW / 0.625) // Time = N * 0.625 msec }; - ESP_LOGI(TAG, "Set GAP scan parameters"); + ESP_LOGI(TAG, "Set GAP scan parameters"); // This function is called to set scan parameters. status = esp_ble_gap_set_scan_params(&ble_scan_params); diff --git a/src/configmanager.cpp b/src/configmanager.cpp index 6df43b4a..650c3d93 100644 --- a/src/configmanager.cpp +++ b/src/configmanager.cpp @@ -30,6 +30,7 @@ void defaultConfig() { cfg.blescantime = BLESCANTIME; // BLE scan cycle duration [seconds] cfg.blescan = 1; // 0=disabled, 1=enabled cfg.wifiant = 0; // 0=internal, 1=external (for LoPy/LoPy4) + cfg.vendorfilter = 1; // 0=disabled, 1=enabled cfg.rgblum = RGBLUMINOSITY; // RGB Led luminosity (0..100%) strncpy( cfg.version, PROGVERSION, sizeof(cfg.version)-1 ); @@ -113,6 +114,9 @@ void saveConfig() { if( nvs_get_i8(my_handle, "wifiant", &flash8) != ESP_OK || flash8 != cfg.wifiant ) nvs_set_i8(my_handle, "wifiant", cfg.wifiant); + if( nvs_get_i8(my_handle, "vendorfilter", &flash8) != ESP_OK || flash8 != cfg.vendorfilter ) + nvs_set_i8(my_handle, "vendorfilter", cfg.vendorfilter); + if( nvs_get_i8(my_handle, "rgblum", &flash8) != ESP_OK || flash8 != cfg.rgblum ) nvs_set_i8(my_handle, "rgblum", cfg.rgblum); @@ -240,6 +244,14 @@ void loadConfig() { saveConfig(); } + if( nvs_get_i8(my_handle, "vendorfilter", &flash8) == ESP_OK ) { + cfg.vendorfilter = flash8; + ESP_LOGI(TAG, "vendorfilter = %i", flash8); + } else { + ESP_LOGI(TAG, "Vendorfilter mode set to default %i", cfg.vendorfilter); + saveConfig(); + } + if( nvs_get_i8(my_handle, "rgblum", &flash8) == ESP_OK ) { cfg.rgblum = flash8; ESP_LOGI(TAG, "rgbluminosity = %i", flash8); diff --git a/src/globals.h b/src/globals.h index dc3b96fb..e032839a 100644 --- a/src/globals.h +++ b/src/globals.h @@ -35,6 +35,7 @@ typedef struct { int8_t blescantime; // BLE scan cycle duration [seconds] int8_t blescan; // 0=disabled, 1=enabled int8_t wifiant; // 0=internal, 1=external (for LoPy/LoPy4) + int8_t vendorfilter; // 0=disabled, 1=enabled int8_t rgblum; // RGB Led luminosity (0..100%) char version[10]; // Firmware version } configData_t; diff --git a/src/macsniff.cpp b/src/macsniff.cpp index 0664f179..20e42c00 100644 --- a/src/macsniff.cpp +++ b/src/macsniff.cpp @@ -34,7 +34,7 @@ bool mac_add(uint8_t *paddr, int8_t rssi, bool sniff_type) { #ifdef VENDORFILTER vendor2int = ( (uint32_t)paddr[2] ) | ( (uint32_t)paddr[1] << 8 ) | ( (uint32_t)paddr[0] << 16 ); - // No vendor filter for BLE + // use OUI vendor filter list only on Wifi, not on BLE if ( (sniff_type==MAC_SNIFF_BLE) || std::find(vendors.begin(), vendors.end(), vendor2int) != vendors.end() ) { #endif @@ -65,7 +65,7 @@ bool mac_add(uint8_t *paddr, int8_t rssi, bool sniff_type) { rgb_set_color(COLOR_MAGENTA); bles.insert(hashedmac); // add hashed MAC to BLE container u8x8.setCursor(0,3); - u8x8.printf("BLE: %-4d", (int) bles.size()); + u8x8.printf("BLTH: %-4d", (int) bles.size()); } #endif @@ -74,8 +74,8 @@ bool mac_add(uint8_t *paddr, int8_t rssi, bool sniff_type) { rgb_set_color(COLOR_NONE); } - ESP_LOGI(TAG, "%s RSSI %ddBi -> MAC %s -> Hash %04X -> WiFi:%d BLE:%d %s", - sniff_type==MAC_SNIFF_WIFI ? "WiFi":"BLE ", + ESP_LOGI(TAG, "%s RSSI %ddBi -> MAC %s -> Hash %04X -> WiFi:%d BLTH:%d %s", + sniff_type==MAC_SNIFF_WIFI ? "WiFi":"BLTH", rssi, buff, hashedmac, (int) wifis.size(), #ifdef BLECOUNTER @@ -83,12 +83,12 @@ bool mac_add(uint8_t *paddr, int8_t rssi, bool sniff_type) { #else 0, #endif - added ? "New" : "Already seen"); + added ? "new" : "known"); #ifdef VENDORFILTER } else { // Very noisy - //ESP_LOGI(TAG, "Filtered MAC %02X:%02X:%02X:%02X:%02X:%02X", paddr[0],paddr[1],paddr[2],paddr[3],paddr[5],paddr[5]); + ESP_LOGD(TAG, "Filtered MAC %02X:%02X:%02X:%02X:%02X:%02X", paddr[0],paddr[1],paddr[2],paddr[3],paddr[5],paddr[5]); } #endif diff --git a/src/main.cpp b/src/main.cpp index 1ee423e4..16444cf4 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -270,7 +270,7 @@ void sniffer_loop(void * pvParameters) { yield(); channel = (channel % WIFI_CHANNEL_MAX) + 1; // rotates variable channel 1..WIFI_CHANNEL_MAX wifi_sniffer_set_channel(channel); - ESP_LOGI(TAG, "Wifi set channel %d", channel); + ESP_LOGD(TAG, "Wifi set channel %d", channel); snprintf(buff, sizeof(buff), "PAX:%d", (int) macs.size()); // convert 16-bit MAC counter to decimal counter value u8x8.draw2x2String(0, 0, buff); // display number on unique macs total @@ -476,7 +476,7 @@ void setup() { u8x8.printf("WIFI: 0"); #ifdef BLECOUNTER u8x8.setCursor(0,3); - u8x8.printf("BLE: 0"); + u8x8.printf("BLTH: 0"); #endif u8x8.setCursor(0,5); u8x8.printf(!cfg.rssilimit ? "RLIM: off" : "RLIM: %d", cfg.rssilimit); diff --git a/src/main.h b/src/main.h index f33f7894..0aef700d 100644 --- a/src/main.h +++ b/src/main.h @@ -1,7 +1,7 @@ #pragma once // program version - note: increment version after modifications to configData_t struct!! -#define PROGVERSION "1.2.97" // use max 10 chars here! +#define PROGVERSION "1.2.98" // use max 10 chars here! #define PROGNAME "PAXCNT" // Verbose enables serial output diff --git a/src/rcommand.cpp b/src/rcommand.cpp index 32099f57..ff80add8 100644 --- a/src/rcommand.cpp +++ b/src/rcommand.cpp @@ -182,6 +182,14 @@ void set_wifiant(int val) { #endif }; +void set_vendorfilter(int val) { + ESP_LOGI(TAG, "Remote command: set vendorfilter mode to %s", val ? "on" : "off"); + switch (val) { + case 1: cfg.vendorfilter = val; break; + default: cfg.vendorfilter = 0; break; + } +}; + void set_rgblum(int val) { // Avoid wrong parameters cfg.rgblum = (val>=0 && val<=100) ? (uint8_t) val : RGBLUMINOSITY; @@ -246,7 +254,7 @@ cmd_t table[] = { {0x0a, set_wifiscancycle, true}, {0x0b, set_wifichancycle, true}, {0x0c, set_blescantime, true}, - {0x0d, set_noop, false}, + {0x0d, set_vendorfilter, false}, {0x0e, set_blescan, true}, {0x0f, set_wifiant, true}, {0x10, set_rgblum, true}, From 34d32df2489e1ea2e3d8dad3a87eee6f81e0da62 Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Sun, 15 Apr 2018 13:59:37 +0200 Subject: [PATCH 16/45] changed core 1->0; increased stack size for bt task -> 8192 --- src/macsniff.cpp | 2 +- src/main.cpp | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/macsniff.cpp b/src/macsniff.cpp index 20e42c00..94f52020 100644 --- a/src/macsniff.cpp +++ b/src/macsniff.cpp @@ -88,7 +88,7 @@ bool mac_add(uint8_t *paddr, int8_t rssi, bool sniff_type) { #ifdef VENDORFILTER } else { // Very noisy - ESP_LOGD(TAG, "Filtered MAC %02X:%02X:%02X:%02X:%02X:%02X", paddr[0],paddr[1],paddr[2],paddr[3],paddr[5],paddr[5]); + // ESP_LOGD(TAG, "Filtered MAC %02X:%02X:%02X:%02X:%02X:%02X", paddr[0],paddr[1],paddr[2],paddr[3],paddr[5],paddr[5]); } #endif diff --git a/src/main.cpp b/src/main.cpp index 16444cf4..6a50a728 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -504,11 +504,11 @@ salt_reset(); // get new 16bit for salting hashes #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 1"); - xTaskCreatePinnedToCore(bt_loop, "btscan", 2048, NULL, 5, NULL, 0); + xTaskCreatePinnedToCore(bt_loop, "btscan", 8192, NULL, 5, NULL, 0); } #endif // to come here: code for switching off core 1 -#else // run wifi task on core 0 and lora task on core 1 and bt task on core 1 +#else // run wifi task on core 0 and lora task on core 1 and bt task on core 0 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"); @@ -516,7 +516,7 @@ salt_reset(); // get new 16bit for salting hashes #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 1"); - xTaskCreatePinnedToCore(bt_loop, "btscan", 2048, NULL, 5, NULL, 1); + xTaskCreatePinnedToCore(bt_loop, "btscan", 8192, NULL, 5, NULL, 0); } #endif #endif From 77dc71ed13bb58355788ee084601a6c96e0a72dd Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Sun, 15 Apr 2018 14:06:25 +0200 Subject: [PATCH 17/45] blescan.cpp: removed delay in bt_loop task --- platformio.ini | 4 ++-- src/blecsan.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/platformio.ini b/platformio.ini index 0d028868..cb04f45b 100644 --- a/platformio.ini +++ b/platformio.ini @@ -75,9 +75,9 @@ lib_deps = U8g2 build_flags = ;set log level, we need build_flag for this, otherwise we can't use ESP_LOGx in arduino framework - -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_INFO +; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_INFO ; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_VERBOSE -; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_NONE + -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_NONE ; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_DEBUG ;override lora settings from LMiC library in lmic/config.h and use main.h instead -D_lmic_config_h_ diff --git a/src/blecsan.cpp b/src/blecsan.cpp index df3287bf..a25b5ce9 100644 --- a/src/blecsan.cpp +++ b/src/blecsan.cpp @@ -280,7 +280,7 @@ void bt_loop(void *ignore) while(1) { - vTaskDelay(500); + //vTaskDelay(500); yield(); } From 31f7c6351a02a4c21ac634611bc3f05a71df5311 Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Sun, 15 Apr 2018 14:25:14 +0200 Subject: [PATCH 18/45] platformio.ini: defaults changed --- platformio.ini | 44 ++++++++++++++++---------------------------- 1 file changed, 16 insertions(+), 28 deletions(-) diff --git a/platformio.ini b/platformio.ini index cb04f45b..ac82926b 100644 --- a/platformio.ini +++ b/platformio.ini @@ -18,6 +18,9 @@ env_default = ttgov2 ;env_default = lolin32lite_lora ;env_default = lolin32_lora +; ---> NOTE: For production run set DEBUG_LEVEL level to NONE! <--- +; otherwise device may crash in dense environments due to serial buffer overflow + [env:heltec_wifi_lora_32] platform = espressif32 board = heltec_wifi_lora_32 @@ -28,17 +31,15 @@ lib_deps = U8g2 build_flags = ;set log level, we need build_flag for this, otherwise we can't use ESP_LOGx in arduino framework - -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_INFO +; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_INFO ; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_VERBOSE -; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_NONE + -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_NONE ; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_DEBUG ;override lora settings from LMiC library in lmic/config.h and use main.h instead -D_lmic_config_h_ -Dheltec_wifi_lora_32 -include "src/main.h" -include "src/hal/heltec.h" -;FreeRTOS single core operation, switches off core 1 (see arduino-esp32/cores/esp32/main.cpp) -; -DCONFIG_FREERTOS_UNICORE [env:ttgov1] platform = espressif32 @@ -52,18 +53,15 @@ lib_deps = U8g2 build_flags = ;set log level, we need build_flag for this, otherwise we can't use ESP_LOGx in arduino framework - -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_INFO +; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_INFO ; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_VERBOSE -; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_NONE + -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_NONE ; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_DEBUG ;override lora settings from LMiC library in lmic/config.h and use main.h instead -Dttgov1 -D_lmic_config_h_ -include "src/main.h" -include "src/hal/ttgov1.h" -;FreeRTOS single core operation, switches off core 1 (see arduino-esp32/cores/esp32/main.cpp) -; -DCONFIG_FREERTOS_UNICORE - [env:ttgov2] platform = espressif32 @@ -84,8 +82,6 @@ build_flags = -Dttgov2 -include "src/main.h" -include "src/hal/ttgov2.h" -;FreeRTOS single core operation, switches off core 1 (see arduino-esp32/cores/esp32/main.cpp) -; -DCONFIG_FREERTOS_UNICORE [env:lopy] platform = espressif32 @@ -98,17 +94,15 @@ lib_deps = SmartLeds build_flags = ;set log level, we need build_flag for this, otherwise we can't use ESP_LOGx in arduino framework - -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_INFO +; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_INFO ; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_VERBOSE -; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_NONE + -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_NONE ; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_DEBUG ;override lora settings from LMiC library in lmic/config.h and use main.h instead -Dlopy -D_lmic_config_h_ -include "src/main.h" -include "src/hal/lopy.h" -;FreeRTOS single core operation, switches off core 1 (see arduino-esp32/cores/esp32/main.cpp) -; -DCONFIG_FREERTOS_UNICORE [env:lopy4] platform = espressif32 @@ -121,17 +115,15 @@ lib_deps = SmartLeds build_flags = ;set log level, we need build_flag for this, otherwise we can't use ESP_LOGx in arduino framework - -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_INFO +; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_INFO ; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_VERBOSE -; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_NONE + -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_NONE ; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_DEBUG ;override lora settings from LMiC library in lmic/config.h and use main.h instead -D_lmic_config_h_ -Dlopy4 -include "src/main.h" -include "src/hal/lopy4.h" -;FreeRTOS single core operation, switches off core 1 (see arduino-esp32/cores/esp32/main.cpp) -; -DCONFIG_FREERTOS_UNICORE [env:lolin32lite_lora] platform = espressif32 @@ -144,17 +136,15 @@ lib_deps = SmartLeds build_flags = ;set log level, we need build_flag for this, otherwise we can't use ESP_LOGx in arduino framework - -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_INFO +; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_INFO ; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_VERBOSE -; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_NONE + -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_NONE ; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_DEBUG ;override lora settings from LMiC library in lmic/config.h and use main.h instead -D_lmic_config_h_ -Dlolin32lite_lora -include "src/main.h" -include "src/hal/lolin32lite_lora.h" -;FreeRTOS single core operation, switches off core 1 (see arduino-esp32/cores/esp32/main.cpp) -; -DCONFIG_FREERTOS_UNICORE [env:lolin32_lora] platform = espressif32 @@ -167,14 +157,12 @@ lib_deps = SmartLeds build_flags = ;set log level, we need build_flag for this, otherwise we can't use ESP_LOGx in arduino framework - -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_INFO +; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_INFO ; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_VERBOSE -; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_NONE + -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_NONE ; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_DEBUG ;override lora settings from LMiC library in lmic/config.h and use main.h instead -D_lmic_config_h_ -Dlolin32_lora -include "src/main.h" - -include "src/hal/lolin32_lora.h" -;FreeRTOS single core operation, switches off core 1 (see arduino-esp32/cores/esp32/main.cpp) -; -DCONFIG_FREERTOS_UNICORE + -include "src/hal/lolin32_lora.h" \ No newline at end of file From 441204236efaedabf5c8bdc62e864d1b40846c8b Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Sun, 15 Apr 2018 14:32:26 +0200 Subject: [PATCH 19/45] main.cpp: single core option removed --- src/main.cpp | 34 ++++++++++------------------------ 1 file changed, 10 insertions(+), 24 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 6a50a728..9c820c60 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -495,30 +495,16 @@ 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 salt_reset(); // get new 16bit for salting hashes -// Start FreeRTOS tasks -#if CONFIG_FREERTOS_UNICORE // run all tasks on core 0 and switch off core 1 - ESP_LOGI(TAG, "Starting Lora task on core 0"); - xTaskCreatePinnedToCore(lorawan_loop, "loratask", 2048, ( void * ) 1, ( 5 | portPRIVILEGE_BIT ), NULL, 0); - ESP_LOGI(TAG, "Starting Wifi task on core 0"); - xTaskCreatePinnedToCore(wifi_sniffer_loop, "wifisniffer", 4096, ( void * ) 1, 1, NULL, 0); - #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 1"); - xTaskCreatePinnedToCore(bt_loop, "btscan", 8192, NULL, 5, NULL, 0); - } - #endif - // to come here: code for switching off core 1 -#else // run wifi task on core 0 and lora task on core 1 and bt task on core 0 - 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", 4096, ( void * ) 1, 1, NULL, 0); - #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 1"); - xTaskCreatePinnedToCore(bt_loop, "btscan", 8192, NULL, 5, NULL, 0); - } - #endif +// run wifi task on core 0 and lora task on core 1 and bt task on core 0 +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", 4096, ( void * ) 1, 1, NULL, 0); +#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", 8192, NULL, 5, NULL, 0); + } #endif // Finally: kickoff first sendjob and join, then send initial payload "0000" From 524adaf8b534eaf119746fe9ac9ed98fe129cec1 Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Sun, 15 Apr 2018 18:05:36 +0200 Subject: [PATCH 20/45] !REPAIR! blescan.cpp: delay(500) back; otherwise watchdog triggers --- src/blecsan.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/blecsan.cpp b/src/blecsan.cpp index a25b5ce9..df3287bf 100644 --- a/src/blecsan.cpp +++ b/src/blecsan.cpp @@ -280,7 +280,7 @@ void bt_loop(void *ignore) while(1) { - //vTaskDelay(500); + vTaskDelay(500); yield(); } From 009aa1686a21c0f651c6d90a78521250501e9873 Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Sun, 15 Apr 2018 18:15:31 +0200 Subject: [PATCH 21/45] platformio.ini: amendments --- platformio.ini | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/platformio.ini b/platformio.ini index ac82926b..2793ccc1 100644 --- a/platformio.ini +++ b/platformio.ini @@ -17,9 +17,7 @@ env_default = ttgov2 ;env_default = lopy4 ;env_default = lolin32lite_lora ;env_default = lolin32_lora - -; ---> NOTE: For production run set DEBUG_LEVEL level to NONE! <--- -; otherwise device may crash in dense environments due to serial buffer overflow +description = Paxcounter is a proof-of-concept ESP32 device for metering passenger flows in realtime. It counts how many mobile devices are around. [env:heltec_wifi_lora_32] platform = espressif32 @@ -31,6 +29,8 @@ lib_deps = U8g2 build_flags = ;set log level, we need build_flag for this, otherwise we can't use ESP_LOGx in arduino framework +; ---> NOTE: For production run set DEBUG_LEVEL level to NONE! <--- +; otherwise device may crash in dense environments due to serial buffer overflow ; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_INFO ; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_VERBOSE -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_NONE @@ -53,6 +53,8 @@ lib_deps = U8g2 build_flags = ;set log level, we need build_flag for this, otherwise we can't use ESP_LOGx in arduino framework +; ---> NOTE: For production run set DEBUG_LEVEL level to NONE! <--- +; otherwise device may crash in dense environments due to serial buffer overflow ; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_INFO ; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_VERBOSE -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_NONE @@ -73,6 +75,8 @@ lib_deps = U8g2 build_flags = ;set log level, we need build_flag for this, otherwise we can't use ESP_LOGx in arduino framework +; ---> NOTE: For production run set DEBUG_LEVEL level to NONE! <--- +; otherwise device may crash in dense environments due to serial buffer overflow ; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_INFO ; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_VERBOSE -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_NONE @@ -94,6 +98,8 @@ lib_deps = SmartLeds build_flags = ;set log level, we need build_flag for this, otherwise we can't use ESP_LOGx in arduino framework +; ---> NOTE: For production run set DEBUG_LEVEL level to NONE! <--- +; otherwise device may crash in dense environments due to serial buffer overflow ; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_INFO ; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_VERBOSE -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_NONE @@ -115,6 +121,8 @@ lib_deps = SmartLeds build_flags = ;set log level, we need build_flag for this, otherwise we can't use ESP_LOGx in arduino framework +; ---> NOTE: For production run set DEBUG_LEVEL level to NONE! <--- +; otherwise device may crash in dense environments due to serial buffer overflow ; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_INFO ; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_VERBOSE -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_NONE @@ -136,6 +144,8 @@ lib_deps = SmartLeds build_flags = ;set log level, we need build_flag for this, otherwise we can't use ESP_LOGx in arduino framework +; ---> NOTE: For production run set DEBUG_LEVEL level to NONE! <--- +; otherwise device may crash in dense environments due to serial buffer overflow ; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_INFO ; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_VERBOSE -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_NONE @@ -157,6 +167,8 @@ lib_deps = SmartLeds build_flags = ;set log level, we need build_flag for this, otherwise we can't use ESP_LOGx in arduino framework +; ---> NOTE: For production run set DEBUG_LEVEL level to NONE! <--- +; otherwise device may crash in dense environments due to serial buffer overflow ; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_INFO ; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_VERBOSE -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_NONE From d3bbd46f7901fe6dd05f1f3f9befb0bef0997b38 Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Sun, 15 Apr 2018 18:19:47 +0200 Subject: [PATCH 22/45] delays in loop_tasks adjusted --- src/blecsan.cpp | 2 +- src/macsniff.cpp | 1 - src/main.cpp | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/blecsan.cpp b/src/blecsan.cpp index df3287bf..d6277941 100644 --- a/src/blecsan.cpp +++ b/src/blecsan.cpp @@ -280,7 +280,7 @@ void bt_loop(void *ignore) while(1) { - vTaskDelay(500); + vTaskDelay(500/portTICK_PERIOD_MS); yield(); } diff --git a/src/macsniff.cpp b/src/macsniff.cpp index 94f52020..15684615 100644 --- a/src/macsniff.cpp +++ b/src/macsniff.cpp @@ -124,6 +124,5 @@ void wifi_sniffer_packet_handler(void* buff, wifi_promiscuous_pkt_type_t type) { } else { ESP_LOGI(TAG, "WiFi RSSI %d -> ignoring (limit: %d)", ppkt->rx_ctrl.rssi, cfg.rssilimit); } - //yield(); } diff --git a/src/main.cpp b/src/main.cpp index 9c820c60..06f832bb 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -530,7 +530,7 @@ void loop() { } else #endif - { vTaskDelay(1000/portTICK_PERIOD_MS); + { vTaskDelay(500/portTICK_PERIOD_MS); uptimecounter = uptime() / 1000; // count uptime seconds } } From a3e26cad9178462449673dc5fe33fb1105ffa165 Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Sun, 15 Apr 2018 18:31:58 +0200 Subject: [PATCH 23/45] platformio.ini: U8G2 set to 2.22.10 (newer have compiler warning) --- platformio.ini | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/platformio.ini b/platformio.ini index 2793ccc1..d395cfdb 100644 --- a/platformio.ini +++ b/platformio.ini @@ -26,7 +26,7 @@ framework = arduino monitor_baud = 115200 upload_speed = 115200 lib_deps = - U8g2 + U8g2@2.22.10 build_flags = ;set log level, we need build_flag for this, otherwise we can't use ESP_LOGx in arduino framework ; ---> NOTE: For production run set DEBUG_LEVEL level to NONE! <--- @@ -50,7 +50,7 @@ monitor_baud = 115200 upload_speed = 921600 ;upload_port = COM15 lib_deps = - U8g2 + U8g2@2.22.10 build_flags = ;set log level, we need build_flag for this, otherwise we can't use ESP_LOGx in arduino framework ; ---> NOTE: For production run set DEBUG_LEVEL level to NONE! <--- @@ -72,7 +72,7 @@ framework = arduino monitor_baud = 115200 upload_speed = 921600 lib_deps = - U8g2 + U8g2@2.22.10 build_flags = ;set log level, we need build_flag for this, otherwise we can't use ESP_LOGx in arduino framework ; ---> NOTE: For production run set DEBUG_LEVEL level to NONE! <--- @@ -94,7 +94,7 @@ framework = arduino monitor_baud = 115200 upload_speed = 921600 lib_deps = - U8g2@>2.21.7 + U8g2@2.22.10 SmartLeds build_flags = ;set log level, we need build_flag for this, otherwise we can't use ESP_LOGx in arduino framework @@ -117,7 +117,7 @@ framework = arduino monitor_baud = 115200 upload_speed = 921600 lib_deps = - U8g2@>2.21.7 + U8g2@2.22.10 SmartLeds build_flags = ;set log level, we need build_flag for this, otherwise we can't use ESP_LOGx in arduino framework @@ -140,7 +140,7 @@ framework = arduino monitor_baud = 115200 upload_speed = 256000 lib_deps = - U8g2@>2.21.7 + U8g2@2.22.10 SmartLeds build_flags = ;set log level, we need build_flag for this, otherwise we can't use ESP_LOGx in arduino framework @@ -163,7 +163,7 @@ framework = arduino monitor_baud = 115200 upload_speed = 921600 lib_deps = - U8g2@>2.21.7 + U8g2@2.22.10 SmartLeds build_flags = ;set log level, we need build_flag for this, otherwise we can't use ESP_LOGx in arduino framework From 24eed4a55ed3c46c5c07744a370c7a5bf0c98152 Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Sun, 15 Apr 2018 18:54:23 +0200 Subject: [PATCH 24/45] main.cpp: small change in main loop --- src/main.cpp | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 06f832bb..ad92f973 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -520,20 +520,22 @@ do_send(&sendjob); // Arduino main moop, runs on core 1 // https://techtutorialsx.com/2017/05/09/esp32-get-task-execution-core/ void loop() { + while(1) { -#ifdef HAS_BUTTON - if (ButtonTriggered) { - ButtonTriggered = false; - ESP_LOGI(TAG, "Button pressed, resetting device to factory defaults"); - eraseConfig(); - esp_restart(); - } - else -#endif - { vTaskDelay(500/portTICK_PERIOD_MS); - uptimecounter = uptime() / 1000; // count uptime seconds - } + + #ifdef HAS_BUTTON + if (ButtonTriggered) { + ButtonTriggered = false; + ESP_LOGI(TAG, "Button pressed, resetting device to factory defaults"); + eraseConfig(); + esp_restart(); + } + #endif + + vTaskDelay(500/portTICK_PERIOD_MS); + uptimecounter = uptime() / 1000; // count uptime seconds } + } /* end Aruino LOOP ------------------------------------------------------------ */ From a0564f36070b5a2ba7459f04ed367d0e920c6af2 Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Sun, 15 Apr 2018 20:20:35 +0200 Subject: [PATCH 25/45] blescan.cpp: bluefi_api removed (unneeded) --- src/blecsan.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/blecsan.cpp b/src/blecsan.cpp index d6277941..29319acc 100644 --- a/src/blecsan.cpp +++ b/src/blecsan.cpp @@ -11,7 +11,6 @@ https://github.com/nkolban/esp32-snippets/tree/master/BLE/scanner #include #include #include -#include #include #define BT_BD_ADDR_HEX(addr) addr[0], addr[1], addr[2], addr[3], addr[4], addr[5] From 46bb3edff7972b1a3d2af72eafaf5cd322dd199f Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Sun, 15 Apr 2018 20:41:12 +0200 Subject: [PATCH 26/45] platformio.ini cleanup --- platformio.ini | 117 +++++++++++++++---------------------------------- 1 file changed, 36 insertions(+), 81 deletions(-) diff --git a/platformio.ini b/platformio.ini index d395cfdb..60659fd7 100644 --- a/platformio.ini +++ b/platformio.ini @@ -17,8 +17,28 @@ env_default = ttgov2 ;env_default = lopy4 ;env_default = lolin32lite_lora ;env_default = lolin32_lora +; description = Paxcounter is a proof-of-concept ESP32 device for metering passenger flows in realtime. It counts how many mobile devices are around. +[common_env_data] +build_flags = +; we need build_flag for logging, otherwise we can't use ESP_LOGx in arduino framework +; ---> NOTE: For production run set DEBUG_LEVEL level to NONE! <--- +; otherwise device may crash in dense environments due to serial buffer overflow +; +; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_INFO +; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_VERBOSE +; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_NONE + -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_DEBUG +; +;override lora settings from LMiC library in lmic/config.h and use main.h instead + -D_lmic_config_h_ + -include "src/main.h" +; +lib_deps_builtin = + U8g2@2.22.10 + + [env:heltec_wifi_lora_32] platform = espressif32 board = heltec_wifi_lora_32 @@ -26,19 +46,10 @@ framework = arduino monitor_baud = 115200 upload_speed = 115200 lib_deps = - U8g2@2.22.10 + ${common_env_data.lib_deps_builtin} build_flags = -;set log level, we need build_flag for this, otherwise we can't use ESP_LOGx in arduino framework -; ---> NOTE: For production run set DEBUG_LEVEL level to NONE! <--- -; otherwise device may crash in dense environments due to serial buffer overflow -; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_INFO -; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_VERBOSE - -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_NONE -; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_DEBUG -;override lora settings from LMiC library in lmic/config.h and use main.h instead - -D_lmic_config_h_ + ${common_env_data.build_flags} -Dheltec_wifi_lora_32 - -include "src/main.h" -include "src/hal/heltec.h" [env:ttgov1] @@ -46,23 +57,12 @@ platform = espressif32 board = esp32dev framework = arduino monitor_baud = 115200 -; On my V1, upload does not works over default 115200 -upload_speed = 921600 -;upload_port = COM15 +upload_speed = 115200 lib_deps = - U8g2@2.22.10 + ${common_env_data.lib_deps_builtin} build_flags = -;set log level, we need build_flag for this, otherwise we can't use ESP_LOGx in arduino framework -; ---> NOTE: For production run set DEBUG_LEVEL level to NONE! <--- -; otherwise device may crash in dense environments due to serial buffer overflow -; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_INFO -; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_VERBOSE - -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_NONE -; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_DEBUG -;override lora settings from LMiC library in lmic/config.h and use main.h instead + ${common_env_data.build_flags} -Dttgov1 - -D_lmic_config_h_ - -include "src/main.h" -include "src/hal/ttgov1.h" [env:ttgov2] @@ -72,19 +72,10 @@ framework = arduino monitor_baud = 115200 upload_speed = 921600 lib_deps = - U8g2@2.22.10 + ${common_env_data.lib_deps_builtin} build_flags = -;set log level, we need build_flag for this, otherwise we can't use ESP_LOGx in arduino framework -; ---> NOTE: For production run set DEBUG_LEVEL level to NONE! <--- -; otherwise device may crash in dense environments due to serial buffer overflow -; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_INFO -; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_VERBOSE - -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_NONE -; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_DEBUG -;override lora settings from LMiC library in lmic/config.h and use main.h instead - -D_lmic_config_h_ + ${common_env_data.build_flags} -Dttgov2 - -include "src/main.h" -include "src/hal/ttgov2.h" [env:lopy] @@ -94,20 +85,11 @@ framework = arduino monitor_baud = 115200 upload_speed = 921600 lib_deps = - U8g2@2.22.10 + ${common_env_data.lib_deps_builtin} SmartLeds build_flags = -;set log level, we need build_flag for this, otherwise we can't use ESP_LOGx in arduino framework -; ---> NOTE: For production run set DEBUG_LEVEL level to NONE! <--- -; otherwise device may crash in dense environments due to serial buffer overflow -; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_INFO -; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_VERBOSE - -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_NONE -; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_DEBUG -;override lora settings from LMiC library in lmic/config.h and use main.h instead + ${common_env_data.build_flags} -Dlopy - -D_lmic_config_h_ - -include "src/main.h" -include "src/hal/lopy.h" [env:lopy4] @@ -117,20 +99,11 @@ framework = arduino monitor_baud = 115200 upload_speed = 921600 lib_deps = - U8g2@2.22.10 - SmartLeds + ${common_env_data.lib_deps_builtin} + SmartLeds build_flags = -;set log level, we need build_flag for this, otherwise we can't use ESP_LOGx in arduino framework -; ---> NOTE: For production run set DEBUG_LEVEL level to NONE! <--- -; otherwise device may crash in dense environments due to serial buffer overflow -; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_INFO -; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_VERBOSE - -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_NONE -; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_DEBUG -;override lora settings from LMiC library in lmic/config.h and use main.h instead - -D_lmic_config_h_ + ${common_env_data.build_flags} -Dlopy4 - -include "src/main.h" -include "src/hal/lopy4.h" [env:lolin32lite_lora] @@ -140,20 +113,11 @@ framework = arduino monitor_baud = 115200 upload_speed = 256000 lib_deps = - U8g2@2.22.10 + ${common_env_data.lib_deps_builtin} SmartLeds build_flags = -;set log level, we need build_flag for this, otherwise we can't use ESP_LOGx in arduino framework -; ---> NOTE: For production run set DEBUG_LEVEL level to NONE! <--- -; otherwise device may crash in dense environments due to serial buffer overflow -; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_INFO -; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_VERBOSE - -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_NONE -; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_DEBUG -;override lora settings from LMiC library in lmic/config.h and use main.h instead - -D_lmic_config_h_ + ${common_env_data.build_flags} -Dlolin32lite_lora - -include "src/main.h" -include "src/hal/lolin32lite_lora.h" [env:lolin32_lora] @@ -163,18 +127,9 @@ framework = arduino monitor_baud = 115200 upload_speed = 921600 lib_deps = - U8g2@2.22.10 + ${common_env_data.lib_deps_builtin} SmartLeds build_flags = -;set log level, we need build_flag for this, otherwise we can't use ESP_LOGx in arduino framework -; ---> NOTE: For production run set DEBUG_LEVEL level to NONE! <--- -; otherwise device may crash in dense environments due to serial buffer overflow -; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_INFO -; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_VERBOSE - -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_NONE -; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_DEBUG -;override lora settings from LMiC library in lmic/config.h and use main.h instead - -D_lmic_config_h_ + ${common_env_data.build_flags} -Dlolin32_lora - -include "src/main.h" -include "src/hal/lolin32_lora.h" \ No newline at end of file From 43c06bb94f53fad8f4f328e4f3237fc3d10423a3 Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Sun, 15 Apr 2018 20:58:08 +0200 Subject: [PATCH 27/45] blescsn.cpp: esp_blufi_api.h include added again (*is* needed) --- src/blecsan.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/blecsan.cpp b/src/blecsan.cpp index 29319acc..d6277941 100644 --- a/src/blecsan.cpp +++ b/src/blecsan.cpp @@ -11,6 +11,7 @@ https://github.com/nkolban/esp32-snippets/tree/master/BLE/scanner #include #include #include +#include #include #define BT_BD_ADDR_HEX(addr) addr[0], addr[1], addr[2], addr[3], addr[4], addr[5] From 01e81b35811eb6b0f7371eaa7630748f8facc683 Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Sun, 15 Apr 2018 21:02:29 +0200 Subject: [PATCH 28/45] blescan.cpp: comment added --- src/blecsan.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/blecsan.cpp b/src/blecsan.cpp index d6277941..415ec045 100644 --- a/src/blecsan.cpp +++ b/src/blecsan.cpp @@ -11,7 +11,7 @@ https://github.com/nkolban/esp32-snippets/tree/master/BLE/scanner #include #include #include -#include +#include // needed for BLE_ADDR types, do not remove #include #define BT_BD_ADDR_HEX(addr) addr[0], addr[1], addr[2], addr[3], addr[4], addr[5] @@ -94,8 +94,7 @@ static void gap_callback_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_pa esp_ble_gap_cb_param_t *p = (esp_ble_gap_cb_param_t *)param; esp_err_t status; - ESP_LOGD(tag, "BT payload sniffed -> type: 0x%.2x -> %s", *p->scan_rst.ble_adv, btsig_gap_type(*p->scan_rst.ble_adv)); - + ESP_LOGD(tag, "BT payload rcvd -> type: 0x%.2x -> %s", *p->scan_rst.ble_adv, btsig_gap_type(*p->scan_rst.ble_adv)); switch (event) { From b6b8ac800316b3f3d216c40309f87e6efc030733 Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Sun, 15 Apr 2018 21:48:55 +0200 Subject: [PATCH 29/45] platformio.ini: set defaults --- platformio.ini | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/platformio.ini b/platformio.ini index 60659fd7..8f4d829a 100644 --- a/platformio.ini +++ b/platformio.ini @@ -10,9 +10,9 @@ ; ---> SELECT TARGET PLATFORM HERE! <--- [platformio] -;env_default = heltec_wifi_lora_32 +env_default = heltec_wifi_lora_32 ;env_default = ttgov1 -env_default = ttgov2 +;env_default = ttgov2 ;env_default = lopy ;env_default = lopy4 ;env_default = lolin32lite_lora @@ -28,8 +28,8 @@ build_flags = ; ; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_INFO ; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_VERBOSE -; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_NONE - -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_DEBUG + -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_NONE +; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_DEBUG ; ;override lora settings from LMiC library in lmic/config.h and use main.h instead -D_lmic_config_h_ From 130fefd49d617c61421ea55d5bf5e2bb1bc5ec80 Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Sun, 15 Apr 2018 22:21:30 +0200 Subject: [PATCH 30/45] centralize display writes (part 1) --- platformio.ini | 4 ++-- src/macsniff.cpp | 14 +++++++------- src/main.cpp | 49 +++++++++++++++++++++++++++++++----------------- src/main.h | 3 +++ 4 files changed, 44 insertions(+), 26 deletions(-) diff --git a/platformio.ini b/platformio.ini index 8f4d829a..f37e652b 100644 --- a/platformio.ini +++ b/platformio.ini @@ -10,9 +10,9 @@ ; ---> SELECT TARGET PLATFORM HERE! <--- [platformio] -env_default = heltec_wifi_lora_32 +;nv_default = heltec_wifi_lora_32 ;env_default = ttgov1 -;env_default = ttgov2 +env_default = ttgov2 ;env_default = lopy ;env_default = lopy4 ;env_default = lolin32lite_lora diff --git a/src/macsniff.cpp b/src/macsniff.cpp index 15684615..a377d01b 100644 --- a/src/macsniff.cpp +++ b/src/macsniff.cpp @@ -50,22 +50,22 @@ bool mac_add(uint8_t *paddr, int8_t rssi, bool sniff_type) { // Insert only if it was not found on global count if (added) { - char buff[16]; - snprintf(buff, sizeof(buff), "PAX:%-4d", (int) macs.size()); // convert 16-bit MAC counter to decimal counter value - u8x8.draw2x2String(0, 0, buff); // display number on unique macs total Wifi + BLE + //char buff[16]; + //snprintf(buff, sizeof(buff), "PAX:%-4d", (int) macs.size()); // convert 16-bit MAC counter to decimal counter value + //u8x8.draw2x2String(0, 0, buff); // display number on unique macs total Wifi + BLE if (sniff_type == MAC_SNIFF_WIFI ) { rgb_set_color(COLOR_GREEN); wifis.insert(hashedmac); // add hashed MAC to wifi container - u8x8.setCursor(0,4); - u8x8.printf("WIFI: %-4d", (int) wifis.size()); + //u8x8.setCursor(0,4); + //u8x8.printf("WIFI: %-4d", (int) wifis.size()); } #ifdef BLECOUNTER else if (sniff_type == MAC_SNIFF_BLE ) { rgb_set_color(COLOR_MAGENTA); bles.insert(hashedmac); // add hashed MAC to BLE container - u8x8.setCursor(0,3); - u8x8.printf("BLTH: %-4d", (int) bles.size()); + //u8x8.setCursor(0,3); + //u8x8.printf("BLTH: %-4d", (int) bles.size()); } #endif diff --git a/src/main.cpp b/src/main.cpp index ad92f973..73ebc35f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -45,6 +45,7 @@ configData_t cfg; // struct holds current device configuration osjob_t sendjob, initjob; // LMIC // Initialize global variables +uint8_t channel = 0; int macnum = 0; uint64_t uptimecounter = 0; bool joinstate = false; @@ -258,7 +259,7 @@ void bt_loop(void *ignore); void sniffer_loop(void * pvParameters) { configASSERT( ( ( uint32_t ) pvParameters ) == 1 ); // FreeRTOS check - uint8_t channel=0; + channel=0; char buff[16]; int nloop=0, lorawait=0; @@ -271,7 +272,7 @@ void sniffer_loop(void * pvParameters) { channel = (channel % WIFI_CHANNEL_MAX) + 1; // rotates variable channel 1..WIFI_CHANNEL_MAX wifi_sniffer_set_channel(channel); ESP_LOGD(TAG, "Wifi set channel %d", channel); - +/* snprintf(buff, sizeof(buff), "PAX:%d", (int) macs.size()); // convert 16-bit MAC counter to decimal counter value u8x8.draw2x2String(0, 0, buff); // display number on unique macs total @@ -279,7 +280,7 @@ void sniffer_loop(void * pvParameters) { u8x8.printf("ch:%02i", channel); u8x8.setCursor(0,5); u8x8.printf(!cfg.rssilimit ? "RLIM: off" : "RLIM: %-3d", cfg.rssilimit); - +*/ // duration of one wifi scan loop reached? then send data and begin new scan cycle if ( nloop >= ( (100 / cfg.wifichancycle) * (cfg.wifiscancycle * 2)) +1 ) { u8x8.setPowerSave(!cfg.screenon); // set display on if enabled @@ -499,11 +500,11 @@ salt_reset(); // get new 16bit for salting hashes 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", 4096, ( void * ) 1, 1, NULL, 0); +xTaskCreatePinnedToCore(sniffer_loop, "wifisniffer", 16384, ( void * ) 1, 1, NULL, 0); #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", 8192, NULL, 5, NULL, 0); + xTaskCreatePinnedToCore(bt_loop, "btscan", 16384, NULL, 5, NULL, 0); } #endif @@ -521,20 +522,34 @@ do_send(&sendjob); // https://techtutorialsx.com/2017/05/09/esp32-get-task-execution-core/ void loop() { - while(1) { + #ifdef HAS_BUTTON + if (ButtonTriggered) { + ButtonTriggered = false; + ESP_LOGI(TAG, "Button pressed, resetting device to factory defaults"); + eraseConfig(); + esp_restart(); + } + #endif - #ifdef HAS_BUTTON - if (ButtonTriggered) { - ButtonTriggered = false; - ESP_LOGI(TAG, "Button pressed, resetting device to factory defaults"); - eraseConfig(); - esp_restart(); - } - #endif - - vTaskDelay(500/portTICK_PERIOD_MS); + #ifdef HAS_DISPLAY + // display counters(lines 0-4) + char buff[16]; + snprintf(buff, sizeof(buff), "PAX:%-4d", (int) macs.size()); // convert 16-bit MAC counter to decimal counter value + u8x8.draw2x2String(0, 0, buff); // display number on unique macs total Wifi + BLE + u8x8.setCursor(0,4); + u8x8.printf("WIFI: %-4d", (int) wifis.size()); + u8x8.setCursor(0,3); + u8x8.printf("BLTH: %-4d", (int) bles.size()); + // display actual wifi channel (line 4) + u8x8.setCursor(11,4); + u8x8.printf("ch:%02i", channel); + // display RSSI status (line 5) + u8x8.setCursor(0,5); + u8x8.printf(!cfg.rssilimit ? "RLIM: off" : "RLIM: %-3d", cfg.rssilimit); + #endif + + vTaskDelay(DISPLAYREFRESH/portTICK_PERIOD_MS); uptimecounter = uptime() / 1000; // count uptime seconds - } } diff --git a/src/main.h b/src/main.h index 0aef700d..358096b2 100644 --- a/src/main.h +++ b/src/main.h @@ -46,6 +46,9 @@ // Default RGB LED luminosity (in %) #define RGBLUMINOSITY 30 // 30% +// OLED Display refresh cycle (in Milliseconds) +#define DISPLAYREFRESH 200 // 200ms + // LMIC settings // define hardware independent LMIC settings here, settings of standard library in /lmic/config.h will be ignored // define hardware specifics settings in platformio.ini as build_flag for hardware environment From 3efd3890f39034f2dcb50d1156542fe57749c1e1 Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Sun, 15 Apr 2018 22:31:19 +0200 Subject: [PATCH 31/45] centralize display writes (part 2) --- src/macsniff.cpp | 16 ++++------------ src/main.cpp | 16 +++++----------- 2 files changed, 9 insertions(+), 23 deletions(-) diff --git a/src/macsniff.cpp b/src/macsniff.cpp index a377d01b..6084d6be 100644 --- a/src/macsniff.cpp +++ b/src/macsniff.cpp @@ -50,22 +50,14 @@ bool mac_add(uint8_t *paddr, int8_t rssi, bool sniff_type) { // Insert only if it was not found on global count if (added) { - //char buff[16]; - //snprintf(buff, sizeof(buff), "PAX:%-4d", (int) macs.size()); // convert 16-bit MAC counter to decimal counter value - //u8x8.draw2x2String(0, 0, buff); // display number on unique macs total Wifi + BLE - if (sniff_type == MAC_SNIFF_WIFI ) { rgb_set_color(COLOR_GREEN); wifis.insert(hashedmac); // add hashed MAC to wifi container - //u8x8.setCursor(0,4); - //u8x8.printf("WIFI: %-4d", (int) wifis.size()); - } + } #ifdef BLECOUNTER - else if (sniff_type == MAC_SNIFF_BLE ) { - rgb_set_color(COLOR_MAGENTA); - bles.insert(hashedmac); // add hashed MAC to BLE container - //u8x8.setCursor(0,3); - //u8x8.printf("BLTH: %-4d", (int) bles.size()); + else if (sniff_type == MAC_SNIFF_BLE ) { + rgb_set_color(COLOR_MAGENTA); + bles.insert(hashedmac); // add hashed MAC to BLE container } #endif diff --git a/src/main.cpp b/src/main.cpp index 73ebc35f..c3dd607c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -272,15 +272,7 @@ void sniffer_loop(void * pvParameters) { channel = (channel % WIFI_CHANNEL_MAX) + 1; // rotates variable channel 1..WIFI_CHANNEL_MAX wifi_sniffer_set_channel(channel); ESP_LOGD(TAG, "Wifi set channel %d", channel); -/* - snprintf(buff, sizeof(buff), "PAX:%d", (int) macs.size()); // convert 16-bit MAC counter to decimal counter value - u8x8.draw2x2String(0, 0, buff); // display number on unique macs total - - u8x8.setCursor(11,4); - u8x8.printf("ch:%02i", channel); - u8x8.setCursor(0,5); - u8x8.printf(!cfg.rssilimit ? "RLIM: off" : "RLIM: %-3d", cfg.rssilimit); -*/ + // duration of one wifi scan loop reached? then send data and begin new scan cycle if ( nloop >= ( (100 / cfg.wifichancycle) * (cfg.wifiscancycle * 2)) +1 ) { u8x8.setPowerSave(!cfg.screenon); // set display on if enabled @@ -538,8 +530,10 @@ void loop() { u8x8.draw2x2String(0, 0, buff); // display number on unique macs total Wifi + BLE u8x8.setCursor(0,4); u8x8.printf("WIFI: %-4d", (int) wifis.size()); - u8x8.setCursor(0,3); - u8x8.printf("BLTH: %-4d", (int) bles.size()); + #ifdef BLECOUNTER + u8x8.setCursor(0,3); + u8x8.printf("BLTH: %-4d", (int) bles.size()); + #endif // display actual wifi channel (line 4) u8x8.setCursor(11,4); u8x8.printf("ch:%02i", channel); From 4bc888d78dc782fc9df6ab9a4827c7f4ebe5c413 Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Sun, 15 Apr 2018 23:50:53 +0200 Subject: [PATCH 32/45] centralize display writes (part 3) --- src/globals.h | 1 + src/lorawan.cpp | 28 ++++++++++++---------------- src/main.cpp | 21 ++++++++++++++++----- 3 files changed, 29 insertions(+), 21 deletions(-) diff --git a/src/globals.h b/src/globals.h index e032839a..06a3de38 100644 --- a/src/globals.h +++ b/src/globals.h @@ -44,6 +44,7 @@ extern configData_t cfg; extern uint8_t mydata[]; extern uint64_t uptimecounter; extern osjob_t sendjob; +extern char display_lora[], display_lmic[]; extern int countermode, screensaver, adrmode, lorasf, txpower, rlim; extern bool joinstate; extern std::set wifis; diff --git a/src/lorawan.cpp b/src/lorawan.cpp index 3d061893..fd8693e3 100644 --- a/src/lorawan.cpp +++ b/src/lorawan.cpp @@ -65,7 +65,7 @@ void get_hard_deveui(uint8_t *pdeveui) { Wire.requestFrom(MCP_24AA02E64_I2C_ADDRESS, 8); while (Wire.available()) { data = Wire.read(); - sprintf(deveui+strlen(deveui), "%02X ", data) ; + sprintf(deveui+strlen(deveui), "%02X ", data); *pdeveui++ = data; } i2c_ret = Wire.endTransmission(); @@ -135,15 +135,14 @@ void do_send(osjob_t* j){ //mydata[5] = data & 0xff; // Check if there is not a current TX/RX job running - u8x8.clearLine(7); if (LMIC.opmode & OP_TXRXPEND) { ESP_LOGI(TAG, "OP_TXRXPEND, not sending"); - u8x8.drawString(0, 7, "LORA BUSY"); + sprintf(display_lmic, "LORA BUSY"); } else { // Prepare upstream data transmission at the next possible time. LMIC_setTxData2(1, mydata, sizeof(mydata), (cfg.countermode & 0x02)); ESP_LOGI(TAG, "Packet queued"); - u8x8.drawString(0, 7, "PACKET QUEUED"); + sprintf(display_lmic, "PACKET QUEUED"); } // Next TX is scheduled after TX_COMPLETE event. } @@ -168,7 +167,7 @@ void onEvent (ev_t ev) { case EV_JOINED: strcpy_P(buff, PSTR("JOINED")); - u8x8.clearLine(6); // erase "Join Wait" message from display, see main.cpp + sprintf(display_lora, " "); // erase "Join Wait" message from display // Disable link check validation (automatically enabled // during join, but not supported by TTN at this time). LMIC_setLinkCheckMode(0); @@ -182,23 +181,21 @@ void onEvent (ev_t ev) { break; case EV_TXCOMPLETE: ESP_LOGI(TAG, "EV_TXCOMPLETE (includes waiting for RX windows)"); - u8x8.clearLine(7); if (LMIC.txrxFlags & TXRX_ACK) { ESP_LOGI(TAG, "Received ack"); - u8x8.drawString(0, 7, "RECEIVED ACK"); + sprintf(display_lmic, "RECEIVED ACK"); + } else { - u8x8.drawString(0, 7, "TX COMPLETE"); + sprintf(display_lmic, "TX COMPLETE"); } if (LMIC.dataLen) { ESP_LOGI(TAG, "Received %d bytes of payload", LMIC.dataLen); - u8x8.clearLine(6); - u8x8.setCursor(0, 6); - u8x8.printf("Rcvd %d bytes", LMIC.dataLen); - u8x8.clearLine(7); - u8x8.setCursor(0, 7); + sprintf(display_lora, "Rcvd %d bytes", LMIC.dataLen); + // LMIC.snr = SNR twos compliment [dB] * 4 // LMIC.rssi = RSSI [dBm] (-196...+63) - u8x8.printf("RSSI %d SNR %d", LMIC.rssi, (signed char)LMIC.snr / 4); + sprintf(display_lmic, "RSSI %d SNR %d", LMIC.rssi, (signed char)LMIC.snr / 4 ); + // check if payload received on command port, then call remote command interpreter if ( (LMIC.txrxFlags & TXRX_PORT) && (LMIC.frame[LMIC.dataBeg-1] == RCMDPORT ) ) { // caution: buffering LMIC values here because rcommand() can modify LMIC.frame @@ -217,8 +214,7 @@ void onEvent (ev_t ev) { // Log & Display if asked if (*buff) { ESP_LOGI(TAG, "EV_%s", buff); - u8x8.clearLine(7); - u8x8.drawString(0, 7, buff); + sprintf(display_lmic, buff); } diff --git a/src/main.cpp b/src/main.cpp index c3dd607c..786e7264 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -45,6 +45,7 @@ configData_t cfg; // struct holds current device configuration osjob_t sendjob, initjob; // LMIC // Initialize global variables +char display_lora[16], display_lmic[16]; uint8_t channel = 0; int macnum = 0; uint64_t uptimecounter = 0; @@ -289,15 +290,13 @@ void sniffer_loop(void * pvParameters) { bles.clear(); // clear BLE macs counter #endif salt_reset(); // get new salt for salting hashes - u8x8.clearLine(0); // clear Display counter - u8x8.clearLine(1); } // wait until payload is sent, while wifi scanning and mac counting task continues lorawait = 0; while(LMIC.opmode & OP_TXRXPEND) { if(!lorawait) - u8x8.drawString(0,6,"LoRa wait "); + sprintf(display_lora, "LoRa wait"); lorawait++; // in case sending really fails: reset and rejoin network if( (lorawait % MAXLORARETRY ) == 0) { @@ -473,7 +472,7 @@ void setup() { #endif u8x8.setCursor(0,5); u8x8.printf(!cfg.rssilimit ? "RLIM: off" : "RLIM: %d", cfg.rssilimit); - u8x8.drawString(0,6,"Join Wait "); + sprintf(display_lora, "Join wait"); // output LoRaWAN keys to console #ifdef VERBOSE @@ -524,7 +523,8 @@ void loop() { #endif #ifdef HAS_DISPLAY - // display counters(lines 0-4) + + // display counters (lines 0-4) char buff[16]; snprintf(buff, sizeof(buff), "PAX:%-4d", (int) macs.size()); // convert 16-bit MAC counter to decimal counter value u8x8.draw2x2String(0, 0, buff); // display number on unique macs total Wifi + BLE @@ -534,12 +534,23 @@ void loop() { u8x8.setCursor(0,3); u8x8.printf("BLTH: %-4d", (int) bles.size()); #endif + // display actual wifi channel (line 4) u8x8.setCursor(11,4); u8x8.printf("ch:%02i", channel); + // display RSSI status (line 5) u8x8.setCursor(0,5); u8x8.printf(!cfg.rssilimit ? "RLIM: off" : "RLIM: %-3d", cfg.rssilimit); + + // display LoRa status (line 6) + u8x8.setCursor(0,6); + u8x8.printf("%-16s", display_lora); + + // display LMiC event (line 7) + u8x8.setCursor(0,7); + u8x8.printf("%-16s", display_lmic); + #endif vTaskDelay(DISPLAYREFRESH/portTICK_PERIOD_MS); From 52142c9d05e05b8662c1f7bd4fc13264101f5cfe Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Mon, 16 Apr 2018 00:05:11 +0200 Subject: [PATCH 33/45] centralize display writes (part 4) --- src/configmanager.cpp | 4 ++-- src/main.cpp | 18 ++++++++++-------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/configmanager.cpp b/src/configmanager.cpp index 650c3d93..49341163 100644 --- a/src/configmanager.cpp +++ b/src/configmanager.cpp @@ -287,8 +287,8 @@ void loadConfig() { nvs_close(my_handle); ESP_LOGI(TAG, "Done"); - // put actions to be triggered on loaded config here - u8x8.setPowerSave(!cfg.screenon); // set display on/off + // put actions to be triggered after config loaded here + #ifdef HAS_ANTENNA_SWITCH // set antenna type, if device has one antenna_select(cfg.wifiant); #endif diff --git a/src/main.cpp b/src/main.cpp index 786e7264..ddaa23f6 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -292,7 +292,7 @@ void sniffer_loop(void * pvParameters) { salt_reset(); // get new salt for salting hashes } - // wait until payload is sent, while wifi scanning and mac counting task continues + // check if payload is sent lorawait = 0; while(LMIC.opmode & OP_TXRXPEND) { if(!lorawait) @@ -306,8 +306,7 @@ void sniffer_loop(void * pvParameters) { vTaskDelay(1000/portTICK_PERIOD_MS); yield(); } - - u8x8.clearLine(6); + sprintf(display_lora, " "); // clear LoRa wait message fromd display // TBD: need to check if long 2000ms pause causes stack problems while scanning continues if (cfg.screenon && cfg.screensaver) { @@ -524,7 +523,10 @@ void loop() { #ifdef HAS_DISPLAY - // display counters (lines 0-4) + // set display on/off according to current device configuration + u8x8.setPowerSave(!cfg.screenon); + + // write counters (lines 0-4) char buff[16]; snprintf(buff, sizeof(buff), "PAX:%-4d", (int) macs.size()); // convert 16-bit MAC counter to decimal counter value u8x8.draw2x2String(0, 0, buff); // display number on unique macs total Wifi + BLE @@ -535,19 +537,19 @@ void loop() { u8x8.printf("BLTH: %-4d", (int) bles.size()); #endif - // display actual wifi channel (line 4) + // write actual wifi channel (line 4) u8x8.setCursor(11,4); u8x8.printf("ch:%02i", channel); - // display RSSI status (line 5) + // write RSSI status (line 5) u8x8.setCursor(0,5); u8x8.printf(!cfg.rssilimit ? "RLIM: off" : "RLIM: %-3d", cfg.rssilimit); - // display LoRa status (line 6) + // write LoRa status (line 6) u8x8.setCursor(0,6); u8x8.printf("%-16s", display_lora); - // display LMiC event (line 7) + // write LMiC event (line 7) u8x8.setCursor(0,7); u8x8.printf("%-16s", display_lmic); From 514e2c6d0513fdf33111b3cb1237a7c8ddb1c916 Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Mon, 16 Apr 2018 00:05:33 +0200 Subject: [PATCH 34/45] centralize display writes (part 5) --- src/main.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index ddaa23f6..c6e40bf8 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -276,7 +276,6 @@ void sniffer_loop(void * pvParameters) { // duration of one wifi scan loop reached? then send data and begin new scan cycle if ( nloop >= ( (100 / cfg.wifichancycle) * (cfg.wifiscancycle * 2)) +1 ) { - u8x8.setPowerSave(!cfg.screenon); // set display on if enabled nloop=0; channel=0; // reset wifi scan + channel loop counter do_send(&sendjob); // Prepare and execute LoRaWAN data upload vTaskDelay(500/portTICK_PERIOD_MS); From dbd3a0e0ddbbcee8a6e1de706d1e380924150baa Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Mon, 16 Apr 2018 00:08:01 +0200 Subject: [PATCH 35/45] platformio.ini typo fix --- platformio.ini | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/platformio.ini b/platformio.ini index f37e652b..8f4d829a 100644 --- a/platformio.ini +++ b/platformio.ini @@ -10,9 +10,9 @@ ; ---> SELECT TARGET PLATFORM HERE! <--- [platformio] -;nv_default = heltec_wifi_lora_32 +env_default = heltec_wifi_lora_32 ;env_default = ttgov1 -env_default = ttgov2 +;env_default = ttgov2 ;env_default = lopy ;env_default = lopy4 ;env_default = lolin32lite_lora From 11f4205b9a409ff833cef0418336d9cec6ff51e9 Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Mon, 16 Apr 2018 00:22:42 +0200 Subject: [PATCH 36/45] update readme.md --- README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index ceac836d..f6b6f362 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,8 @@ # ESP32-Paxcounter **Wifi & Bluetooth driven, LoRaWAN enabled, battery powered mini Paxcounter built on cheap ESP32 boards** +---> check branch "development" for latest alpha version <--- + # Use case @@ -20,13 +22,13 @@ This can all be done with a single small and cheap ESP32 board for less than $20 Currently supported IoT boards: - Heltec LoRa-32 {1} - TTGOv1 {1} -- TTGOv2 {1} +- TTGOv2 {1}{4} - Pycom LoPy {2} - Pycom LoPy4 {2} - LoLin32 with [LoraNode32 shield](https://github.com/hallard/LoLin32-Lora) {2}{3} - LoLin32 Lite with [LoraNode32-Lite shield](https://github.com/hallard/LoLin32-Lite-Lora) {2}{3} -{1} on board OLED Display supported; {2} on board RGB LED supported; {3} on board Hardware unique DEVEUI supported +{1} on board OLED Display supported; {2} on board RGB LED supported; {3} on board Hardware unique DEVEUI supported; {4} special wiring needed, see instructions in /hal/ttgov2.h Target platform must be selected in [platformio.ini](https://github.com/cyberman54/ESP32-Paxcounter/blob/master/platformio.ini).
Hardware dependent settings (pinout etc.) are stored in board files in /hal directory.
From 68cded9c717d88df8019eeeb8303927a27c10cad Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Mon, 16 Apr 2018 00:28:55 +0200 Subject: [PATCH 37/45] main.cpp: update comments --- src/main.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index c6e40bf8..01887c82 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -510,8 +510,10 @@ do_send(&sendjob); // Arduino main moop, runs on core 1 // https://techtutorialsx.com/2017/05/09/esp32-get-task-execution-core/ void loop() { + + uptimecounter = uptime() / 1000; // count uptime seconds - #ifdef HAS_BUTTON + #ifdef HAS_BUTTON // ...then check if pressed if (ButtonTriggered) { ButtonTriggered = false; ESP_LOGI(TAG, "Button pressed, resetting device to factory defaults"); @@ -520,12 +522,12 @@ void loop() { } #endif - #ifdef HAS_DISPLAY + #ifdef HAS_DISPLAY // ...then update mask // set display on/off according to current device configuration u8x8.setPowerSave(!cfg.screenon); - // write counters (lines 0-4) + // update counter display (lines 0-4) char buff[16]; snprintf(buff, sizeof(buff), "PAX:%-4d", (int) macs.size()); // convert 16-bit MAC counter to decimal counter value u8x8.draw2x2String(0, 0, buff); // display number on unique macs total Wifi + BLE @@ -536,26 +538,25 @@ void loop() { u8x8.printf("BLTH: %-4d", (int) bles.size()); #endif - // write actual wifi channel (line 4) + // update wifi channel display (line 4) u8x8.setCursor(11,4); u8x8.printf("ch:%02i", channel); - // write RSSI status (line 5) + // update RSSI limiter status display (line 5) u8x8.setCursor(0,5); u8x8.printf(!cfg.rssilimit ? "RLIM: off" : "RLIM: %-3d", cfg.rssilimit); - // write LoRa status (line 6) + // update LoRa status display (line 6) u8x8.setCursor(0,6); u8x8.printf("%-16s", display_lora); - // write LMiC event (line 7) + // update LMiC event display (line 7) u8x8.setCursor(0,7); u8x8.printf("%-16s", display_lmic); #endif vTaskDelay(DISPLAYREFRESH/portTICK_PERIOD_MS); - uptimecounter = uptime() / 1000; // count uptime seconds } From a3f23aef25eb5a5b923bc52b8c9f9b872839d45f Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Mon, 16 Apr 2018 11:03:12 +0200 Subject: [PATCH 38/45] centralize display writes (part 6) --- README.md | 2 +- platformio.ini | 4 ++-- src/main.cpp | 13 +++++++++---- src/main.h | 2 +- src/rcommand.cpp | 23 +++++------------------ 5 files changed, 18 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index f6b6f362..bf03b766 100644 --- a/README.md +++ b/README.md @@ -115,7 +115,7 @@ Note: all settings are stored in NVRAM and will be reloaded when device starts. 1 = cumulative counter, mac counter is never reset 2 = cyclic confirmed, like 0 but data is resent until confirmation by network received -0x03 set screen saver mode +0x03 (NOT YET IMPLEMENTED) set screen saver mode 0 = screen saver off [default] 1 = screen saver on diff --git a/platformio.ini b/platformio.ini index 8f4d829a..d608ae9d 100644 --- a/platformio.ini +++ b/platformio.ini @@ -10,9 +10,9 @@ ; ---> SELECT TARGET PLATFORM HERE! <--- [platformio] -env_default = heltec_wifi_lora_32 +;env_default = heltec_wifi_lora_32 ;env_default = ttgov1 -;env_default = ttgov2 +env_default = ttgov2 ;env_default = lopy ;env_default = lopy4 ;env_default = lolin32lite_lora diff --git a/src/main.cpp b/src/main.cpp index 01887c82..56249126 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -306,13 +306,16 @@ void sniffer_loop(void * pvParameters) { yield(); } sprintf(display_lora, " "); // clear LoRa wait message fromd display - + + /* // TBD: need to check if long 2000ms pause causes stack problems while scanning continues if (cfg.screenon && cfg.screensaver) { vTaskDelay(2000/portTICK_PERIOD_MS); // pause for displaying results yield(); u8x8.setPowerSave(1 && cfg.screensaver); // set display off if screensaver is enabled - } + } + */ + } // end of send data cycle } // end of infinite wifi channel rotation loop @@ -534,8 +537,10 @@ void loop() { u8x8.setCursor(0,4); u8x8.printf("WIFI: %-4d", (int) wifis.size()); #ifdef BLECOUNTER + if (cfg.blescan) { u8x8.setCursor(0,3); u8x8.printf("BLTH: %-4d", (int) bles.size()); + } #endif // update wifi channel display (line 4) @@ -544,7 +549,7 @@ void loop() { // update RSSI limiter status display (line 5) u8x8.setCursor(0,5); - u8x8.printf(!cfg.rssilimit ? "RLIM: off" : "RLIM: %-3d", cfg.rssilimit); + u8x8.printf(!cfg.rssilimit ? "RLIM: off" : "RLIM: %-4d", cfg.rssilimit); // update LoRa status display (line 6) u8x8.setCursor(0,6); @@ -556,7 +561,7 @@ void loop() { #endif - vTaskDelay(DISPLAYREFRESH/portTICK_PERIOD_MS); + vTaskDelay(1000/DISPLAYFPS/portTICK_PERIOD_MS); } diff --git a/src/main.h b/src/main.h index 358096b2..49b93e54 100644 --- a/src/main.h +++ b/src/main.h @@ -47,7 +47,7 @@ #define RGBLUMINOSITY 30 // 30% // OLED Display refresh cycle (in Milliseconds) -#define DISPLAYREFRESH 200 // 200ms +#define DISPLAYFPS 5 // [fps] -> 5 Frames per second ps = 200ms refreseh cycle // LMIC settings // define hardware independent LMIC settings here, settings of standard library in /lmic/config.h will be ignored diff --git a/src/rcommand.cpp b/src/rcommand.cpp index ff80add8..ac2ac1b5 100644 --- a/src/rcommand.cpp +++ b/src/rcommand.cpp @@ -58,9 +58,7 @@ void set_reset(int val) { switch (val) { case 0: // restart device ESP_LOGI(TAG, "Remote command: restart device"); - u8x8.clearLine(5); - u8x8.setCursor(0, 5); - u8x8.printf("Reset pending "); + sprintf(display_lora, "Reset pending"); vTaskDelay(10000/portTICK_PERIOD_MS); // wait for LMIC to confirm LoRa downlink to server esp_restart(); break; @@ -72,16 +70,11 @@ void set_reset(int val) { bles.clear(); // clear BLE macs container #endif salt_reset(); // get new 16bit salt - u8x8.clearLine(0); u8x8.clearLine(1); // clear Display counter - u8x8.clearLine(5); - u8x8.setCursor(0, 5); - u8x8.printf("Reset counter "); + sprintf(display_lora, "Reset counter"); break; case 2: // reset device to factory settings ESP_LOGI(TAG, "Remote command: reset device to factory settings"); - u8x8.clearLine(5); - u8x8.setCursor(0, 5); - u8x8.printf("Factory reset "); + sprintf(display_lora, "Factory reset"); eraseConfig(); break; } @@ -90,9 +83,6 @@ void set_reset(int val) { void set_rssi(int val) { cfg.rssilimit = val * -1; ESP_LOGI(TAG, "Remote command: set RSSI limit to %i", cfg.rssilimit); - u8x8.clearLine(5); - u8x8.setCursor(0, 5); - u8x8.printf(!cfg.rssilimit ? "RLIM: off" : "RLIM: -%4i", cfg.rssilimit); }; void set_wifiscancycle(int val) { @@ -133,7 +123,6 @@ void set_screensaver(int val) { case 1: cfg.screensaver = val; break; default: cfg.screensaver = 0; break; } - u8x8.setPowerSave(cfg.screensaver); // set display 0=on / 1=off }; void set_display(int val) { @@ -142,7 +131,6 @@ void set_display(int val) { case 1: cfg.screenon = val; break; default: cfg.screenon = 0; break; } - u8x8.setPowerSave(!cfg.screenon); // set display 0=on / 1=off }; void set_lorasf(int val) { @@ -166,7 +154,6 @@ void set_blescan(int val) { default: cfg.blescan = 0; btStop(); - u8x8.clearLine(3); // clear BLE results from display break; } }; @@ -244,12 +231,12 @@ void get_cputemp (int val) { cmd_t table[] = { {0x01, set_rssi, true}, {0x02, set_countmode, true}, - {0x03, set_screensaver, true}, + {0x03, set_noop, false}, {0x04, set_display, true}, {0x05, set_lorasf, true}, {0x06, set_lorapower, true}, {0x07, set_loraadr, true}, - {0x08, set_noop, false}, + {0x08, set_screensaver, true}, {0x09, set_reset, false}, {0x0a, set_wifiscancycle, true}, {0x0b, set_wifichancycle, true}, From 3c0af4d14646c8411d3d127df47369ced7f4dba8 Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Mon, 16 Apr 2018 11:15:50 +0200 Subject: [PATCH 39/45] release v1.3.0 --- platformio.ini | 4 ++-- src/main.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/platformio.ini b/platformio.ini index d608ae9d..8f4d829a 100644 --- a/platformio.ini +++ b/platformio.ini @@ -10,9 +10,9 @@ ; ---> SELECT TARGET PLATFORM HERE! <--- [platformio] -;env_default = heltec_wifi_lora_32 +env_default = heltec_wifi_lora_32 ;env_default = ttgov1 -env_default = ttgov2 +;env_default = ttgov2 ;env_default = lopy ;env_default = lopy4 ;env_default = lolin32lite_lora diff --git a/src/main.h b/src/main.h index 49b93e54..43a2b08c 100644 --- a/src/main.h +++ b/src/main.h @@ -1,7 +1,7 @@ #pragma once // program version - note: increment version after modifications to configData_t struct!! -#define PROGVERSION "1.2.98" // use max 10 chars here! +#define PROGVERSION "1.3.0" // use max 10 chars here! #define PROGNAME "PAXCNT" // Verbose enables serial output From e01d4c2100d1a4f52c09cc4d370ad7f849810ebf Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Mon, 16 Apr 2018 20:56:29 +0200 Subject: [PATCH 40/45] cleanups --- platformio.ini | 33 +++++++++++++++++---------------- src/globals.h | 8 ++++---- src/main.cpp | 15 +++++++-------- 3 files changed, 28 insertions(+), 28 deletions(-) diff --git a/platformio.ini b/platformio.ini index 8f4d829a..9d54a245 100644 --- a/platformio.ini +++ b/platformio.ini @@ -20,24 +20,29 @@ env_default = heltec_wifi_lora_32 ; description = Paxcounter is a proof-of-concept ESP32 device for metering passenger flows in realtime. It counts how many mobile devices are around. +;----------- common part ----------- [common_env_data] build_flags = ; we need build_flag for logging, otherwise we can't use ESP_LOGx in arduino framework ; ---> NOTE: For production run set DEBUG_LEVEL level to NONE! <--- ; otherwise device may crash in dense environments due to serial buffer overflow ; + -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_NONE ; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_INFO ; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_VERBOSE - -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_NONE ; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_DEBUG ; -;override lora settings from LMiC library in lmic/config.h and use main.h instead +; override lora settings from LMiC library in lmic/config.h and use main.h instead -D_lmic_config_h_ -include "src/main.h" ; -lib_deps_builtin = - U8g2@2.22.10 - +lib_deps_display = + U8g2@>=2.22.14 +lib_deps_rgbled = + SmartLeds +; +; +;----------- hardware specific part ----------- [env:heltec_wifi_lora_32] platform = espressif32 @@ -46,7 +51,7 @@ framework = arduino monitor_baud = 115200 upload_speed = 115200 lib_deps = - ${common_env_data.lib_deps_builtin} + ${common_env_data.lib_deps_display} build_flags = ${common_env_data.build_flags} -Dheltec_wifi_lora_32 @@ -59,7 +64,7 @@ framework = arduino monitor_baud = 115200 upload_speed = 115200 lib_deps = - ${common_env_data.lib_deps_builtin} + ${common_env_data.lib_deps_display} build_flags = ${common_env_data.build_flags} -Dttgov1 @@ -72,7 +77,7 @@ framework = arduino monitor_baud = 115200 upload_speed = 921600 lib_deps = - ${common_env_data.lib_deps_builtin} + ${common_env_data.lib_deps_display} build_flags = ${common_env_data.build_flags} -Dttgov2 @@ -85,8 +90,7 @@ framework = arduino monitor_baud = 115200 upload_speed = 921600 lib_deps = - ${common_env_data.lib_deps_builtin} - SmartLeds + ${common_env_data.lib_deps_rgbled} build_flags = ${common_env_data.build_flags} -Dlopy @@ -99,8 +103,7 @@ framework = arduino monitor_baud = 115200 upload_speed = 921600 lib_deps = - ${common_env_data.lib_deps_builtin} - SmartLeds + ${common_env_data.lib_deps_rgbled} build_flags = ${common_env_data.build_flags} -Dlopy4 @@ -113,8 +116,7 @@ framework = arduino monitor_baud = 115200 upload_speed = 256000 lib_deps = - ${common_env_data.lib_deps_builtin} - SmartLeds + ${common_env_data.lib_deps_rgbled} build_flags = ${common_env_data.build_flags} -Dlolin32lite_lora @@ -127,8 +129,7 @@ framework = arduino monitor_baud = 115200 upload_speed = 921600 lib_deps = - ${common_env_data.lib_deps_builtin} - SmartLeds + ${common_env_data.lib_deps_rgbled} build_flags = ${common_env_data.build_flags} -Dlolin32_lora diff --git a/src/globals.h b/src/globals.h index 06a3de38..72598669 100644 --- a/src/globals.h +++ b/src/globals.h @@ -6,8 +6,10 @@ #include #include -// OLED Display -#include +#ifdef HAS_DISPLAY + // OLED Display + #include +#endif // LMIC-Arduino LoRaWAN Stack #include @@ -52,8 +54,6 @@ extern std::set macs; #ifdef HAS_DISPLAY extern HAS_DISPLAY u8x8; -#else - extern U8X8_NULL u8x8; #endif #ifdef BLECOUNTER diff --git a/src/main.cpp b/src/main.cpp index 56249126..31ac22aa 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -27,9 +27,8 @@ Refer to LICENSE.txt file in repository for more details. // std::set for unified array functions #include -// OLED driver -#include -#include // Does nothing and avoid any compilation error with I2C +// Does nothing and avoid any compilation error with I2C +#include // LMIC-Arduino LoRaWAN Stack #include "loraconf.h" @@ -207,8 +206,6 @@ void lorawan_loop(void * pvParameters) { #ifdef HAS_DISPLAY HAS_DISPLAY u8x8(OLED_RST, OLED_SCL, OLED_SDA); -#else - U8X8_NULL u8x8; #endif #ifdef HAS_ANTENNA_SWITCH @@ -332,6 +329,7 @@ uint64_t uptime() { return (uint64_t) high32 << 32 | low32; } +#ifdef HAS_DISPLAY // Print a key on display void DisplayKey(const uint8_t * key, uint8_t len, bool lsb) { uint8_t start=lsb?len:0; @@ -345,10 +343,9 @@ void DisplayKey(const uint8_t * key, uint8_t len, bool lsb) { } void init_display(const char *Productname, const char *Version) { + uint8_t buf[32]; u8x8.begin(); u8x8.setFont(u8x8_font_chroma48medium8_r); -#ifdef HAS_DISPLAY - uint8_t buf[32]; u8x8.clear(); u8x8.setFlipMode(0); u8x8.setInverseFont(1); @@ -392,8 +389,8 @@ void init_display(const char *Productname, const char *Version) { DisplayKey(buf, 8, true); delay(5000); u8x8.clear(); -#endif // HAS_DISPLAY } +#endif // HAS_DISPLAY /* begin Aruino SETUP ------------------------------------------------------------ */ @@ -461,6 +458,7 @@ void setup() { antenna_init(); #endif +#ifdef HAS_DISPLAY // initialize display init_display(PROGNAME, PROGVERSION); u8x8.setPowerSave(!cfg.screenon); // set display off if disabled @@ -474,6 +472,7 @@ void setup() { u8x8.setCursor(0,5); u8x8.printf(!cfg.rssilimit ? "RLIM: off" : "RLIM: %d", cfg.rssilimit); sprintf(display_lora, "Join wait"); +#endif // output LoRaWAN keys to console #ifdef VERBOSE From 84cc1c937ad510be5d8fa5a9335250516add6123 Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Mon, 16 Apr 2018 21:16:24 +0200 Subject: [PATCH 41/45] cleanups --- platformio.ini | 36 +++++++++++++----------------------- 1 file changed, 13 insertions(+), 23 deletions(-) diff --git a/platformio.ini b/platformio.ini index 9d54a245..5e9d4d94 100644 --- a/platformio.ini +++ b/platformio.ini @@ -8,6 +8,7 @@ ; Please visit documentation for the other options and examples ; http://docs.platformio.org/page/projectconf.html + ; ---> SELECT TARGET PLATFORM HERE! <--- [platformio] env_default = heltec_wifi_lora_32 @@ -20,8 +21,12 @@ env_default = heltec_wifi_lora_32 ; description = Paxcounter is a proof-of-concept ESP32 device for metering passenger flows in realtime. It counts how many mobile devices are around. -;----------- common part ----------- [common_env_data] +monitor_baud = 115200 +lib_deps_display = + U8g2@>=2.22.14 +lib_deps_rgbled = + SmartLeds build_flags = ; we need build_flag for logging, otherwise we can't use ESP_LOGx in arduino framework ; ---> NOTE: For production run set DEBUG_LEVEL level to NONE! <--- @@ -35,20 +40,11 @@ build_flags = ; override lora settings from LMiC library in lmic/config.h and use main.h instead -D_lmic_config_h_ -include "src/main.h" -; -lib_deps_display = - U8g2@>=2.22.14 -lib_deps_rgbled = - SmartLeds -; -; -;----------- hardware specific part ----------- [env:heltec_wifi_lora_32] platform = espressif32 -board = heltec_wifi_lora_32 framework = arduino -monitor_baud = 115200 +board = heltec_wifi_lora_32 upload_speed = 115200 lib_deps = ${common_env_data.lib_deps_display} @@ -59,9 +55,8 @@ build_flags = [env:ttgov1] platform = espressif32 -board = esp32dev framework = arduino -monitor_baud = 115200 +board = esp32dev upload_speed = 115200 lib_deps = ${common_env_data.lib_deps_display} @@ -72,9 +67,8 @@ build_flags = [env:ttgov2] platform = espressif32 -board = esp32dev framework = arduino -monitor_baud = 115200 +board = esp32dev upload_speed = 921600 lib_deps = ${common_env_data.lib_deps_display} @@ -85,9 +79,8 @@ build_flags = [env:lopy] platform = espressif32 -board = esp32dev framework = arduino -monitor_baud = 115200 +board = esp32dev upload_speed = 921600 lib_deps = ${common_env_data.lib_deps_rgbled} @@ -98,9 +91,8 @@ build_flags = [env:lopy4] platform = espressif32 -board = esp32dev framework = arduino -monitor_baud = 115200 +board = esp32dev upload_speed = 921600 lib_deps = ${common_env_data.lib_deps_rgbled} @@ -111,9 +103,8 @@ build_flags = [env:lolin32lite_lora] platform = espressif32 -board = lolin32 framework = arduino -monitor_baud = 115200 +board = lolin32 upload_speed = 256000 lib_deps = ${common_env_data.lib_deps_rgbled} @@ -124,9 +115,8 @@ build_flags = [env:lolin32_lora] platform = espressif32 +framework = arduino board = lolin32 -framework = arduino -monitor_baud = 115200 upload_speed = 921600 lib_deps = ${common_env_data.lib_deps_rgbled} From b973de716bd9ecf12f1b4464c26e5b0b1f5dd2ca Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Mon, 16 Apr 2018 21:27:11 +0200 Subject: [PATCH 42/45] cleanups --- README.md | 4 ++-- platformio.ini | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index bf03b766..3c6c35f7 100644 --- a/README.md +++ b/README.md @@ -64,8 +64,8 @@ If your device has silicon **Unique ID** which is stored in serial EEPROM Microc To upload the code to your ESP32 board this needs to be switched from run to bootloader mode. Boards with USB bridge like Heltec and TTGO usually have an onboard logic which allows soft switching by the upload tool. In PlatformIO this happenes automatically.

The LoPy/LoPy4 board needs to be set manually. See these -instructions how to do it.

-For the LoPy/LoPy4 the original Pycom firmware is not needed here, so there is no need to update it before flashing Paxcounter. Just flash the paxcounter code on your LoPy/LoPy4. If you want to go back to the Pycom firmware, no problem. Download the firmware from Pycom and flash it over. +instructions how to do it. Don't forget to press on board reset button after switching between run and bootloader mode.

+The original Pycom firmware is not needed, so there is no need to update it before flashing Paxcounter. Just flash the compiled paxcounter binary (.elf file) on your LoPy/LoPy4. If you later want to go back to the Pycom firmware, download the firmware from Pycom and flash it over. # Legal note diff --git a/platformio.ini b/platformio.ini index 5e9d4d94..c92a9060 100644 --- a/platformio.ini +++ b/platformio.ini @@ -11,10 +11,10 @@ ; ---> SELECT TARGET PLATFORM HERE! <--- [platformio] -env_default = heltec_wifi_lora_32 +;env_default = heltec_wifi_lora_32 ;env_default = ttgov1 ;env_default = ttgov2 -;env_default = lopy +env_default = lopy ;env_default = lopy4 ;env_default = lolin32lite_lora ;env_default = lolin32_lora From c28aa8820be01a93e1cc0a2b5afc74e2f38db700 Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Mon, 16 Apr 2018 21:31:09 +0200 Subject: [PATCH 43/45] cleanups --- platformio.ini | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/platformio.ini b/platformio.ini index c92a9060..40445272 100644 --- a/platformio.ini +++ b/platformio.ini @@ -22,7 +22,6 @@ env_default = lopy description = Paxcounter is a proof-of-concept ESP32 device for metering passenger flows in realtime. It counts how many mobile devices are around. [common_env_data] -monitor_baud = 115200 lib_deps_display = U8g2@>=2.22.14 lib_deps_rgbled = @@ -45,6 +44,7 @@ build_flags = platform = espressif32 framework = arduino board = heltec_wifi_lora_32 +monitor_baud = 115200 upload_speed = 115200 lib_deps = ${common_env_data.lib_deps_display} @@ -57,6 +57,7 @@ build_flags = platform = espressif32 framework = arduino board = esp32dev +monitor_baud = 115200 upload_speed = 115200 lib_deps = ${common_env_data.lib_deps_display} @@ -69,6 +70,7 @@ build_flags = platform = espressif32 framework = arduino board = esp32dev +monitor_baud = 115200 upload_speed = 921600 lib_deps = ${common_env_data.lib_deps_display} @@ -81,6 +83,7 @@ build_flags = platform = espressif32 framework = arduino board = esp32dev +monitor_baud = 115200 upload_speed = 921600 lib_deps = ${common_env_data.lib_deps_rgbled} @@ -93,6 +96,7 @@ build_flags = platform = espressif32 framework = arduino board = esp32dev +monitor_baud = 115200 upload_speed = 921600 lib_deps = ${common_env_data.lib_deps_rgbled} @@ -105,6 +109,7 @@ build_flags = platform = espressif32 framework = arduino board = lolin32 +monitor_baud = 115200 upload_speed = 256000 lib_deps = ${common_env_data.lib_deps_rgbled} @@ -117,6 +122,7 @@ build_flags = platform = espressif32 framework = arduino board = lolin32 +monitor_baud = 115200 upload_speed = 921600 lib_deps = ${common_env_data.lib_deps_rgbled} From 9fbaf4bea61b1b28679e55d1e3340f8c85531512 Mon Sep 17 00:00:00 2001 From: Verkehrsrot <10289836+cyberman54@users.noreply.github.com> Date: Mon, 16 Apr 2018 21:36:43 +0200 Subject: [PATCH 44/45] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 3c6c35f7..372fc03f 100644 --- a/README.md +++ b/README.md @@ -163,7 +163,7 @@ Note: all settings are stored in NVRAM and will be reloaded when device starts. 0x0C set BLE scan cycle timer 0 ... 255 duration of a BLE scan cycle in seconds - e.g. 15 -> 1 cycle runs for 15 seconds [default] + e.g. 11 -> 1 cycle runs for 11 seconds [default] 0x0D (NOT YET IMPLEMENTED) set BLE and WIFI vendorfilter mode From e69c9115869e42b4d80567666225cd9f7599d236 Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Mon, 16 Apr 2018 22:48:00 +0200 Subject: [PATCH 45/45] bugfixes in bluetooth on/off (still not fixed) --- platformio.ini | 4 ++-- src/blecsan.cpp | 3 ++- src/main.cpp | 7 ++++--- src/main.h | 2 +- src/rcommand.cpp | 14 +++++++++----- 5 files changed, 18 insertions(+), 12 deletions(-) diff --git a/platformio.ini b/platformio.ini index 40445272..fff50de0 100644 --- a/platformio.ini +++ b/platformio.ini @@ -11,10 +11,10 @@ ; ---> SELECT TARGET PLATFORM HERE! <--- [platformio] -;env_default = heltec_wifi_lora_32 +env_default = heltec_wifi_lora_32 ;env_default = ttgov1 ;env_default = ttgov2 -env_default = lopy +;env_default = lopy ;env_default = lopy4 ;env_default = lolin32lite_lora ;env_default = lolin32_lora diff --git a/src/blecsan.cpp b/src/blecsan.cpp index 415ec045..4e028aaf 100644 --- a/src/blecsan.cpp +++ b/src/blecsan.cpp @@ -139,7 +139,8 @@ static void gap_callback_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_pa #endif // add this device and show new count total if it was not previously added - mac_add((uint8_t *) p->scan_rst.bda, p->scan_rst.rssi, MAC_SNIFF_BLE); + if (cfg.blescan) // count only if BLE scan is enabled + mac_add((uint8_t *) p->scan_rst.bda, p->scan_rst.rssi, MAC_SNIFF_BLE); break; skip: diff --git a/src/main.cpp b/src/main.cpp index 31ac22aa..2bfadabd 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -536,10 +536,11 @@ void loop() { u8x8.setCursor(0,4); u8x8.printf("WIFI: %-4d", (int) wifis.size()); #ifdef BLECOUNTER - if (cfg.blescan) { u8x8.setCursor(0,3); - u8x8.printf("BLTH: %-4d", (int) bles.size()); - } + if (cfg.blescan) + u8x8.printf("BLTH: %-4d", (int) bles.size()); + else + u8x8.printf("%-16s", "BLTH: off"); #endif // update wifi channel display (line 4) diff --git a/src/main.h b/src/main.h index 43a2b08c..490fea31 100644 --- a/src/main.h +++ b/src/main.h @@ -1,7 +1,7 @@ #pragma once // program version - note: increment version after modifications to configData_t struct!! -#define PROGVERSION "1.3.0" // use max 10 chars here! +#define PROGVERSION "1.3.01" // use max 10 chars here! #define PROGNAME "PAXCNT" // Verbose enables serial output diff --git a/src/rcommand.cpp b/src/rcommand.cpp index ac2ac1b5..29ed2f1c 100644 --- a/src/rcommand.cpp +++ b/src/rcommand.cpp @@ -150,11 +150,15 @@ void set_loraadr(int val) { void set_blescan(int val) { ESP_LOGI(TAG, "Remote command: set BLE scan mode to %s", val ? "on" : "off"); switch (val) { - case 1: cfg.blescan = val; break; - default: - cfg.blescan = 0; - btStop(); - break; + case 0: + cfg.blescan = 0; + #ifdef BLECOUNTER + bles.clear(); // clear BLE macs container + #endif + break; + default: + cfg.blescan = 1; + break; } };