From 06e68459c85b646d8516f38fb0a9f0b9314342d8 Mon Sep 17 00:00:00 2001 From: Cyberman54 Date: Fri, 11 May 2018 12:40:36 +0200 Subject: [PATCH 01/38] loraconf.sample.h modified --- src/loraconf.sample.h | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/loraconf.sample.h b/src/loraconf.sample.h index cbfd3d47..d5596162 100644 --- a/src/loraconf.sample.h +++ b/src/loraconf.sample.h @@ -7,8 +7,6 @@ #include -/* - // Set your DEVEUI here, if you have one. You can leave this untouched, // then the DEVEUI will be generated during runtime from device's MAC adress // Note: Use same format as in TTN console (cut & paste, for your convenience) @@ -21,6 +19,4 @@ static const u1_t DEVEUI[8]={ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; static const u1_t APPEUI[8]={ 0x70, 0xB3, 0xD5, 0x00, 0x00, 0x00, 0x00, 0x00 }; // Note: Use msb format for APPEUI as in TTN console (cut & paste, for your convenience) -static const u1_t APPKEY[16] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - -*/ \ No newline at end of file +static const u1_t APPKEY[16] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; \ No newline at end of file From 14b00196de88a04b5d46122ceb67c8f7265fd7ec Mon Sep 17 00:00:00 2001 From: cyberman54 Date: Fri, 11 May 2018 19:07:48 +0200 Subject: [PATCH 02/38] experimental bug fix memory threshold --- src/blecsan.cpp | 7 ++----- src/lorawan.cpp | 1 + src/main.cpp | 5 ++++- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/blecsan.cpp b/src/blecsan.cpp index 4c2bb9af..3524e0af 100644 --- a/src/blecsan.cpp +++ b/src/blecsan.cpp @@ -99,17 +99,16 @@ static void gap_callback_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_pa switch (event) { case ESP_GAP_BLE_SCAN_PARAM_SET_COMPLETE_EVT: - { // restart scan + // restart scan status = esp_ble_gap_start_scanning(cfg.blescantime); if (status != ESP_OK) { ESP_LOGE(TAG, "esp_ble_gap_start_scanning: rc=%d", status); } - } break; case ESP_GAP_BLE_SCAN_RESULT_EVT: - { + // evaluate scan results if ( p->scan_rst.search_evt == ESP_GAP_SEARCH_INQ_CMPL_EVT) // Inquiry complete, scan is done { // restart scan status = esp_ble_gap_start_scanning (cfg.blescantime); @@ -177,8 +176,6 @@ static void gap_callback_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_pa */ } - - } break; default: diff --git a/src/lorawan.cpp b/src/lorawan.cpp index a5e3e90a..b2269571 100644 --- a/src/lorawan.cpp +++ b/src/lorawan.cpp @@ -136,6 +136,7 @@ void do_send(osjob_t* j){ if (cfg.countermode != 1) { reset_counters(); // clear macs container and reset all counters reset_salt(); // get new salt for salting hashes + ESP_LOGI(TAG, "Counter cleared (countermode = %d)", cfg.countermode); } } diff --git a/src/main.cpp b/src/main.cpp index 5f360faa..3cdd289e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -627,7 +627,10 @@ void loop() { #endif // check free memory - if (ESP.getFreeHeap() <= MEM_LOW) { + //if (ESP.getFreeHeap() <= MEM_LOW) { + if (esp_get_minimum_free_heap_size() <= MEM_LOW) { + // ESP_LOGI(TAG, "Counter cleared (memory low = %d Bytes)", ESP.getFreeHeap()); + ESP_LOGI(TAG, "Counter cleared (memory low water mark = %d Bytes)", esp_get_minimum_free_heap_size()); do_send(&sendjob); // send count reset_counters(); // clear macs container and reset all counters reset_salt(); // get new salt for salting hashes From e96593d5b8491cea28b0970fd07b31248d9166b6 Mon Sep 17 00:00:00 2001 From: cyberman54 Date: Fri, 11 May 2018 23:54:09 +0200 Subject: [PATCH 03/38] v1.3.41 --- src/main.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.h b/src/main.h index 5ad9b39b..adae07fb 100644 --- a/src/main.h +++ b/src/main.h @@ -1,6 +1,6 @@ // program version - note: increment version after modifications to configData_t struct!! -#define PROGVERSION "1.3.4" // use max 10 chars here! +#define PROGVERSION "1.3.41" // use max 10 chars here! #define PROGNAME "PAXCNT" //--- Declarations --- From 78ffbd6e6489b26eb8d90d7f8664038407b9a041 Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Sat, 12 May 2018 13:43:47 +0200 Subject: [PATCH 04/38] code sanitization --- src/blecsan.cpp | 20 ++++++++------------ src/macsniff.cpp | 8 ++++---- src/main.h | 2 +- 3 files changed, 13 insertions(+), 17 deletions(-) diff --git a/src/blecsan.cpp b/src/blecsan.cpp index 3524e0af..51b6a563 100644 --- a/src/blecsan.cpp +++ b/src/blecsan.cpp @@ -125,28 +125,24 @@ static void gap_callback_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_pa 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 + if ((cfg.rssilimit) && (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; - + if ((p->scan_rst.ble_addr_type == BLE_ADDR_TYPE_RANDOM) || (p->scan_rst.ble_addr_type == BLE_ADDR_TYPE_RPA_RANDOM)) { + ESP_LOGD(TAG, "BT device filtered"); + break; + } + #endif // add this device and show new count total if it was not previously added 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: - ESP_LOGD(TAG, "BT device filtered"); - break; - - + /* to be improved in vendorfilter if: // you can search for elements in the payload using the @@ -175,7 +171,7 @@ static void gap_callback_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_pa */ - } + } // evaluate sniffed packet break; default: diff --git a/src/macsniff.cpp b/src/macsniff.cpp index 331feb35..fbaa01d6 100644 --- a/src/macsniff.cpp +++ b/src/macsniff.cpp @@ -107,11 +107,11 @@ void wifi_sniffer_packet_handler(void* buff, wifi_promiscuous_pkt_type_t type) { const wifi_ieee80211_packet_t *ipkt = (wifi_ieee80211_packet_t *)ppkt->payload; const wifi_ieee80211_mac_hdr_t *hdr = &ipkt->hdr; - if (( cfg.rssilimit == 0 ) || (ppkt->rx_ctrl.rssi > cfg.rssilimit )) { // rssi is negative value - uint8_t *p = (uint8_t *) hdr->addr2; - mac_add(p, ppkt->rx_ctrl.rssi, MAC_SNIFF_WIFI) ; - } else { + if ((cfg.rssilimit) && (ppkt->rx_ctrl.rssi < cfg.rssilimit )) { // rssi is negative value ESP_LOGI(TAG, "WiFi RSSI %d -> ignoring (limit: %d)", ppkt->rx_ctrl.rssi, cfg.rssilimit); + } else { + uint8_t *p = (uint8_t *) hdr->addr2; + mac_add(p, ppkt->rx_ctrl.rssi, MAC_SNIFF_WIFI) ; } } diff --git a/src/main.h b/src/main.h index adae07fb..b9556935 100644 --- a/src/main.h +++ b/src/main.h @@ -1,6 +1,6 @@ // program version - note: increment version after modifications to configData_t struct!! -#define PROGVERSION "1.3.41" // use max 10 chars here! +#define PROGVERSION "1.3.42" // use max 10 chars here! #define PROGNAME "PAXCNT" //--- Declarations --- From 0cb94aaff8ac17247fefcaa7af99d9f836d74a7f Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Sat, 12 May 2018 17:14:52 +0200 Subject: [PATCH 05/38] BT stacksize configurable --- src/blecsan.cpp | 2 +- src/paxcounter.conf | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/blecsan.cpp b/src/blecsan.cpp index 51b6a563..41678a2f 100644 --- a/src/blecsan.cpp +++ b/src/blecsan.cpp @@ -235,7 +235,7 @@ void bt_loop(void * pvParameters) // 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(); - bt_cfg.controller_task_stack_size = 8192; // double BT stack size + bt_cfg.controller_task_stack_size = BLESTACKSIZE; // set BT stack size to value configured in paxcounter.conf if (esp_bt_controller_init(&bt_cfg) != ESP_OK) { diff --git a/src/paxcounter.conf b/src/paxcounter.conf index cc953b6b..8ab4da35 100644 --- a/src/paxcounter.conf +++ b/src/paxcounter.conf @@ -10,6 +10,7 @@ #define BLECOUNTER 1 // comment out if you don't want BLE count // BLE scan parameters +#define BLESTACKSIZE 8192 // stack size for esp_bt_controller #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 811ece9ee948be83e508bf7c6c16a4b14b1c2fa2 Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Sat, 12 May 2018 18:20:15 +0200 Subject: [PATCH 06/38] update readme.md --- README.md | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/README.md b/README.md index 500457b2..a9596c02 100644 --- a/README.md +++ b/README.md @@ -36,17 +36,7 @@ Hardware dependent settings (pinout etc.) are stored in board files in /hal dire 3D printable cases can be found (and, if wanted so, ordered) on Thingiverse, see Heltec and TTGOv2, for example.
-Power consumption: - -- 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.97 while continuously scanning wifi and ble, no LoRa TX’ing, OLED display (if present) on, 5V USB powered. +Power consumption was metered at around 1000mW, depending on board (i.e. has display or not) and user settings in paxcounter.conf. If you are limited on battery, you may want to save around 30% power by disabling bluetooth (commenting out line *#define BLECOUNTER* in paxcounter.conf). # Preparing From 7f5c936061061bde1c0bb3b65799d8f7a976ed20 Mon Sep 17 00:00:00 2001 From: Florian Ludwig Date: Mon, 14 May 2018 18:14:59 +0200 Subject: [PATCH 07/38] add FiPy environment --- platformio.ini | 13 +++++++++++++ src/hal/fipy.h | 19 +++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 src/hal/fipy.h diff --git a/platformio.ini b/platformio.ini index f780a017..8efbc391 100644 --- a/platformio.ini +++ b/platformio.ini @@ -79,6 +79,19 @@ build_flags = -Dttgov2 -include "src/hal/ttgov2.h" +[env:fipy] +platform = espressif32 +framework = arduino +board = esp32dev +monitor_baud = 115200 +upload_speed = 921600 +lib_deps = + ${common_env_data.lib_deps_rgbled} +build_flags = + ${common_env_data.build_flags} + -Dlopy + -include "src/hal/fipy.h" + [env:lopy] platform = espressif32 framework = arduino diff --git a/src/hal/fipy.h b/src/hal/fipy.h new file mode 100644 index 00000000..31aa55f6 --- /dev/null +++ b/src/hal/fipy.h @@ -0,0 +1,19 @@ +// Hardware related definitions for Pycom LoPy Board (not: LoPy4) + +#define CFG_sx1272_radio 1 +#define HAS_LED NOT_A_PIN // LoPy4 has no on board LED, so we use RGB LED on LoPy4 +#define HAS_RGB_LED 0 // WS2812B RGB LED on GPIO0 + +// Hardware pin definitions for Pycom LoPy4 board +#define PIN_SPI_SS 18 +#define PIN_SPI_MOSI 27 +#define PIN_SPI_MISO 19 +#define PIN_SPI_SCK 5 +#define RST LMIC_UNUSED_PIN +#define DIO0 23 // LoRa IRQ +#define DIO1 23 // workaround +#define DIO2 LMIC_UNUSED_PIN + +// select WIFI antenna (internal = onboard / external = u.fl socket) +#define HAS_ANTENNA_SWITCH 21 // pin for switching wifi antenna +#define WIFI_ANTENNA 0 // 0 = internal, 1 = external From acc41382e9af8900ffc7126a2a82634daee95728 Mon Sep 17 00:00:00 2001 From: Florian Ludwig Date: Mon, 14 May 2018 18:49:02 +0200 Subject: [PATCH 08/38] add FiPy to README --- README.md | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 500457b2..1be082d2 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,7 @@ Currently supported IoT boards: - TTGOv2 {1}{4} - Pycom LoPy {2} - Pycom LoPy4 {2} +- Pycom FiPy {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} @@ -69,9 +70,9 @@ Use PlatformIO with your preferred IDE for # Uploading 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 +The LoPy/LoPy4/FiPy board needs to be set manually. See these 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. +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/FiPy. If you later want to go back to the Pycom firmware, download the firmware from Pycom and flash it over. # Legal note @@ -181,12 +182,12 @@ Note: all settings are stored in NVRAM and will be reloaded when device starts. 0 = disabled 1 = enabled [default] -0x0F set WIFI antenna switch (works on LoPy/LoPy4 only) +0x0F set WIFI antenna switch (works on LoPy/LoPy4/FiPy only) 0 = internal antenna [default] 1 = external antenna -0x10 set RGB led luminosity (works on LoPy/LoPy4 and LoRaNode32 shield only) +0x10 set RGB led luminosity (works on LoPy/LoPy4/FiPy and LoRaNode32 shield only) 0 ... 100 percentage of luminosity (100% = full light) e.g. 50 -> 50% of luminosity [default] @@ -221,7 +222,7 @@ device answers with it's current configuration. The configuration is a C structu # RGB Led color description -Description of the RGB LED color (LoPy/LoPy4 and Lolin32 only): +Description of the RGB LED color (LoPy/LoPy4/FiPy and Lolin32 only): - Yellow quick blink: joining LoRaWAN network in progress or pending - Blue blink: LoRaWAN data transmit (including waiting for receive windows) in progress or pending From 5d692bf8c768ec6fe932edcb4c72d72e897669e1 Mon Sep 17 00:00:00 2001 From: Verkehrsrot Date: Mon, 14 May 2018 20:31:29 +0200 Subject: [PATCH 09/38] Update fipy.h --- src/hal/fipy.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/hal/fipy.h b/src/hal/fipy.h index 31aa55f6..cccee3fb 100644 --- a/src/hal/fipy.h +++ b/src/hal/fipy.h @@ -1,10 +1,10 @@ -// Hardware related definitions for Pycom LoPy Board (not: LoPy4) +// Hardware related definitions for Pycom FiPy Board #define CFG_sx1272_radio 1 -#define HAS_LED NOT_A_PIN // LoPy4 has no on board LED, so we use RGB LED on LoPy4 +#define HAS_LED NOT_A_PIN // FiPy4 has no on board LED, so we use RGB LED #define HAS_RGB_LED 0 // WS2812B RGB LED on GPIO0 -// Hardware pin definitions for Pycom LoPy4 board +// Hardware pin definitions for Pycom FiPy board #define PIN_SPI_SS 18 #define PIN_SPI_MOSI 27 #define PIN_SPI_MISO 19 From c82ce3e26b69cef4f48f1e25b0c8848bd8126255 Mon Sep 17 00:00:00 2001 From: Verkehrsrot Date: Mon, 14 May 2018 20:35:10 +0200 Subject: [PATCH 10/38] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 046504c6..e7e1ebf0 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,7 @@ Currently supported IoT boards: - Heltec LoRa-32 {1} - TTGOv1 {1} - TTGOv2 {1}{4} +- TTGO2v.1 not yet, but coming soon - Pycom LoPy {2} - Pycom LoPy4 {2} - Pycom FiPy {2} From e2da3ec839034f5b36bf1c2a02b7d527f01e43d4 Mon Sep 17 00:00:00 2001 From: Verkehrsrot Date: Mon, 14 May 2018 20:35:42 +0200 Subject: [PATCH 11/38] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e7e1ebf0..7bdb8e6a 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ Currently supported IoT boards: - Heltec LoRa-32 {1} - TTGOv1 {1} - TTGOv2 {1}{4} -- TTGO2v.1 not yet, but coming soon +- TTGOv2.1 not yet, coming soon - Pycom LoPy {2} - Pycom LoPy4 {2} - Pycom FiPy {2} From 90f01fa6e080bd043c64c2fc06fe66a8997c8254 Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Mon, 14 May 2018 20:53:35 +0200 Subject: [PATCH 12/38] FiPy support added --- platformio.ini | 1 + src/hal/fipy.h | 2 +- src/hal/lopy.h | 2 +- src/hal/lopy4.h | 2 +- 4 files changed, 4 insertions(+), 3 deletions(-) diff --git a/platformio.ini b/platformio.ini index 8efbc391..59b9fbc3 100644 --- a/platformio.ini +++ b/platformio.ini @@ -16,6 +16,7 @@ env_default = heltec_wifi_lora_32 ;env_default = ttgov2 ;env_default = lopy ;env_default = lopy4 +;env_default = fipy ;env_default = lolin32lite_lora ;env_default = lolin32_lora ; diff --git a/src/hal/fipy.h b/src/hal/fipy.h index cccee3fb..7622d811 100644 --- a/src/hal/fipy.h +++ b/src/hal/fipy.h @@ -1,7 +1,7 @@ // Hardware related definitions for Pycom FiPy Board #define CFG_sx1272_radio 1 -#define HAS_LED NOT_A_PIN // FiPy4 has no on board LED, so we use RGB LED +#define HAS_LED NOT_A_PIN // FiPy has no on board LED, so we use RGB LED #define HAS_RGB_LED 0 // WS2812B RGB LED on GPIO0 // Hardware pin definitions for Pycom FiPy board diff --git a/src/hal/lopy.h b/src/hal/lopy.h index 3e34dc8f..219a3a96 100644 --- a/src/hal/lopy.h +++ b/src/hal/lopy.h @@ -12,7 +12,7 @@ #define RST 18 #define DIO0 23 // LoRa IRQ #define DIO1 23 // workaround -#define DIO2 LMIC_UNUSED_PIN // 23 workaround +#define DIO2 LMIC_UNUSED_PIN // select WIFI antenna (internal = onboard / external = u.fl socket) #define HAS_ANTENNA_SWITCH 16 // pin for switching wifi antenna diff --git a/src/hal/lopy4.h b/src/hal/lopy4.h index 223e26b5..aaed263a 100644 --- a/src/hal/lopy4.h +++ b/src/hal/lopy4.h @@ -12,7 +12,7 @@ #define RST LMIC_UNUSED_PIN #define DIO0 23 // LoRa IRQ #define DIO1 23 // workaround -#define DIO2 LMIC_UNUSED_PIN // 23 workaround +#define DIO2 LMIC_UNUSED_PIN // select WIFI antenna (internal = onboard / external = u.fl socket) #define HAS_ANTENNA_SWITCH 21 // pin for switching wifi antenna From 79f14b020ddafa358b75baf6dff603a83f3dad96 Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Tue, 15 May 2018 10:36:11 +0200 Subject: [PATCH 13/38] TTGOv2.1 support added --- README.md | 2 +- platformio.ini | 14 ++++++++++++++ src/hal/ttgov21.h | 28 ++++++++++++++++++++++++++++ 3 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 src/hal/ttgov21.h diff --git a/README.md b/README.md index 7bdb8e6a..ebb259b5 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ Currently supported IoT boards: - Heltec LoRa-32 {1} - TTGOv1 {1} - TTGOv2 {1}{4} -- TTGOv2.1 not yet, coming soon +- TTGOv2.1 (not yet tested) {1} - Pycom LoPy {2} - Pycom LoPy4 {2} - Pycom FiPy {2} diff --git a/platformio.ini b/platformio.ini index 59b9fbc3..518e995c 100644 --- a/platformio.ini +++ b/platformio.ini @@ -14,6 +14,7 @@ env_default = heltec_wifi_lora_32 ;env_default = ttgov1 ;env_default = ttgov2 +;env_default = ttgov21 ;env_default = lopy ;env_default = lopy4 ;env_default = fipy @@ -80,6 +81,19 @@ build_flags = -Dttgov2 -include "src/hal/ttgov2.h" +[env:ttgov21] +platform = espressif32 +framework = arduino +board = esp32dev +monitor_baud = 115200 +upload_speed = 921600 +lib_deps = + ${common_env_data.lib_deps_display} +build_flags = + ${common_env_data.build_flags} + -Dttgov2 + -include "src/hal/ttgov21.h" + [env:fipy] platform = espressif32 framework = arduino diff --git a/src/hal/ttgov21.h b/src/hal/ttgov21.h new file mode 100644 index 00000000..b5e38c94 --- /dev/null +++ b/src/hal/ttgov21.h @@ -0,0 +1,28 @@ +// Hardware related definitions for TTGO V2.1 Board +// NOT YET TESTED + +#define CFG_sx1276_radio 1 // HPD13A LoRa SoC + +#define HAS_DISPLAY U8X8_SSD1306_128X64_NONAME_HW_I2C +#define DISPLAY_FLIP 1 // rotated display +#define HAS_LED 23 + +// disable brownout detection (needed on TTGOv2 for battery powered operation) +#define DISABLE_BROWNOUT 1 // comment out if you want to keep brownout feature + +// re-define pin definitions of pins_arduino.h +#define PIN_SPI_SS 18 // ESP32 GPIO18 (Pin18) -- HPD13A NSS/SEL (Pin4) SPI Chip Select Input +#define PIN_SPI_MOSI 27 // ESP32 GPIO27 (Pin27) -- HPD13A MOSI/DSI (Pin6) SPI Data Input +#define PIN_SPI_MISO 19 // ESP32 GPIO19 (Pin19) -- HPD13A MISO/DSO (Pin7) SPI Data Output +#define PIN_SPI_SCK 5 // ESP32 GPIO5 (Pin5) -- HPD13A SCK (Pin5) SPI Clock Input + +// non arduino pin definitions +#define RST LMIC_UNUSED_PIN // connected to ESP32 RST/EN +#define DIO0 26 // ESP32 GPIO26 wired on PCB to HPD13A +#define DIO1 32 +#define DIO2 33 + +// Hardware pin definitions for TTGO V2 Board with OLED SSD1306 0,96" I2C Display +#define OLED_RST U8X8_PIN_NONE // connected to CPU RST/EN +#define OLED_SDA 21 // ESP32 GPIO4 (Pin4) -- SD1306 D1+D2 +#define OLED_SCL 22 // ESP32 GPIO15 (Pin15) -- SD1306 D0 \ No newline at end of file From 9b567fa844794a2aac9bbe461216c13d637c1347 Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Tue, 15 May 2018 10:41:04 +0200 Subject: [PATCH 14/38] low memory threshold --- src/main.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 3cdd289e..7497274f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -627,10 +627,9 @@ void loop() { #endif // check free memory - //if (ESP.getFreeHeap() <= MEM_LOW) { if (esp_get_minimum_free_heap_size() <= MEM_LOW) { - // ESP_LOGI(TAG, "Counter cleared (memory low = %d Bytes)", ESP.getFreeHeap()); - ESP_LOGI(TAG, "Counter cleared (memory low water mark = %d Bytes)", esp_get_minimum_free_heap_size()); + ESP_LOGI(TAG, "Memory full, counter cleared (heap low water mark = %d Bytes / free heap = %d bytes)", \ + esp_get_minimum_free_heap_size(), ESP.getFreeHeap()); do_send(&sendjob); // send count reset_counters(); // clear macs container and reset all counters reset_salt(); // get new salt for salting hashes From 094ffecced6c23f6c3ea098e04847d75cf20a9e3 Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Tue, 15 May 2018 11:49:46 +0200 Subject: [PATCH 15/38] settings for TTGOv2.1 adapted --- src/hal/ttgov21.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/hal/ttgov21.h b/src/hal/ttgov21.h index b5e38c94..a7bcba40 100644 --- a/src/hal/ttgov21.h +++ b/src/hal/ttgov21.h @@ -5,7 +5,7 @@ #define HAS_DISPLAY U8X8_SSD1306_128X64_NONAME_HW_I2C #define DISPLAY_FLIP 1 // rotated display -#define HAS_LED 23 +#define HAS_LED 23 // green on board LED G3 D0 // disable brownout detection (needed on TTGOv2 for battery powered operation) #define DISABLE_BROWNOUT 1 // comment out if you want to keep brownout feature @@ -18,9 +18,9 @@ // non arduino pin definitions #define RST LMIC_UNUSED_PIN // connected to ESP32 RST/EN -#define DIO0 26 // ESP32 GPIO26 wired on PCB to HPD13A -#define DIO1 32 -#define DIO2 33 +#define DIO0 26 // ESP32 GPIO26 <-> HPD13A IO0 +#define DIO1 33 // ESP32 GPIO33 <-> HPDIO1 <-> HPD13A IO1 +#define DIO2 32 // ESP32 GPIO32 <-> HPDIO2 <-> HPD13A IO2 // Hardware pin definitions for TTGO V2 Board with OLED SSD1306 0,96" I2C Display #define OLED_RST U8X8_PIN_NONE // connected to CPU RST/EN From a44587eb6370fc6fb62765643b2ab75a90d8ad9d Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Tue, 15 May 2018 11:55:52 +0200 Subject: [PATCH 16/38] small correction in ttgov21.h --- src/hal/ttgov21.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/hal/ttgov21.h b/src/hal/ttgov21.h index a7bcba40..8bf61742 100644 --- a/src/hal/ttgov21.h +++ b/src/hal/ttgov21.h @@ -5,7 +5,7 @@ #define HAS_DISPLAY U8X8_SSD1306_128X64_NONAME_HW_I2C #define DISPLAY_FLIP 1 // rotated display -#define HAS_LED 23 // green on board LED G3 D0 +#define HAS_LED 23 // green on board LED_G3 // disable brownout detection (needed on TTGOv2 for battery powered operation) #define DISABLE_BROWNOUT 1 // comment out if you want to keep brownout feature @@ -24,5 +24,5 @@ // Hardware pin definitions for TTGO V2 Board with OLED SSD1306 0,96" I2C Display #define OLED_RST U8X8_PIN_NONE // connected to CPU RST/EN -#define OLED_SDA 21 // ESP32 GPIO4 (Pin4) -- SD1306 D1+D2 +#define OLED_SDA 21 // ESP32 GPIO4 (Pin4) -- SD1306 D1+D2 #define OLED_SCL 22 // ESP32 GPIO15 (Pin15) -- SD1306 D0 \ No newline at end of file From c91be66fbbee02f1a2be78db1de869932e87da35 Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Fri, 18 May 2018 17:54:45 +0200 Subject: [PATCH 17/38] platformio.ini sanitized --- platformio.ini | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/platformio.ini b/platformio.ini index 518e995c..dffcf47f 100644 --- a/platformio.ini +++ b/platformio.ini @@ -11,15 +11,15 @@ ; ---> SELECT TARGET PLATFORM HERE! <--- [platformio] -env_default = heltec_wifi_lora_32 +env_default = heltec ;env_default = ttgov1 ;env_default = ttgov2 ;env_default = ttgov21 ;env_default = lopy ;env_default = lopy4 ;env_default = fipy -;env_default = lolin32lite_lora -;env_default = lolin32_lora +;env_default = lolin32lite +;env_default = lolin32 ; description = Paxcounter is a proof-of-concept ESP32 device for metering passenger flows in realtime. It counts how many mobile devices are around. @@ -42,17 +42,15 @@ build_flags = -D_lmic_config_h_ -include "src/paxcounter.conf" -[env:heltec_wifi_lora_32] +[env:heltec] platform = espressif32 framework = arduino board = heltec_wifi_lora_32 monitor_baud = 115200 -upload_speed = 115200 lib_deps = ${common_env_data.lib_deps_display} build_flags = ${common_env_data.build_flags} - -Dheltec_wifi_lora_32 -include "src/hal/heltec.h" [env:ttgov1] @@ -65,7 +63,6 @@ lib_deps = ${common_env_data.lib_deps_display} build_flags = ${common_env_data.build_flags} - -Dttgov1 -include "src/hal/ttgov1.h" [env:ttgov2] @@ -78,7 +75,6 @@ lib_deps = ${common_env_data.lib_deps_display} build_flags = ${common_env_data.build_flags} - -Dttgov2 -include "src/hal/ttgov2.h" [env:ttgov21] @@ -91,7 +87,6 @@ lib_deps = ${common_env_data.lib_deps_display} build_flags = ${common_env_data.build_flags} - -Dttgov2 -include "src/hal/ttgov21.h" [env:fipy] @@ -104,7 +99,6 @@ lib_deps = ${common_env_data.lib_deps_rgbled} build_flags = ${common_env_data.build_flags} - -Dlopy -include "src/hal/fipy.h" [env:lopy] @@ -117,7 +111,6 @@ lib_deps = ${common_env_data.lib_deps_rgbled} build_flags = ${common_env_data.build_flags} - -Dlopy -include "src/hal/lopy.h" [env:lopy4] @@ -130,10 +123,9 @@ lib_deps = ${common_env_data.lib_deps_rgbled} build_flags = ${common_env_data.build_flags} - -Dlopy4 -include "src/hal/lopy4.h" -[env:lolin32lite_lora] +[env:lolin32lite] platform = espressif32 framework = arduino board = lolin32 @@ -143,10 +135,9 @@ lib_deps = ${common_env_data.lib_deps_rgbled} build_flags = ${common_env_data.build_flags} - -Dlolin32lite_lora -include "src/hal/lolin32lite_lora.h" -[env:lolin32_lora] +[env:lolin32] platform = espressif32 framework = arduino board = lolin32 @@ -156,5 +147,4 @@ lib_deps = ${common_env_data.lib_deps_rgbled} build_flags = ${common_env_data.build_flags} - -Dlolin32_lora -include "src/hal/lolin32_lora.h" \ No newline at end of file From f79976a350de6593b3a6f603c20715977fa82e90 Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Sat, 19 May 2018 13:44:52 +0200 Subject: [PATCH 18/38] platformio.ini: changed monitor_baud -> monitor_speed --- platformio.ini | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/platformio.ini b/platformio.ini index dffcf47f..fc426838 100644 --- a/platformio.ini +++ b/platformio.ini @@ -46,7 +46,7 @@ build_flags = platform = espressif32 framework = arduino board = heltec_wifi_lora_32 -monitor_baud = 115200 +monitor_speed = 115200 lib_deps = ${common_env_data.lib_deps_display} build_flags = @@ -57,7 +57,7 @@ build_flags = platform = espressif32 framework = arduino board = esp32dev -monitor_baud = 115200 +monitor_speed = 115200 upload_speed = 115200 lib_deps = ${common_env_data.lib_deps_display} @@ -69,7 +69,7 @@ build_flags = platform = espressif32 framework = arduino board = esp32dev -monitor_baud = 115200 +monitor_speed = 115200 upload_speed = 921600 lib_deps = ${common_env_data.lib_deps_display} @@ -81,7 +81,7 @@ build_flags = platform = espressif32 framework = arduino board = esp32dev -monitor_baud = 115200 +monitor_speed = 115200 upload_speed = 921600 lib_deps = ${common_env_data.lib_deps_display} @@ -93,7 +93,7 @@ build_flags = platform = espressif32 framework = arduino board = esp32dev -monitor_baud = 115200 +monitor_speed = 115200 upload_speed = 921600 lib_deps = ${common_env_data.lib_deps_rgbled} @@ -105,7 +105,7 @@ build_flags = platform = espressif32 framework = arduino board = esp32dev -monitor_baud = 115200 +monitor_speed = 115200 upload_speed = 921600 lib_deps = ${common_env_data.lib_deps_rgbled} @@ -117,7 +117,7 @@ build_flags = platform = espressif32 framework = arduino board = esp32dev -monitor_baud = 115200 +monitor_speed = 115200 upload_speed = 921600 lib_deps = ${common_env_data.lib_deps_rgbled} @@ -129,7 +129,7 @@ build_flags = platform = espressif32 framework = arduino board = lolin32 -monitor_baud = 115200 +monitor_speed = 115200 upload_speed = 256000 lib_deps = ${common_env_data.lib_deps_rgbled} @@ -141,7 +141,7 @@ build_flags = platform = espressif32 framework = arduino board = lolin32 -monitor_baud = 115200 +monitor_speed = 115200 upload_speed = 921600 lib_deps = ${common_env_data.lib_deps_rgbled} From ca7773403954db1b9bbb024a19abdc5397ff2824 Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Sat, 19 May 2018 16:55:18 +0200 Subject: [PATCH 19/38] bluetooth infinite scan --- README.md | 18 +++++++++--------- src/blecsan.cpp | 6 +++--- src/configmanager.cpp | 2 +- src/main.h | 2 +- src/paxcounter.conf | 12 ++++++------ src/rcommand.cpp | 25 +++++++++++++++++++++++++ 6 files changed, 45 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index ebb259b5..255dbd8e 100644 --- a/README.md +++ b/README.md @@ -148,27 +148,27 @@ Note: all settings are stored in NVRAM and will be reloaded when device starts. 1 = reset MAC counter to zero 2 = reset device to factory settings -0x0A set payload send cycle +0x0A set LoRaWAN payload send cycle 0 ... 255 payload send cycle in seconds/2 e.g. 120 -> payload is transmitted each 240 seconds [default] 0x0B set Wifi channel switch interval timer - 0 ... 255 timeout for scanning 1 wifi channel in seconds/100 + 0 ... 255 duration for scanning one wifi channel in seconds/100 e.g. 50 -> each channel is scanned for 0,5 seconds [default] -0x0C set BLE scan cycle timer +0x0C set Bluetooth channel switch interval timer - 0 ... 255 duration of a BLE scan cycle in seconds - e.g. 11 -> 1 cycle runs for 11 seconds [default] + 0 ... 255 duration for scanning one bluetooth channel in seconds/100 + e.g. 1 -> each channel is scanned for 10 milliseconds [default] 0x0D (NOT YET IMPLEMENTED) set BLE and WIFI vendorfilter mode 0 = disabled (use to count devices, not people) 1 = enabled [default] -0x0E set BLE scan mode +0x0E set Bluetooth scanner 0 = disabled 1 = enabled [default] @@ -194,10 +194,10 @@ device answers with it's current configuration. The configuration is a C structu byte 5: Display status (1=on, 0=off) byte 6: Counter mode (0=cyclic unconfirmed, 1=cumulative, 2=cyclic confirmed) bytes 7-8: RSSI limiter threshold value (negative) - byte 9: Payload send cycle in seconds/2 (0..255) + byte 9: Lora Payload send cycle in seconds/2 (0..255) byte 10: Wifi channel switch interval in seconds/100 (0..255) - byte 11: BLE scan cycle duration in seconds (0..255) - byte 12: BLE scan mode (1=on, 0=0ff) + byte 11: Bluetooth channel switch interval in seconds/100 (0..255) + byte 12: Bluetooth scanner status (1=on, 0=0ff) byte 13: Wifi antenna switch (0=internal, 1=external) byte 14: Vendorfilter mode (0=disabled, 1=enabled) byte 15: RGB LED luminosity (0..100 %) diff --git a/src/blecsan.cpp b/src/blecsan.cpp index 41678a2f..fdc96630 100644 --- a/src/blecsan.cpp +++ b/src/blecsan.cpp @@ -100,7 +100,7 @@ static void gap_callback_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_pa { case ESP_GAP_BLE_SCAN_PARAM_SET_COMPLETE_EVT: // restart scan - status = esp_ble_gap_start_scanning(cfg.blescantime); + status = esp_ble_gap_start_scanning(BLESCANTIME); if (status != ESP_OK) { ESP_LOGE(TAG, "esp_ble_gap_start_scanning: rc=%d", status); @@ -111,7 +111,7 @@ static void gap_callback_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_pa // evaluate scan results if ( p->scan_rst.search_evt == ESP_GAP_SEARCH_INQ_CMPL_EVT) // Inquiry complete, scan is done { // restart scan - status = esp_ble_gap_start_scanning (cfg.blescantime); + status = esp_ble_gap_start_scanning (BLESCANTIME); if (status != ESP_OK) { ESP_LOGE(TAG, "esp_ble_gap_start_scanning: rc=%d", status); @@ -207,7 +207,7 @@ esp_err_t register_ble_functionality(void) #else .scan_filter_policy = BLE_SCAN_FILTER_ALLOW_ALL, #endif - .scan_interval = (uint16_t) (BLESCANINTERVAL / 0.625), // Time = N * 0.625 msec + .scan_interval = (uint16_t) (cfg.blescantime * 10 / 0.625), // Time = N * 0.625 msec .scan_window = (uint16_t) (BLESCANWINDOW / 0.625) // Time = N * 0.625 msec }; diff --git a/src/configmanager.cpp b/src/configmanager.cpp index 74c26206..808af4b6 100644 --- a/src/configmanager.cpp +++ b/src/configmanager.cpp @@ -27,7 +27,7 @@ void defaultConfig() { cfg.rssilimit = 0; // threshold for rssilimiter, negative value! cfg.sendcycle = SEND_SECS; // payload send cycle [seconds/2] cfg.wifichancycle = WIFI_CHANNEL_SWITCH_INTERVAL; // wifi channel switch cycle [seconds/100] - cfg.blescantime = BLESCANTIME; // BLE scan cycle duration [seconds] + cfg.blescantime = BLESCANINTERVAL / 10; // BT channel scan cycle duration [seconds/100], default 1 (= 10ms) cfg.blescan = 1; // 0=disabled, 1=enabled cfg.wifiant = 0; // 0=internal, 1=external (for LoPy/LoPy4) cfg.vendorfilter = 1; // 0=disabled, 1=enabled diff --git a/src/main.h b/src/main.h index b9556935..f8047656 100644 --- a/src/main.h +++ b/src/main.h @@ -1,6 +1,6 @@ // program version - note: increment version after modifications to configData_t struct!! -#define PROGVERSION "1.3.42" // use max 10 chars here! +#define PROGVERSION "1.3.5" // use max 10 chars here! #define PROGNAME "PAXCNT" //--- Declarations --- diff --git a/src/paxcounter.conf b/src/paxcounter.conf index 8ab4da35..4cfb4a4a 100644 --- a/src/paxcounter.conf +++ b/src/paxcounter.conf @@ -11,18 +11,18 @@ // BLE scan parameters #define BLESTACKSIZE 8192 // stack size for esp_bt_controller -#define BLESCANTIME 11 // [seconds] scan duration, see note below +#define BLESCANTIME 0 // [seconds] scan duration, 0 means infinite [default], see note below #define BLESCANWINDOW 10 // [milliseconds] scan window, see below, 3 .. 10240, default 10 #define BLESCANINTERVAL 10 // [milliseconds] how long to wait between scans, 3 .. 10240, default 10 /* Note: guide for setting bluetooth parameters * -* |< Scan Window > |< Scan Window > |< Scan Window > | -* |< Scan Interval >|< Scan Interval >|< Scan Interval >| -* |< Scan duration >| +* |< Scan Window > |< Scan Window > | ... |< Scan Window > | +* |< Scan Interval >|< Scan Interval >| ... |< Scan Interval >| +* |< Scan duration >| * -* Scan duration sets how long scanning should be going on, interrupting a wifi scan cycle. -* Scan window sets how much of the interval should be occupied by scanning. +* Scan duration sets how long scanning should be going on, before starting a new scan cycle. 0 means infinite (default). +* Scan window sets how much of the interval should be occupied by scanning. Should be >= BLESCANINTERVAL. * Scan interval is how long scanning should be done on each channel. BLE uses 3 channels for advertising. * -> Adjust these values with power consumption in mind if power is limited. */ diff --git a/src/rcommand.cpp b/src/rcommand.cpp index 95ccee33..9cc533c0 100644 --- a/src/rcommand.cpp +++ b/src/rcommand.cpp @@ -9,6 +9,12 @@ #include #include +// Bluetooth specific includes +#ifdef BLECOUNTER + #include // needed for switching interval parameter by rcommand + esp_err_t register_ble_functionality(void); // defined in blescan.cpp +#endif + // Local logging tag static const char *TAG = "rcommand"; @@ -92,6 +98,25 @@ void set_wifichancycle(uint8_t val) { void set_blescantime(uint8_t val) { cfg.blescantime = val; ESP_LOGI(TAG, "Remote command: set BLE scan time to %d seconds", cfg.blescantime); + #ifdef BLECOUNTER + + // stop scan + ESP_LOGI(TAG, "Stopping BLE scan"); + if (esp_ble_gap_stop_scanning() != ESP_OK) + ESP_LOGE(TAG, "Stopping BLE scan failed"); + + // modify parameters + ESP_LOGI(TAG, "Re-register BLE functionality"); + if (register_ble_functionality() != ESP_OK) + ESP_LOGE(TAG, "Re-register BLE functionality failed"); + + // restart scan + ESP_LOGI(TAG, "Restarting BLE scan"); + if (esp_ble_gap_start_scanning(BLESCANTIME) != ESP_OK) + ESP_LOGE(TAG, "Restarting BLE scan failed"); + + + #endif }; void set_countmode(uint8_t val) { From 7c42fe62fc7809c893a9e803625f9fb96c0ac829 Mon Sep 17 00:00:00 2001 From: Verkehrsrot Date: Sat, 19 May 2018 17:05:13 +0200 Subject: [PATCH 20/38] update legal notes in readme.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 255dbd8e..a292d313 100644 --- a/README.md +++ b/README.md @@ -73,7 +73,7 @@ The original Pycom firmware is not needed, so there is no need to update it befo (e.g. UK citizens may want to check [Data Protection Act 1998](https://ico.org.uk/media/1560691/wi-fi-location-analytics-guidance.pdf) and [GDPR 2018](https://ico.org.uk/for-organisations/guide-to-the-general-data-protection-regulation-gdpr/key-definitions/)) -(e.g. Citizens in the the Netherlands may want to read [this article](https://www.ivir.nl/publicaties/download/PrivacyInformatie_2016_6.pdf)) +(e.g. Citizens in the the Netherlands may want to read [this article](https://www.ivir.nl/publicaties/download/PrivacyInformatie_2016_6.pdf) and [this article](https://autoriteitpersoonsgegevens.nl/nl/nieuws/europese-privacytoezichthouders-publiceren-opinie-eprivacyverordening)) Note: If you use this software you do this at your own risk. That means that you alone - not the authors of this software - are responsible for the legal compliance of an application using this or build from this software and/or usage of a device created using this software. You should take special care and get prior legal advice if you plan metering passengers in public areas and/or publish data drawn from doing so. From 624d24d1c63f2f069880c895dd923b0d501b1822 Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Sun, 20 May 2018 11:47:13 +0200 Subject: [PATCH 21/38] loraconf.sample.h --- src/loraconf.sample.h | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/loraconf.sample.h b/src/loraconf.sample.h index d5596162..ea8f3211 100644 --- a/src/loraconf.sample.h +++ b/src/loraconf.sample.h @@ -1,22 +1,25 @@ /************************************************************ * LMIC LoRaWAN configuration * - * Read the values from TTN console (or whatever applies) + * Read the values from TTN console (or whatever applies), insert them here, + * and rename this file to src/loraconf.h + + * Set your DEVEUI here, if you have one. You can leave this untouched, + * then the DEVEUI will be generated during runtime from device's MAC adress + * and will be displayed on device's screen as well as on serial console. + * + * NOTE: Use MSB format (as displayed in TTN console, so you can cut & paste from there) + * For TTN, APPEUI in MSB format always starts with 0x70, 0xB3, 0xD5 + * + * Note: If using a board with Microchip 24AA02E64 Uinique ID for deveui, + * the DEVEUI will be overwriten by the one contained in the Microchip module * ************************************************************/ #include -// Set your DEVEUI here, if you have one. You can leave this untouched, -// then the DEVEUI will be generated during runtime from device's MAC adress -// Note: Use same format as in TTN console (cut & paste, for your convenience) -// *** Take care : If Using a board with Microchip 24AA02E64 Uinique ID for deveui, ** -// *** this DEVEUI will be overwriten by the one contained in the Microchip module *** static const u1_t DEVEUI[8]={ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; -// Note: Use msb format for APPEUI as in TTN console (cut & paste, for your convenience) -// For TTN, APPEUI always starts with 0x70, 0xB3, 0xD5 static const u1_t APPEUI[8]={ 0x70, 0xB3, 0xD5, 0x00, 0x00, 0x00, 0x00, 0x00 }; -// Note: Use msb format for APPEUI as in TTN console (cut & paste, for your convenience) static const u1_t APPKEY[16] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; \ No newline at end of file From 9bdc7291d8f5ada73550215718c60f3a0405fcbc Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Sun, 20 May 2018 13:50:00 +0200 Subject: [PATCH 22/38] bluetooth tasking reworked --- src/blecsan.cpp | 26 +++++++++++++------------- src/main.cpp | 8 ++++---- src/main.h | 5 ++++- src/paxcounter.conf | 5 +++-- src/rcommand.cpp | 39 ++++++++++++++------------------------- 5 files changed, 38 insertions(+), 45 deletions(-) diff --git a/src/blecsan.cpp b/src/blecsan.cpp index fdc96630..9ca85b2a 100644 --- a/src/blecsan.cpp +++ b/src/blecsan.cpp @@ -224,11 +224,17 @@ esp_err_t register_ble_functionality(void) return ESP_OK ; } +void stop_BLEscan(void){ + ESP_LOGI(TAG, "Shutting BT Down ..."); + esp_ble_gap_register_callback(NULL); + esp_bluedroid_disable(); + esp_bluedroid_deinit(); + esp_bt_controller_disable(); + esp_bt_controller_deinit(); +} -// Main start code running in its own Xtask -void bt_loop(void * pvParameters) -{ - configASSERT( ( ( uint32_t ) pvParameters ) == 1 ); // FreeRTOS check +void start_BLEscan(void){ + ESP_LOGI(TAG, "Initializing bluetooth scanner ..."); esp_err_t status; @@ -277,15 +283,9 @@ void bt_loop(void * pvParameters) goto end; } - while(1) - { - vTaskDelay(10/portTICK_PERIOD_MS); // reset watchdog - } - end: - ESP_LOGI(TAG, "Terminating BT logging task"); - vTaskDelete(NULL); - -} // bt_loop +ESP_LOGI(TAG, "Bluetooth scanner initialization finished"); + +} // start_BLEscan #endif // BLECOUNTER \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 7497274f..f099049b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -583,17 +583,17 @@ wifi_sniffer_init(); // setup wifi in monitor mode and start MAC counting // note: do this *after* wifi has started, since gets it's seed from RF noise reset_salt(); // get new 16bit for salting hashes -// run wifi task on core 0 and lora task on core 1 and bt task on core 0 +// run wifi channel switching task on core 0 and lora lmic task on core 1 (arduino main loop runs on core 1) ESP_LOGI(TAG, "Starting Lora task on core 1"); xTaskCreatePinnedToCore(lorawan_loop, "loratask", 2048, ( void * ) 1, ( 5 | portPRIVILEGE_BIT ), NULL, 1); ESP_LOGI(TAG, "Starting Wifi task on core 0"); xTaskCreatePinnedToCore(sniffer_loop, "wifisniffer", 2048, ( void * ) 1, 1, NULL, 0); +// start BLE scan callback if BLE function is enabled in NVRAM configuration #ifdef BLECOUNTER - if (cfg.blescan) { // start BLE task only if BLE function is enabled in NVRAM configuration - ESP_LOGI(TAG, "Starting Bluetooth task on core 0"); - xTaskCreatePinnedToCore(bt_loop, "btscan", 4096, ( void * ) 1, 1, NULL, 0); + if (cfg.blescan) { + start_BLEscan(); } #endif diff --git a/src/main.h b/src/main.h index f8047656..197924ec 100644 --- a/src/main.h +++ b/src/main.h @@ -41,4 +41,7 @@ void wifi_sniffer_set_channel(uint8_t channel); void wifi_sniffer_packet_handler(void *buff, wifi_promiscuous_pkt_type_t type); // defined in blescan.cpp -void bt_loop(void *ignore); +#ifdef BLECOUNTER + void start_BLEscan(void); + void stop_BLEscan(void); +#endif \ No newline at end of file diff --git a/src/paxcounter.conf b/src/paxcounter.conf index 4cfb4a4a..d18f3248 100644 --- a/src/paxcounter.conf +++ b/src/paxcounter.conf @@ -7,13 +7,13 @@ // set this to include BLE counting and vendor filter functions #define VENDORFILTER 1 // comment out if you want to count things, not people -#define BLECOUNTER 1 // comment out if you don't want BLE count +#define BLECOUNTER 1 // comment out if you don't want BLE count, saves power & memory // BLE scan parameters #define BLESTACKSIZE 8192 // stack size for esp_bt_controller #define BLESCANTIME 0 // [seconds] scan duration, 0 means infinite [default], see note below #define BLESCANWINDOW 10 // [milliseconds] scan window, see below, 3 .. 10240, default 10 -#define BLESCANINTERVAL 10 // [milliseconds] how long to wait between scans, 3 .. 10240, default 10 +#define BLESCANINTERVAL 10 // [milliseconds] scan interval, see below, 3 .. 10240, default 10 /* Note: guide for setting bluetooth parameters * @@ -25,6 +25,7 @@ * Scan window sets how much of the interval should be occupied by scanning. Should be >= BLESCANINTERVAL. * Scan interval is how long scanning should be done on each channel. BLE uses 3 channels for advertising. * -> Adjust these values with power consumption in mind if power is limited. +* -> Scan interval can be changed during runtime by remote comammand. */ // WiFi scan parameters diff --git a/src/rcommand.cpp b/src/rcommand.cpp index 9cc533c0..1920abf5 100644 --- a/src/rcommand.cpp +++ b/src/rcommand.cpp @@ -9,12 +9,6 @@ #include #include -// Bluetooth specific includes -#ifdef BLECOUNTER - #include // needed for switching interval parameter by rcommand - esp_err_t register_ble_functionality(void); // defined in blescan.cpp -#endif - // Local logging tag static const char *TAG = "rcommand"; @@ -97,25 +91,14 @@ void set_wifichancycle(uint8_t val) { void set_blescantime(uint8_t val) { cfg.blescantime = val; - ESP_LOGI(TAG, "Remote command: set BLE scan time to %d seconds", cfg.blescantime); + ESP_LOGI(TAG, "Remote command: set BLE scan time to %.1f seconds", cfg.blescantime/float(100)); #ifdef BLECOUNTER - - // stop scan - ESP_LOGI(TAG, "Stopping BLE scan"); - if (esp_ble_gap_stop_scanning() != ESP_OK) - ESP_LOGE(TAG, "Stopping BLE scan failed"); - - // modify parameters - ESP_LOGI(TAG, "Re-register BLE functionality"); - if (register_ble_functionality() != ESP_OK) - ESP_LOGE(TAG, "Re-register BLE functionality failed"); - - // restart scan - ESP_LOGI(TAG, "Restarting BLE scan"); - if (esp_ble_gap_start_scanning(BLESCANTIME) != ESP_OK) - ESP_LOGE(TAG, "Restarting BLE scan failed"); - - + // stop & restart BLE scan task to apply new parameter + if (cfg.blescan) + { + stop_BLEscan(); + start_BLEscan(); + } #endif }; @@ -167,14 +150,20 @@ void set_loraadr(uint8_t val) { }; void set_blescan(uint8_t val) { - ESP_LOGI(TAG, "Remote command: set BLE scan mode to %s", val ? "on" : "off"); + ESP_LOGI(TAG, "Remote command: set BLE scanner to %s", val ? "on" : "off"); switch (val) { case 0: cfg.blescan = 0; macs_ble = 0; // clear BLE counter + #ifdef BLECOUNTER + stop_BLEscan(); + #endif break; default: cfg.blescan = 1; + #ifdef BLECOUNTER + start_BLEscan(); + #endif break; } }; From 30178bbf433f2212325136d5c6242189d42daec0 Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Sun, 20 May 2018 16:28:12 +0200 Subject: [PATCH 23/38] scan performance optimizations --- README.md | 2 +- platformio.ini | 4 ++-- src/blecsan.cpp | 16 ++++++++-------- src/loraconf.sample.h | 3 +++ src/macsniff.cpp | 3 ++- src/main.cpp | 2 +- src/main.h | 2 +- src/paxcounter.conf | 4 ++-- 8 files changed, 20 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index a292d313..cf0fa620 100644 --- a/README.md +++ b/README.md @@ -161,7 +161,7 @@ Note: all settings are stored in NVRAM and will be reloaded when device starts. 0x0C set Bluetooth channel switch interval timer 0 ... 255 duration for scanning one bluetooth channel in seconds/100 - e.g. 1 -> each channel is scanned for 10 milliseconds [default] + e.g. 3 -> each channel is scanned for 30 milliseconds [default] 0x0D (NOT YET IMPLEMENTED) set BLE and WIFI vendorfilter mode diff --git a/platformio.ini b/platformio.ini index fc426838..5f08fca6 100644 --- a/platformio.ini +++ b/platformio.ini @@ -33,8 +33,8 @@ build_flags = ; ---> 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_NONE +; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_INFO ; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_VERBOSE ; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_DEBUG ; diff --git a/src/blecsan.cpp b/src/blecsan.cpp index 9ca85b2a..777e1ee9 100644 --- a/src/blecsan.cpp +++ b/src/blecsan.cpp @@ -88,8 +88,8 @@ static const char *btsig_gap_type(uint32_t gap_type) { } } // btsig_gap_type - -static void gap_callback_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *param) +// using IRAM_:ATTR here to speed up callback function +IRAM_ATTR 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; @@ -188,7 +188,7 @@ esp_err_t register_ble_functionality(void) // 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); + status = esp_ble_gap_register_callback(&gap_callback_handler); if (status != ESP_OK) { ESP_LOGE(TAG, "esp_ble_gap_register_callback: rc=%d", status); @@ -226,11 +226,11 @@ esp_err_t register_ble_functionality(void) void stop_BLEscan(void){ ESP_LOGI(TAG, "Shutting BT Down ..."); - esp_ble_gap_register_callback(NULL); - esp_bluedroid_disable(); - esp_bluedroid_deinit(); - esp_bt_controller_disable(); - esp_bt_controller_deinit(); + ESP_ERROR_CHECK(esp_ble_gap_register_callback(NULL)); + ESP_ERROR_CHECK(esp_bluedroid_disable()); + ESP_ERROR_CHECK(esp_bluedroid_deinit()); + ESP_ERROR_CHECK(esp_bt_controller_disable()); + ESP_ERROR_CHECK(esp_bt_controller_deinit()); } void start_BLEscan(void){ diff --git a/src/loraconf.sample.h b/src/loraconf.sample.h index ea8f3211..ec816959 100644 --- a/src/loraconf.sample.h +++ b/src/loraconf.sample.h @@ -3,6 +3,9 @@ * * Read the values from TTN console (or whatever applies), insert them here, * and rename this file to src/loraconf.h + * + * Note that DEVEUI, APPEUI and APPKEY should all be specified in MSB format. + * (This is different from standard LMIC-Arduino which expects DEVEUI and APPEUI in LSB format.) * Set your DEVEUI here, if you have one. You can leave this untouched, * then the DEVEUI will be generated during runtime from device's MAC adress diff --git a/src/macsniff.cpp b/src/macsniff.cpp index fbaa01d6..a3712b1a 100644 --- a/src/macsniff.cpp +++ b/src/macsniff.cpp @@ -102,7 +102,8 @@ void wifi_sniffer_set_channel(uint8_t channel) { esp_wifi_set_channel(channel, WIFI_SECOND_CHAN_NONE); } -void wifi_sniffer_packet_handler(void* buff, wifi_promiscuous_pkt_type_t type) { +// using IRAM_:ATTR here to speed up callback function +IRAM_ATTR void wifi_sniffer_packet_handler(void* buff, wifi_promiscuous_pkt_type_t type) { const wifi_promiscuous_pkt_t *ppkt = (wifi_promiscuous_pkt_t *)buff; const wifi_ieee80211_packet_t *ipkt = (wifi_ieee80211_packet_t *)ppkt->payload; const wifi_ieee80211_mac_hdr_t *hdr = &ipkt->hdr; diff --git a/src/main.cpp b/src/main.cpp index f099049b..7c42b7f0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -327,7 +327,7 @@ uint64_t uptime() { if (cfg.blescan) u8x8.printf("BLTH:%-4d", macs_ble); else - u8x8.printf("%-16s", "BLTH:off"); + u8x8.printf("%s", "BLTH:off"); #endif // update LoRa SF display (line 3) diff --git a/src/main.h b/src/main.h index 197924ec..71220c44 100644 --- a/src/main.h +++ b/src/main.h @@ -1,6 +1,6 @@ // program version - note: increment version after modifications to configData_t struct!! -#define PROGVERSION "1.3.5" // use max 10 chars here! +#define PROGVERSION "1.3.51" // use max 10 chars here! #define PROGNAME "PAXCNT" //--- Declarations --- diff --git a/src/paxcounter.conf b/src/paxcounter.conf index d18f3248..8412d90f 100644 --- a/src/paxcounter.conf +++ b/src/paxcounter.conf @@ -12,8 +12,8 @@ // BLE scan parameters #define BLESTACKSIZE 8192 // stack size for esp_bt_controller #define BLESCANTIME 0 // [seconds] scan duration, 0 means infinite [default], see note below -#define BLESCANWINDOW 10 // [milliseconds] scan window, see below, 3 .. 10240, default 10 -#define BLESCANINTERVAL 10 // [milliseconds] scan interval, see below, 3 .. 10240, default 10 +#define BLESCANWINDOW 0x50 // [milliseconds] scan window, see below, 3 .. 10240, default 80ms +#define BLESCANINTERVAL 0x50 // [milliseconds] scan interval, see below, 3 .. 10240, default 80ms = 100% duty cycle /* Note: guide for setting bluetooth parameters * From ed25ec1e928e8f5b47e4f0387e352598da65350d Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Sun, 20 May 2018 18:31:41 +0200 Subject: [PATCH 24/38] blescan.cpp code refactoring --- src/blecsan.cpp | 123 +++++++++++++----------------------------------- 1 file changed, 34 insertions(+), 89 deletions(-) diff --git a/src/blecsan.cpp b/src/blecsan.cpp index 777e1ee9..3610def6 100644 --- a/src/blecsan.cpp +++ b/src/blecsan.cpp @@ -17,7 +17,7 @@ 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"; +static const char *TAG = "blescan"; // defined in macsniff.cpp bool mac_add(uint8_t *paddr, int8_t rssi, bool sniff_type); @@ -100,22 +100,14 @@ IRAM_ATTR static void gap_callback_handler(esp_gap_ble_cb_event_t event, esp_ble { 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); - } + ESP_ERROR_CHECK(esp_ble_gap_start_scanning(BLESCANTIME)); break; case ESP_GAP_BLE_SCAN_RESULT_EVT: // evaluate scan results if ( p->scan_rst.search_evt == ESP_GAP_SEARCH_INQ_CMPL_EVT) // Inquiry complete, scan is done { // restart scan - status = esp_ble_gap_start_scanning (BLESCANTIME); - if (status != ESP_OK) - { - ESP_LOGE(TAG, "esp_ble_gap_start_scanning: rc=%d", status); - } + ESP_ERROR_CHECK(esp_ble_gap_start_scanning(BLESCANTIME)); return; } @@ -140,8 +132,7 @@ IRAM_ATTR static void gap_callback_handler(esp_gap_ble_cb_event_t event, esp_ble #endif // add this device and show new count total if it was not previously added - 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); + mac_add((uint8_t *) p->scan_rst.bda, p->scan_rst.rssi, MAC_SNIFF_BLE); /* to be improved in vendorfilter if: @@ -180,20 +171,12 @@ IRAM_ATTR static void gap_callback_handler(esp_gap_ble_cb_event_t event, esp_ble } // gap_callback_handler -esp_err_t register_ble_functionality(void) -{ - esp_err_t status; - +esp_err_t register_ble_callback(void) { 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; - } + ESP_ERROR_CHECK(esp_ble_gap_register_callback(&gap_callback_handler)); static esp_ble_scan_params_t ble_scan_params = { @@ -207,85 +190,47 @@ esp_err_t register_ble_functionality(void) #else .scan_filter_policy = BLE_SCAN_FILTER_ALLOW_ALL, #endif + .scan_interval = (uint16_t) (cfg.blescantime * 10 / 0.625), // Time = N * 0.625 msec .scan_window = (uint16_t) (BLESCANWINDOW / 0.625) // Time = N * 0.625 msec }; - 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); - if (status != ESP_OK) - { - ESP_LOGE(TAG, "esp_ble_gap_set_scan_params: rc=%d", status); - return ESP_FAIL; - } + ESP_ERROR_CHECK(esp_ble_gap_set_scan_params(&ble_scan_params)); - return ESP_OK ; -} + return ESP_OK; + +} // register_ble_callback + +void start_BLEscan(void){ + ESP_LOGI(TAG, "Initializing bluetooth scanner ..."); + + // Initialize BT controller to allocate task and other resource. + esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT(); + bt_cfg.controller_task_stack_size = BLESTACKSIZE; // set BT stack size to value configured in paxcounter.conf + ESP_ERROR_CHECK(esp_bt_controller_init(&bt_cfg)); + ESP_ERROR_CHECK(esp_bt_controller_enable(ESP_BT_MODE_BTDM)); + + // Init and alloc the resource for bluetooth stack, must be done prior to every bluetooth stuff + ESP_ERROR_CHECK(esp_bluedroid_init()); + ESP_ERROR_CHECK(esp_bluedroid_enable()); + + // Register callback function for capturing bluetooth packets + ESP_ERROR_CHECK(register_ble_callback()); + + ESP_LOGI(TAG, "Bluetooth scanner started"); +} // start_BLEscan void stop_BLEscan(void){ - ESP_LOGI(TAG, "Shutting BT Down ..."); + ESP_LOGI(TAG, "Shutting down bluetooth scanner ..."); ESP_ERROR_CHECK(esp_ble_gap_register_callback(NULL)); ESP_ERROR_CHECK(esp_bluedroid_disable()); ESP_ERROR_CHECK(esp_bluedroid_deinit()); ESP_ERROR_CHECK(esp_bt_controller_disable()); ESP_ERROR_CHECK(esp_bt_controller_deinit()); -} - -void start_BLEscan(void){ - ESP_LOGI(TAG, "Initializing bluetooth scanner ..."); - - esp_err_t status; - - // 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(); - bt_cfg.controller_task_stack_size = BLESTACKSIZE; // set BT stack size to value configured in paxcounter.conf - - 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_bt_controller_mem_release(ESP_BT_MODE_BTDM); // gives 30KB more RAM for heap - - // 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) - { - 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, "Register BLE functionality"); - status = register_ble_functionality(); - if (status != ESP_OK) - { - ESP_LOGE(TAG, "Register BLE functionality failed"); - goto end; - } - -end: -ESP_LOGI(TAG, "Bluetooth scanner initialization finished"); - -} // start_BLEscan + ESP_LOGI(TAG, "Bluetooth scanner stopped"); +} // stop_BLEscan #endif // BLECOUNTER \ No newline at end of file From 45066af7c942785c23af1e877441d30c05e07d36 Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Sun, 20 May 2018 21:21:47 +0200 Subject: [PATCH 25/38] readme.md and ble default timings --- README.md | 8 ++++---- src/paxcounter.conf | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index cf0fa620..98d8f2f1 100644 --- a/README.md +++ b/README.md @@ -155,13 +155,13 @@ Note: all settings are stored in NVRAM and will be reloaded when device starts. 0x0B set Wifi channel switch interval timer - 0 ... 255 duration for scanning one wifi channel in seconds/100 - e.g. 50 -> each channel is scanned for 0,5 seconds [default] + 0 ... 255 duration for scanning a wifi channel in seconds/100 + e.g. 50 -> each channel is scanned for 500 milliseconds [default] 0x0C set Bluetooth channel switch interval timer - 0 ... 255 duration for scanning one bluetooth channel in seconds/100 - e.g. 3 -> each channel is scanned for 30 milliseconds [default] + 0 ... 255 duration for scanning a bluetooth advertising channel in seconds/100 + e.g. 8 -> each channel is scanned for 80 milliseconds [default] 0x0D (NOT YET IMPLEMENTED) set BLE and WIFI vendorfilter mode diff --git a/src/paxcounter.conf b/src/paxcounter.conf index 8412d90f..bc709486 100644 --- a/src/paxcounter.conf +++ b/src/paxcounter.conf @@ -12,8 +12,8 @@ // BLE scan parameters #define BLESTACKSIZE 8192 // stack size for esp_bt_controller #define BLESCANTIME 0 // [seconds] scan duration, 0 means infinite [default], see note below -#define BLESCANWINDOW 0x50 // [milliseconds] scan window, see below, 3 .. 10240, default 80ms -#define BLESCANINTERVAL 0x50 // [milliseconds] scan interval, see below, 3 .. 10240, default 80ms = 100% duty cycle +#define BLESCANWINDOW 80 // [milliseconds] scan window, see below, 3 .. 10240, default 80ms +#define BLESCANINTERVAL 80 // [illiseconds] scan interval, see below, 3 .. 10240, default 80ms = 100% duty cycle /* Note: guide for setting bluetooth parameters * From 776795d75b7c6b2f6af2719797efe143886442e9 Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Sun, 20 May 2018 21:48:21 +0200 Subject: [PATCH 26/38] lorawan.cpp bugfix BLE payload --- src/lorawan.cpp | 53 ++++++++++++++++++++++++++----------------------- 1 file changed, 28 insertions(+), 25 deletions(-) diff --git a/src/lorawan.cpp b/src/lorawan.cpp index b2269571..90052ba8 100644 --- a/src/lorawan.cpp +++ b/src/lorawan.cpp @@ -108,36 +108,39 @@ void printKeys(void) { #endif // VERBOSE void do_send(osjob_t* j){ - uint8_t mydata[4]; - // Sum of unique WIFI MACs seen - mydata[0] = (macs_wifi & 0xff00) >> 8; - mydata[1] = macs_wifi & 0xff; - - #ifdef BLECOUNTER - // Sum of unique BLE MACs seen - mydata[2] = (macs_ble & 0xff00) >> 8; - mydata[3] = macs_ble & 0xff; - #else - mydata[2] = 0; - mydata[3] = 0; - #endif - - // Check if there is not a current TX/RX job running + // Check if there is a pending TX/RX job running if (LMIC.opmode & OP_TXRXPEND) { ESP_LOGI(TAG, "OP_TXRXPEND, not sending"); sprintf(display_lmic, "LORA BUSY"); + return; + } + + uint8_t mydata[4]; + + // prepare payload with sum of unique WIFI MACs seen + mydata[0] = (macs_wifi & 0xff00) >> 8; + mydata[1] = macs_wifi & 0xff; + + if (cfg.blescan) { + // append sum of unique BLE MACs seen to payload + mydata[2] = (macs_ble & 0xff00) >> 8; + mydata[3] = macs_ble & 0xff; } else { - // Prepare upstream data transmission at the next possible time. - LMIC_setTxData2(1, mydata, sizeof(mydata), (cfg.countermode & 0x02)); - ESP_LOGI(TAG, "Packet queued"); - sprintf(display_lmic, "PACKET QUEUED"); - // clear counter if not in cumulative counter mode - if (cfg.countermode != 1) { - reset_counters(); // clear macs container and reset all counters - reset_salt(); // get new salt for salting hashes - ESP_LOGI(TAG, "Counter cleared (countermode = %d)", cfg.countermode); - } + mydata[2] = 0; + mydata[3] = 0; + } + + // Prepare upstream data transmission at the next possible time. + LMIC_setTxData2(1, mydata, sizeof(mydata), (cfg.countermode & 0x02)); + ESP_LOGI(TAG, "Packet queued"); + sprintf(display_lmic, "PACKET QUEUED"); + + // clear counter if not in cumulative counter mode + if (cfg.countermode != 1) { + reset_counters(); // clear macs container and reset all counters + reset_salt(); // get new salt for salting hashes + ESP_LOGI(TAG, "Counter cleared (countermode = %d)", cfg.countermode); } // Schedule next transmission From ff024d7abc7d78ccee3c8c7fbecc70f1f9864cf9 Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Sun, 20 May 2018 21:57:03 +0200 Subject: [PATCH 27/38] lorawan.cpp bugfix "LORA BUSY" --- src/lorawan.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/lorawan.cpp b/src/lorawan.cpp index 90052ba8..80685254 100644 --- a/src/lorawan.cpp +++ b/src/lorawan.cpp @@ -113,7 +113,7 @@ void do_send(osjob_t* j){ if (LMIC.opmode & OP_TXRXPEND) { ESP_LOGI(TAG, "OP_TXRXPEND, not sending"); sprintf(display_lmic, "LORA BUSY"); - return; + goto end; } uint8_t mydata[4]; @@ -144,6 +144,7 @@ void do_send(osjob_t* j){ } // Schedule next transmission + end: os_setTimedCallback(&sendjob, os_getTime()+sec2osticks(cfg.sendcycle * 2), do_send); } // do_send() From 0777f53b938a625972bff36657411467543c2c2b Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Sun, 20 May 2018 22:30:13 +0200 Subject: [PATCH 28/38] readme.md LED description updated --- README.md | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 98d8f2f1..5b79c0cc 100644 --- a/README.md +++ b/README.md @@ -81,6 +81,23 @@ Note: If you use this software you do this at your own risk. That means that you Paxcounter generates identifiers for sniffed MAC adresses and collects them temporary in the device's RAM for a configurable scan cycle time (default 240 seconds). After each scan cycle the collected identifiers are cleared. Identifiers are generated by salting and hashing MAC adresses. The random salt value changes after each scan cycle. Identifiers and MAC adresses are never transferred to the LoRaWAN network. No persistent storing of MAC adresses, identifiers or timestamps and no other kind of analytics than counting are implemented in this code. Wireless networks are not touched by this code, but MAC adresses from wireless devices as well within as not within wireless networks, regardless if encrypted or unencrypted, are sniffed and processed by this code. If the bluetooth option in the code is enabled, bluetooth MACs are scanned and processed by the included BLE stack, then hashed and counted by this code. +# LED + +Legend for mono color on board LED: + +- Single Flash (50ms): seen a new Wifi or BLE device +- Quick blink (20ms on each 1/5 second): joining LoRaWAN network in progress or pending +- Small blink (10ms on each 1/2 second): LoRaWAN data transmit in progress or pending +- Long blink (200ms on each 2 seconds): LoRaWAN stack error + +Legend for RGB LED (LoPy/LoPy4/FiPy/Lolin32 only): + +- Green each blink: seen a new Wifi device +- Magenta each blink: seen a new BLE device +- Yellow quick blink: joining LoRaWAN network in progress or pending +- Blue blink: LoRaWAN data transmit in progress or pending +- Red long blink: LoRaWAN stack error + # Payload format description FPort1: @@ -211,15 +228,6 @@ device answers with it's current configuration. The configuration is a C structu bytes 1-3: chip temperature in celsius (little endian format) -# RGB Led color description - -Description of the RGB LED color (LoPy/LoPy4/FiPy and Lolin32 only): - -- Yellow quick blink: joining LoRaWAN network in progress or pending -- Blue blink: LoRaWAN data transmit (including waiting for receive windows) in progress or pending -- Green each blink: seen a new Wifi device -- Magenta each blink: seen a new BLE device - # License Copyright 2018 Oliver Brandmueller From 61bd56860f3a03acec593679c2ba439fa28303a3 Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Mon, 21 May 2018 14:16:25 +0200 Subject: [PATCH 29/38] minor fixes --- src/lorawan.cpp | 8 +++++--- src/main.cpp | 38 +++++++++++++++++++------------------- 2 files changed, 24 insertions(+), 22 deletions(-) diff --git a/src/lorawan.cpp b/src/lorawan.cpp index 80685254..38777bfb 100644 --- a/src/lorawan.cpp +++ b/src/lorawan.cpp @@ -151,7 +151,7 @@ void do_send(osjob_t* j){ void onEvent (ev_t ev) { char buff[24]=""; - + switch(ev) { case EV_SCAN_TIMEOUT: strcpy_P(buff, PSTR("SCAN TIMEOUT")); break; case EV_BEACON_FOUND: strcpy_P(buff, PSTR("BEACON FOUND")); break; @@ -171,10 +171,12 @@ void onEvent (ev_t ev) { joinstate=true; strcpy_P(buff, PSTR("JOINED")); + sprintf(display_lora, ""); // clear previous lmic status message from display // Disable link check validation (automatically enabled // during join, but not supported by TTN at this time). - LMIC_setLinkCheckMode(0); + // LMIC_setLinkCheckMode(0); -> do we need this? + // set data rate adaptation LMIC_setAdrMode(cfg.adrmode); // Set data rate and transmit power (note: txpower seems to be ignored by the library) @@ -187,7 +189,7 @@ void onEvent (ev_t ev) { case EV_TXCOMPLETE: strcpy_P(buff, (LMIC.txrxFlags & TXRX_ACK) ? PSTR("RECEIVED ACK") : PSTR("TX COMPLETE")); - sprintf(display_lora, ""); // erase previous LoRa message from display + sprintf(display_lora, ""); // clear previous lmic status message from display if (LMIC.dataLen) { ESP_LOGI(TAG, "Received %d bytes of payload, RSSI %d SNR %d", LMIC.dataLen, LMIC.rssi, (signed char)LMIC.snr / 4); diff --git a/src/main.cpp b/src/main.cpp index 7c42b7f0..282a955c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -134,8 +134,9 @@ static void lora_init (osjob_t* j) { LMIC_reset(); // This tells LMIC to make the receive windows bigger, in case your clock is 1% faster or slower. LMIC_setClockError(MAX_CLOCK_ERROR * 1 / 100); - // start joining - LMIC_startJoining(); + // start joining -> will happen automatically after first do_send job + // LMIC_startJoining(); + // lmic init done - onEvent() callback will be invoked when events occur } // LMIC FreeRTos Task @@ -552,18 +553,19 @@ void setup() { sprintf(display_lora, "Join wait"); - // setup Display IRQ, thanks to https://techtutorialsx.com/2017/10/07/esp32-arduino-timer-interrupts/ + // setup display refresh trigger IRQ using esp32 hardware timer 0 + // for explanation see https://techtutorialsx.com/2017/10/07/esp32-arduino-timer-interrupts/ displaytimer = timerBegin(0, 80, true); // prescaler 80 -> divides 80 MHz CPU freq to 1 MHz, timer 0, count up timerAttachInterrupt(displaytimer, &DisplayIRQ, true); // interrupt handler DisplayIRQ, triggered by edge timerAlarmWrite(displaytimer, DISPLAYREFRESH_MS * 1000, true); // reload interrupt after each trigger of display refresh cycle timerAlarmEnable(displaytimer); // enable display interrupt #endif -// setup channel rotation IRQ, thanks to https://techtutorialsx.com/2017/10/07/esp32-arduino-timer-interrupts/ -channelSwitch = timerBegin(1, 80, true); // prescaler 80 -> divides 80 MHz CPU freq to 1 MHz, timer 1, count up -timerAttachInterrupt(channelSwitch, &ChannelSwitchIRQ, true); // interrupt handler, triggered by edge -timerAlarmWrite(channelSwitch, cfg.wifichancycle * 10000, true); // reload interrupt after each trigger of channel switch cycle -timerAlarmEnable(channelSwitch); // enable channel switching interrupt +// setup channel rotation trigger IRQ using esp32 hardware timer 1 +channelSwitch = timerBegin(1, 80, true); +timerAttachInterrupt(channelSwitch, &ChannelSwitchIRQ, true); +timerAlarmWrite(channelSwitch, cfg.wifichancycle * 10000, true); +timerAlarmEnable(channelSwitch); // show compiled features ESP_LOGI(TAG, "Features %s", features); @@ -573,21 +575,19 @@ ESP_LOGI(TAG, "Features %s", features); printKeys(); #endif -os_init(); // setup LMIC -LMIC_reset(); // Reset the MAC state. Session and pending data transfers will be discarded. -os_setCallback(&initjob, lora_init); // setup initial job & join network +os_init(); // initialize lmic run-time environment +os_setCallback(&initjob, lora_init); // setup initial job & join LoRaWAN network -wifi_sniffer_init(); // setup wifi in monitor mode and start MAC counting - -// initialize salt value using esp_random() called by random() in arduino-esp32 core -// note: do this *after* wifi has started, since gets it's seed from RF noise -reset_salt(); // get new 16bit for salting hashes - -// run wifi channel switching task on core 0 and lora lmic task on core 1 (arduino main loop runs on core 1) +// start lmic runloop in rtos task on core 1 (arduino main loop runs on core 1) ESP_LOGI(TAG, "Starting Lora task on core 1"); xTaskCreatePinnedToCore(lorawan_loop, "loratask", 2048, ( void * ) 1, ( 5 | portPRIVILEGE_BIT ), NULL, 1); +// start wifi in monitor mode and start channel rotation task on core 0 ESP_LOGI(TAG, "Starting Wifi task on core 0"); +wifi_sniffer_init(); +// initialize salt value using esp_random() called by random() in arduino-esp32 core +// note: do this *after* wifi has started, since function gets it's seed from RF noise +reset_salt(); // get new 16bit for salting hashes xTaskCreatePinnedToCore(sniffer_loop, "wifisniffer", 2048, ( void * ) 1, 1, NULL, 0); // start BLE scan callback if BLE function is enabled in NVRAM configuration @@ -597,7 +597,7 @@ xTaskCreatePinnedToCore(sniffer_loop, "wifisniffer", 2048, ( void * ) 1, 1, NULL } #endif -// Finally: kickoff first sendjob and join, then send initial payload "0000" +// kickoff first sendjob -> joins network and transmits initial payload "0000" uint8_t mydata[] = "0000"; do_send(&sendjob); } From 7b8367fa4a384c8621eec89fe6d6fe7c90b85316 Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Mon, 21 May 2018 17:48:43 +0200 Subject: [PATCH 30/38] reworked rtos tasking & minor core sanitizations --- platformio.ini | 4 +- src/globals.h | 8 +--- src/lorawan.cpp | 9 ++--- src/main.cpp | 100 ++++++++++++++++++++++-------------------------- 4 files changed, 53 insertions(+), 68 deletions(-) diff --git a/platformio.ini b/platformio.ini index 5f08fca6..fc426838 100644 --- a/platformio.ini +++ b/platformio.ini @@ -33,8 +33,8 @@ build_flags = ; ---> 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_NONE + -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_INFO ; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_VERBOSE ; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_DEBUG ; diff --git a/src/globals.h b/src/globals.h index 2578596d..275f1c3b 100644 --- a/src/globals.h +++ b/src/globals.h @@ -44,16 +44,10 @@ typedef struct { } configData_t; 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 uint16_t macs_total, macs_wifi, macs_ble; // MAC counters -extern bool joinstate; extern std::set macs; -extern hw_timer_t * channelSwitch; // hardware timer used for wifi channel switching - -#ifdef HAS_DISPLAY - extern HAS_DISPLAY u8x8; -#endif +extern hw_timer_t * channelSwitch; // hardware timer used for wifi channel switching \ No newline at end of file diff --git a/src/lorawan.cpp b/src/lorawan.cpp index 38777bfb..4cde6d3f 100644 --- a/src/lorawan.cpp +++ b/src/lorawan.cpp @@ -116,9 +116,9 @@ void do_send(osjob_t* j){ goto end; } - uint8_t mydata[4]; - // prepare payload with sum of unique WIFI MACs seen + static uint8_t mydata[4]; + mydata[0] = (macs_wifi & 0xff00) >> 8; mydata[1] = macs_wifi & 0xff; @@ -169,13 +169,12 @@ void onEvent (ev_t ev) { case EV_JOINED: - joinstate=true; strcpy_P(buff, PSTR("JOINED")); sprintf(display_lora, ""); // clear previous lmic status message from display // Disable link check validation (automatically enabled - // during join, but not supported by TTN at this time). - // LMIC_setLinkCheckMode(0); -> do we need this? + // during join, but not supported by TTN at this time). -> do we need this? + LMIC_setLinkCheckMode(0); // set data rate adaptation LMIC_setAdrMode(cfg.adrmode); diff --git a/src/main.cpp b/src/main.cpp index 282a955c..75cfa8d5 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -39,7 +39,7 @@ Refer to LICENSE.txt file in repository for more details. // Initialize global variables configData_t cfg; // struct holds current device configuration -osjob_t sendjob, initjob; // LMIC jobs +osjob_t sendjob; // LMIC job handler uint64_t uptimecounter = 0; // timer global for uptime counter uint8_t DisplayState = 0; // globals for state machine uint16_t macs_total = 0, macs_wifi = 0, macs_ble = 0; // MAC counters globals for display @@ -50,8 +50,6 @@ led_states previousLEDState = LED_ON; // This will force LED to be off at boo unsigned long LEDBlinkStarted = 0; // When (in millis() led blink started) uint16_t LEDBlinkDuration = 0; // How long the blink need to be uint16_t LEDColor = COLOR_NONE; // state machine variable to set RGB LED color -bool joinstate = false; // LoRa network joined? global flag -bool blinkdone = true; // flag for state machine for blinking LED once hw_timer_t * displaytimer = NULL; // configure hardware timer used for cyclic display refresh hw_timer_t * channelSwitch = NULL; // configure hardware timer used for wifi channel switching @@ -128,34 +126,20 @@ const lmic_pinmap lmic_pins = { .dio = {DIO0, DIO1, DIO2} }; -// LoRaWAN Initjob -static void lora_init (osjob_t* j) { - // reset MAC state - LMIC_reset(); - // This tells LMIC to make the receive windows bigger, in case your clock is 1% faster or slower. - LMIC_setClockError(MAX_CLOCK_ERROR * 1 / 100); - // start joining -> will happen automatically after first do_send job - // LMIC_startJoining(); - // lmic init done - onEvent() callback will be invoked when events occur -} // LMIC FreeRTos Task void lorawan_loop(void * pvParameters) { configASSERT( ( ( uint32_t ) pvParameters ) == 1 ); // FreeRTOS check - static uint16_t lorawait = 0; + //static uint16_t lorawait = 0; while(1) { // execute LMIC jobs os_runloop_once(); - // indicate LMIC state on LEDs if present - #if (HAS_LED != NOT_A_PIN) || defined (HAS_RGB_LED) - led_loop(); - #endif -/* + /* // check if payload is sent while(LMIC.opmode & OP_TXRXPEND) { if(!lorawait) @@ -169,13 +153,14 @@ void lorawan_loop(void * pvParameters) { }; vTaskDelay(1000/portTICK_PERIOD_MS); } -*/ + */ + vTaskDelay(10/portTICK_PERIOD_MS); // reset watchdog } } -/* end LMIC specific parts --------------------------------------------------------------- */ +/* end LMIC specific parts --------------------------------------------------------------- */ /* beginn hardware specific parts -------------------------------------------------------- */ @@ -384,6 +369,7 @@ uint64_t uptime() { #endif #if (HAS_LED != NOT_A_PIN) || defined (HAS_RGB_LED) + void blink_LED(uint16_t set_color, uint16_t set_blinkduration) { LEDColor = set_color; // set color for RGB LED LEDBlinkDuration = set_blinkduration; // duration @@ -457,7 +443,6 @@ uint64_t uptime() { #endif - /* begin Aruino SETUP ------------------------------------------------------------ */ void setup() { @@ -575,10 +560,16 @@ ESP_LOGI(TAG, "Features %s", features); printKeys(); #endif -os_init(); // initialize lmic run-time environment -os_setCallback(&initjob, lora_init); // setup initial job & join LoRaWAN network +// initialize LoRaWAN LMIC run-time environment +os_init(); +// reset LMIC MAC state +LMIC_reset(); +// This tells LMIC to make the receive windows bigger, in case your clock is 1% faster or slower. +LMIC_setClockError(MAX_CLOCK_ERROR * 1 / 100); + +// start lmic runloop in rtos task on core 1 (note: arduino main loop runs on core 1, too) +// https://techtutorialsx.com/2017/05/09/esp32-get-task-execution-core/ -// start lmic runloop in rtos task on core 1 (arduino main loop runs on core 1) ESP_LOGI(TAG, "Starting Lora task on core 1"); xTaskCreatePinnedToCore(lorawan_loop, "loratask", 2048, ( void * ) 1, ( 5 | portPRIVILEGE_BIT ), NULL, 1); @@ -597,46 +588,47 @@ xTaskCreatePinnedToCore(sniffer_loop, "wifisniffer", 2048, ( void * ) 1, 1, NULL } #endif -// kickoff first sendjob -> joins network and transmits initial payload "0000" -uint8_t mydata[] = "0000"; +// kickoff sendjob -> joins network and rescedules sendjob for cyclic transmitting payload do_send(&sendjob); + } -/* end Aruino SETUP ------------------------------------------------------------ */ +/* end Arduino SETUP ------------------------------------------------------------ */ +/* begin Arduino main loop ------------------------------------------------------ */ -/* begin Aruino LOOP ------------------------------------------------------------ */ - -// Arduino main moop, runs on core 1 -// https://techtutorialsx.com/2017/05/09/esp32-get-task-execution-core/ void loop() { - // simple state machine for controlling display, LED, button, etc. - uptimecounter = uptime() / 1000; // counts uptime in seconds (64bit) + while (1) { - #if (HAS_LED != NOT_A_PIN) || defined (HAS_RGB_LED) - led_loop(); - #endif + // simple state machine for controlling uptime, display, LED, button, memory. + + uptimecounter = uptime() / 1000; // counts uptime in seconds (64bit) + + #if (HAS_LED != NOT_A_PIN) || defined (HAS_RGB_LED) + led_loop(); + #endif - #ifdef HAS_BUTTON - readButton(); - #endif + #ifdef HAS_BUTTON + readButton(); + #endif - #ifdef HAS_DISPLAY - updateDisplay(); - #endif + #ifdef HAS_DISPLAY + updateDisplay(); + #endif - // check free memory - if (esp_get_minimum_free_heap_size() <= MEM_LOW) { - ESP_LOGI(TAG, "Memory full, counter cleared (heap low water mark = %d Bytes / free heap = %d bytes)", \ - esp_get_minimum_free_heap_size(), ESP.getFreeHeap()); - do_send(&sendjob); // send count - reset_counters(); // clear macs container and reset all counters - reset_salt(); // get new salt for salting hashes - } + // check free memory + if (esp_get_minimum_free_heap_size() <= MEM_LOW) { + ESP_LOGI(TAG, "Memory full, counter cleared (heap low water mark = %d Bytes / free heap = %d bytes)", \ + esp_get_minimum_free_heap_size(), ESP.getFreeHeap()); + do_send(&sendjob); // send count + reset_counters(); // clear macs container and reset all counters + reset_salt(); // get new salt for salting hashes + } - vTaskDelay(10/portTICK_PERIOD_MS); // reset watchdog + vTaskDelay(10/portTICK_PERIOD_MS); // reset watchdog - } + } // end of infinite main loop +} -/* end Aruino LOOP ------------------------------------------------------------ */ +/* end Arduino main loop ------------------------------------------------------------ */ From 92cc55a36a323fd6a88ae34163f423fb5b8c23e0 Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Mon, 21 May 2018 20:35:33 +0200 Subject: [PATCH 31/38] ADR display --- README.md | 3 ++- src/main.cpp | 9 +++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 5b79c0cc..e842faa9 100644 --- a/README.md +++ b/README.md @@ -153,7 +153,8 @@ Note: all settings are stored in NVRAM and will be reloaded when device starts. 0 = ADR off 1 = ADR on [default] - note: set ADR to off, if device is moving, set to on, if not. + Note: set ADR to off, if device is moving, set to on, if not. + If ADR is set to on, SF value is shown inverted on display. 0x08 do nothing diff --git a/src/main.cpp b/src/main.cpp index 75cfa8d5..a33e5787 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -318,8 +318,13 @@ uint64_t uptime() { // update LoRa SF display (line 3) u8x8.setCursor(11,3); - u8x8.printf("SF:%c%c", lora_datarate[LMIC.datarate * 2], lora_datarate[LMIC.datarate * 2 + 1]); - + u8x8.printf("SF:"); + if (cfg.adrmode) // if ADR=on then display SF value inverse + u8x8.setInverseFont(1); + u8x8.printf("%c%c", lora_datarate[LMIC.datarate * 2], lora_datarate[LMIC.datarate * 2 + 1]); + if (cfg.adrmode) // switch off inverse if it was turned on + u8x8.setInverseFont(0); + // update wifi channel display (line 4) u8x8.setCursor(11,4); u8x8.printf("ch:%02d", channel); From f878b929a6ce87ef02765c5198bc0b4d18bb794b Mon Sep 17 00:00:00 2001 From: Verkehrsrot Date: Mon, 21 May 2018 21:02:13 +0200 Subject: [PATCH 32/38] Update README.md --- README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/README.md b/README.md index e842faa9..5d31b7bf 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,6 @@ # 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 From 5fb1a9d51ccd5cece84bf1402a4a41452fe0fcba Mon Sep 17 00:00:00 2001 From: Verkehrsrot Date: Thu, 24 May 2018 09:58:27 +0200 Subject: [PATCH 33/38] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5d31b7bf..663a7ee4 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ Currently supported IoT boards: - Heltec LoRa-32 {1} - TTGOv1 {1} - TTGOv2 {1}{4} -- TTGOv2.1 (not yet tested) {1} +- TTGOv2.1 {1} - Pycom LoPy {2} - Pycom LoPy4 {2} - Pycom FiPy {2} From 98739b5c829eb7bc4d15ae7a81d2087a8c41199c Mon Sep 17 00:00:00 2001 From: Verkehrsrot Date: Thu, 24 May 2018 10:43:53 +0200 Subject: [PATCH 34/38] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 663a7ee4..f64ce5ee 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # ESP32-Paxcounter -**Wifi & Bluetooth driven, LoRaWAN enabled, battery powered mini Paxcounter built on cheap ESP32 boards** +**Wifi & Bluetooth driven, LoRaWAN enabled, battery powered mini Paxcounter built on cheap ESP32 LoRa IoT boards** @@ -17,7 +17,7 @@ This can all be done with a single small and cheap ESP32 board for less than $20 # Hardware -Currently supported IoT boards: +Supported ESP32 based LoRa IoT boards: - Heltec LoRa-32 {1} - TTGOv1 {1} - TTGOv2 {1}{4} From be883d577e9e3b503277a6b32c2a234650c36322 Mon Sep 17 00:00:00 2001 From: cyberman54 Date: Sun, 27 May 2018 16:52:13 +0200 Subject: [PATCH 35/38] v1.3.6 release --- src/main.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.h b/src/main.h index 71220c44..7db20f2b 100644 --- a/src/main.h +++ b/src/main.h @@ -1,6 +1,6 @@ // program version - note: increment version after modifications to configData_t struct!! -#define PROGVERSION "1.3.51" // use max 10 chars here! +#define PROGVERSION "1.3.6" // use max 10 chars here! #define PROGNAME "PAXCNT" //--- Declarations --- From b9e3961609f8b24397ae90e40058d9ef247a0ce7 Mon Sep 17 00:00:00 2001 From: cyberman54 Date: Sun, 27 May 2018 17:42:18 +0200 Subject: [PATCH 36/38] code sanitizations --- src/antenna.cpp | 2 +- src/blecsan.cpp | 7 +++---- src/configmanager.cpp | 2 +- src/lorawan.cpp | 8 +++----- src/macsniff.cpp | 4 +--- src/main.cpp | 8 ++------ src/rcommand.cpp | 2 +- 7 files changed, 12 insertions(+), 21 deletions(-) diff --git a/src/antenna.cpp b/src/antenna.cpp index bcbf1703..6c083275 100644 --- a/src/antenna.cpp +++ b/src/antenna.cpp @@ -5,7 +5,7 @@ #include // Local logging tag -static const char *TAG = "antenna"; +static const char* TAG = "wifi"; typedef enum { ANTENNA_INT = 0, diff --git a/src/blecsan.cpp b/src/blecsan.cpp index 3610def6..18df2135 100644 --- a/src/blecsan.cpp +++ b/src/blecsan.cpp @@ -17,7 +17,7 @@ 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 = "blescan"; +static const char* TAG = "bluetooth"; // defined in macsniff.cpp bool mac_add(uint8_t *paddr, int8_t rssi, bool sniff_type); @@ -92,9 +92,8 @@ static const char *btsig_gap_type(uint32_t gap_type) { IRAM_ATTR 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 rcvd -> 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) { diff --git a/src/configmanager.cpp b/src/configmanager.cpp index 808af4b6..5f00752e 100644 --- a/src/configmanager.cpp +++ b/src/configmanager.cpp @@ -5,7 +5,7 @@ #include // Local logging tag -static const char *TAG = "configmanager"; +static const char* TAG = "flash"; nvs_handle my_handle; diff --git a/src/lorawan.cpp b/src/lorawan.cpp index 4cde6d3f..87a5c58f 100644 --- a/src/lorawan.cpp +++ b/src/lorawan.cpp @@ -11,7 +11,7 @@ #endif // Local logging Tag -static const char *TAG = "lorawan"; +static const char* TAG = "lora"; // functions defined in rcommand.cpp void rcommand(uint8_t cmd, uint8_t arg); @@ -79,8 +79,6 @@ void get_hard_deveui(uint8_t *pdeveui) { // Display a key void printKey(const char * name, const uint8_t * key, uint8_t len, bool lsb) { - uint8_t start=lsb?len:0; - uint8_t end = lsb?0:len; const uint8_t * p ; char keystring[len+1] = "", keybyte[3]; for (uint8_t i=0; i do we need this? @@ -188,7 +186,7 @@ void onEvent (ev_t ev) { case EV_TXCOMPLETE: strcpy_P(buff, (LMIC.txrxFlags & TXRX_ACK) ? PSTR("RECEIVED ACK") : PSTR("TX COMPLETE")); - sprintf(display_lora, ""); // clear previous lmic status message from display + sprintf(display_lora, " "); // clear previous lmic status message from display if (LMIC.dataLen) { ESP_LOGI(TAG, "Received %d bytes of payload, RSSI %d SNR %d", LMIC.dataLen, LMIC.rssi, (signed char)LMIC.snr / 4); diff --git a/src/macsniff.cpp b/src/macsniff.cpp index a3712b1a..0f566349 100644 --- a/src/macsniff.cpp +++ b/src/macsniff.cpp @@ -3,13 +3,11 @@ #include "globals.h" #ifdef VENDORFILTER - #include - #include #include "vendor_array.h" #endif // Local logging tag -static const char *TAG = "macsniff"; +static const char* TAG = "wifi"; static wifi_country_t wifi_country = {.cc=WIFI_MY_COUNTRY, .schan=WIFI_CHANNEL_MIN, .nchan=WIFI_CHANNEL_MAX, .policy=WIFI_COUNTRY_POLICY_MANUAL}; diff --git a/src/main.cpp b/src/main.cpp index a33e5787..2b1b3e67 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -61,9 +61,7 @@ std::set macs; // associative container holds total of unique MAC adre static volatile int ButtonPressed = 0, DisplayTimerIRQ = 0, ChannelTimerIRQ = 0; // local Tag for logging -static const char *TAG = "paxcnt"; -// Note: Log level control seems not working during runtime, -// so we need to switch loglevel by compiler build option in platformio.ini +static const char* TAG = "main"; #ifndef VERBOSE int redirect_log(const char * fmt, va_list args) { @@ -241,8 +239,6 @@ uint64_t uptime() { // Print a key on display void DisplayKey(const uint8_t * key, uint8_t len, bool lsb) { - uint8_t start=lsb?len:0; - uint8_t end = lsb?0:len; const uint8_t * p ; for (uint8_t i=0; i // Local logging tag -static const char *TAG = "rcommand"; +static const char* TAG = "main"; // table of remote commands and assigned functions typedef struct { From 1aa0aef6699dad82bf66f8812721894cd84ae2be Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Sun, 27 May 2018 17:45:07 +0200 Subject: [PATCH 37/38] ttgpv21.h --- src/hal/ttgov21.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/hal/ttgov21.h b/src/hal/ttgov21.h index 8bf61742..bbd27002 100644 --- a/src/hal/ttgov21.h +++ b/src/hal/ttgov21.h @@ -1,11 +1,10 @@ // Hardware related definitions for TTGO V2.1 Board -// NOT YET TESTED #define CFG_sx1276_radio 1 // HPD13A LoRa SoC #define HAS_DISPLAY U8X8_SSD1306_128X64_NONAME_HW_I2C #define DISPLAY_FLIP 1 // rotated display -#define HAS_LED 23 // green on board LED_G3 +#define HAS_LED 23 // green on board LED_G3 (not in initial board version) // disable brownout detection (needed on TTGOv2 for battery powered operation) #define DISABLE_BROWNOUT 1 // comment out if you want to keep brownout feature From 1c312bd04535aa1358ec9ac8035c8b4f5fe9f950 Mon Sep 17 00:00:00 2001 From: cyberman54 Date: Thu, 31 May 2018 00:35:02 +0200 Subject: [PATCH 38/38] platform.ini: enforcing espressif32 v0.12.0, otherwise .elf too large --- platformio.ini | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/platformio.ini b/platformio.ini index fc426838..a2a3ab93 100644 --- a/platformio.ini +++ b/platformio.ini @@ -43,7 +43,7 @@ build_flags = -include "src/paxcounter.conf" [env:heltec] -platform = espressif32 +platform = espressif32@0.12.0 framework = arduino board = heltec_wifi_lora_32 monitor_speed = 115200 @@ -54,7 +54,7 @@ build_flags = -include "src/hal/heltec.h" [env:ttgov1] -platform = espressif32 +platform = espressif32@0.12.0 framework = arduino board = esp32dev monitor_speed = 115200 @@ -66,7 +66,7 @@ build_flags = -include "src/hal/ttgov1.h" [env:ttgov2] -platform = espressif32 +platform = espressif32@0.12.0 framework = arduino board = esp32dev monitor_speed = 115200 @@ -78,7 +78,7 @@ build_flags = -include "src/hal/ttgov2.h" [env:ttgov21] -platform = espressif32 +platform = espressif32@0.12.0 framework = arduino board = esp32dev monitor_speed = 115200 @@ -90,7 +90,7 @@ build_flags = -include "src/hal/ttgov21.h" [env:fipy] -platform = espressif32 +platform = espressif32@0.12.0 framework = arduino board = esp32dev monitor_speed = 115200 @@ -102,7 +102,7 @@ build_flags = -include "src/hal/fipy.h" [env:lopy] -platform = espressif32 +platform = espressif32@0.12.0 framework = arduino board = esp32dev monitor_speed = 115200 @@ -114,7 +114,7 @@ build_flags = -include "src/hal/lopy.h" [env:lopy4] -platform = espressif32 +platform = espressif32@0.12.0 framework = arduino board = esp32dev monitor_speed = 115200 @@ -126,7 +126,7 @@ build_flags = -include "src/hal/lopy4.h" [env:lolin32lite] -platform = espressif32 +platform = espressif32@0.12.0 framework = arduino board = lolin32 monitor_speed = 115200 @@ -138,7 +138,7 @@ build_flags = -include "src/hal/lolin32lite_lora.h" [env:lolin32] -platform = espressif32 +platform = espressif32@0.12.0 framework = arduino board = lolin32 monitor_speed = 115200