From 130fefd49d617c61421ea55d5bf5e2bb1bc5ec80 Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Sun, 15 Apr 2018 22:21:30 +0200 Subject: [PATCH] centralize display writes (part 1) --- platformio.ini | 4 ++-- src/macsniff.cpp | 14 +++++++------- src/main.cpp | 49 +++++++++++++++++++++++++++++++----------------- src/main.h | 3 +++ 4 files changed, 44 insertions(+), 26 deletions(-) diff --git a/platformio.ini b/platformio.ini index 8f4d829a..f37e652b 100644 --- a/platformio.ini +++ b/platformio.ini @@ -10,9 +10,9 @@ ; ---> SELECT TARGET PLATFORM HERE! <--- [platformio] -env_default = heltec_wifi_lora_32 +;nv_default = heltec_wifi_lora_32 ;env_default = ttgov1 -;env_default = ttgov2 +env_default = ttgov2 ;env_default = lopy ;env_default = lopy4 ;env_default = lolin32lite_lora diff --git a/src/macsniff.cpp b/src/macsniff.cpp index 15684615..a377d01b 100644 --- a/src/macsniff.cpp +++ b/src/macsniff.cpp @@ -50,22 +50,22 @@ bool mac_add(uint8_t *paddr, int8_t rssi, bool sniff_type) { // Insert only if it was not found on global count if (added) { - char buff[16]; - snprintf(buff, sizeof(buff), "PAX:%-4d", (int) macs.size()); // convert 16-bit MAC counter to decimal counter value - u8x8.draw2x2String(0, 0, buff); // display number on unique macs total Wifi + BLE + //char buff[16]; + //snprintf(buff, sizeof(buff), "PAX:%-4d", (int) macs.size()); // convert 16-bit MAC counter to decimal counter value + //u8x8.draw2x2String(0, 0, buff); // display number on unique macs total Wifi + BLE if (sniff_type == MAC_SNIFF_WIFI ) { rgb_set_color(COLOR_GREEN); wifis.insert(hashedmac); // add hashed MAC to wifi container - u8x8.setCursor(0,4); - u8x8.printf("WIFI: %-4d", (int) wifis.size()); + //u8x8.setCursor(0,4); + //u8x8.printf("WIFI: %-4d", (int) wifis.size()); } #ifdef BLECOUNTER else if (sniff_type == MAC_SNIFF_BLE ) { rgb_set_color(COLOR_MAGENTA); bles.insert(hashedmac); // add hashed MAC to BLE container - u8x8.setCursor(0,3); - u8x8.printf("BLTH: %-4d", (int) bles.size()); + //u8x8.setCursor(0,3); + //u8x8.printf("BLTH: %-4d", (int) bles.size()); } #endif diff --git a/src/main.cpp b/src/main.cpp index ad92f973..73ebc35f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -45,6 +45,7 @@ configData_t cfg; // struct holds current device configuration osjob_t sendjob, initjob; // LMIC // Initialize global variables +uint8_t channel = 0; int macnum = 0; uint64_t uptimecounter = 0; bool joinstate = false; @@ -258,7 +259,7 @@ void bt_loop(void *ignore); void sniffer_loop(void * pvParameters) { configASSERT( ( ( uint32_t ) pvParameters ) == 1 ); // FreeRTOS check - uint8_t channel=0; + channel=0; char buff[16]; int nloop=0, lorawait=0; @@ -271,7 +272,7 @@ void sniffer_loop(void * pvParameters) { channel = (channel % WIFI_CHANNEL_MAX) + 1; // rotates variable channel 1..WIFI_CHANNEL_MAX wifi_sniffer_set_channel(channel); ESP_LOGD(TAG, "Wifi set channel %d", channel); - +/* snprintf(buff, sizeof(buff), "PAX:%d", (int) macs.size()); // convert 16-bit MAC counter to decimal counter value u8x8.draw2x2String(0, 0, buff); // display number on unique macs total @@ -279,7 +280,7 @@ void sniffer_loop(void * pvParameters) { u8x8.printf("ch:%02i", channel); u8x8.setCursor(0,5); u8x8.printf(!cfg.rssilimit ? "RLIM: off" : "RLIM: %-3d", cfg.rssilimit); - +*/ // duration of one wifi scan loop reached? then send data and begin new scan cycle if ( nloop >= ( (100 / cfg.wifichancycle) * (cfg.wifiscancycle * 2)) +1 ) { u8x8.setPowerSave(!cfg.screenon); // set display on if enabled @@ -499,11 +500,11 @@ salt_reset(); // get new 16bit for salting hashes ESP_LOGI(TAG, "Starting Lora task on core 1"); xTaskCreatePinnedToCore(lorawan_loop, "loratask", 2048, ( void * ) 1, ( 5 | portPRIVILEGE_BIT ), NULL, 1); ESP_LOGI(TAG, "Starting Wifi task on core 0"); -xTaskCreatePinnedToCore(sniffer_loop, "wifisniffer", 4096, ( void * ) 1, 1, NULL, 0); +xTaskCreatePinnedToCore(sniffer_loop, "wifisniffer", 16384, ( void * ) 1, 1, NULL, 0); #ifdef BLECOUNTER if (cfg.blescan) { // start BLE task only if BLE function is enabled in NVRAM configuration ESP_LOGI(TAG, "Starting Bluetooth task on core 0"); - xTaskCreatePinnedToCore(bt_loop, "btscan", 8192, NULL, 5, NULL, 0); + xTaskCreatePinnedToCore(bt_loop, "btscan", 16384, NULL, 5, NULL, 0); } #endif @@ -521,20 +522,34 @@ do_send(&sendjob); // https://techtutorialsx.com/2017/05/09/esp32-get-task-execution-core/ void loop() { - while(1) { + #ifdef HAS_BUTTON + if (ButtonTriggered) { + ButtonTriggered = false; + ESP_LOGI(TAG, "Button pressed, resetting device to factory defaults"); + eraseConfig(); + esp_restart(); + } + #endif - #ifdef HAS_BUTTON - if (ButtonTriggered) { - ButtonTriggered = false; - ESP_LOGI(TAG, "Button pressed, resetting device to factory defaults"); - eraseConfig(); - esp_restart(); - } - #endif - - vTaskDelay(500/portTICK_PERIOD_MS); + #ifdef HAS_DISPLAY + // display counters(lines 0-4) + char buff[16]; + snprintf(buff, sizeof(buff), "PAX:%-4d", (int) macs.size()); // convert 16-bit MAC counter to decimal counter value + u8x8.draw2x2String(0, 0, buff); // display number on unique macs total Wifi + BLE + u8x8.setCursor(0,4); + u8x8.printf("WIFI: %-4d", (int) wifis.size()); + u8x8.setCursor(0,3); + u8x8.printf("BLTH: %-4d", (int) bles.size()); + // display actual wifi channel (line 4) + u8x8.setCursor(11,4); + u8x8.printf("ch:%02i", channel); + // display RSSI status (line 5) + u8x8.setCursor(0,5); + u8x8.printf(!cfg.rssilimit ? "RLIM: off" : "RLIM: %-3d", cfg.rssilimit); + #endif + + vTaskDelay(DISPLAYREFRESH/portTICK_PERIOD_MS); uptimecounter = uptime() / 1000; // count uptime seconds - } } diff --git a/src/main.h b/src/main.h index 0aef700d..358096b2 100644 --- a/src/main.h +++ b/src/main.h @@ -46,6 +46,9 @@ // Default RGB LED luminosity (in %) #define RGBLUMINOSITY 30 // 30% +// OLED Display refresh cycle (in Milliseconds) +#define DISPLAYREFRESH 200 // 200ms + // LMIC settings // define hardware independent LMIC settings here, settings of standard library in /lmic/config.h will be ignored // define hardware specifics settings in platformio.ini as build_flag for hardware environment