From 3ca741c6dc6822fc7e057ff281712bebcef110f3 Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Fri, 27 Apr 2018 21:29:46 +0200 Subject: [PATCH] v1.3.3: repair memory display --- platformio.ini | 4 ++-- src/configmanager.cpp | 56 +++++++++++++++++++++---------------------- src/globals.h | 3 +-- src/lorawan.cpp | 2 +- src/macsniff.cpp | 8 ++----- src/main.cpp | 18 +++++++++----- src/main.h | 2 +- src/paxcounter.conf | 4 ++-- src/rcommand.cpp | 18 +++++++------- 9 files changed, 58 insertions(+), 57 deletions(-) diff --git a/platformio.ini b/platformio.ini index 5f249bba..f780a017 100644 --- a/platformio.ini +++ b/platformio.ini @@ -11,9 +11,9 @@ ; ---> SELECT TARGET PLATFORM HERE! <--- [platformio] -;env_default = heltec_wifi_lora_32 +env_default = heltec_wifi_lora_32 ;env_default = ttgov1 -env_default = ttgov2 +;env_default = ttgov2 ;env_default = lopy ;env_default = lopy4 ;env_default = lolin32lite_lora diff --git a/src/configmanager.cpp b/src/configmanager.cpp index fecd37a1..628e4cd3 100644 --- a/src/configmanager.cpp +++ b/src/configmanager.cpp @@ -174,113 +174,113 @@ void loadConfig() { // overwrite defaults with valid values from NVRAM if( nvs_get_i8(my_handle, "lorasf", &flash8) == ESP_OK ) { cfg.lorasf = flash8; - ESP_LOGI(TAG, "lorasf = %i", flash8); + ESP_LOGI(TAG, "lorasf = %d", flash8); } else { - ESP_LOGI(TAG, "lorasf set to default %i", cfg.lorasf); + ESP_LOGI(TAG, "lorasf set to default %d", cfg.lorasf); saveConfig(); } if( nvs_get_i8(my_handle, "txpower", &flash8) == ESP_OK ) { cfg.txpower = flash8; - ESP_LOGI(TAG, "txpower = %i", flash8); + ESP_LOGI(TAG, "txpower = %d", flash8); } else { - ESP_LOGI(TAG, "txpower set to default %i", cfg.txpower); + ESP_LOGI(TAG, "txpower set to default %d", cfg.txpower); saveConfig(); } if( nvs_get_i8(my_handle, "adrmode", &flash8) == ESP_OK ) { cfg.adrmode = flash8; - ESP_LOGI(TAG, "adrmode = %i", flash8); + ESP_LOGI(TAG, "adrmode = %d", flash8); } else { - ESP_LOGI(TAG, "adrmode set to default %i", cfg.adrmode); + ESP_LOGI(TAG, "adrmode set to default %d", cfg.adrmode); saveConfig(); } if( nvs_get_i8(my_handle, "screensaver", &flash8) == ESP_OK ) { cfg.screensaver = flash8; - ESP_LOGI(TAG, "screensaver = %i", flash8); + ESP_LOGI(TAG, "screensaver = %d", flash8); } else { - ESP_LOGI(TAG, "screensaver set to default %i", cfg.screensaver); + ESP_LOGI(TAG, "screensaver set to default %d", cfg.screensaver); saveConfig(); } if( nvs_get_i8(my_handle, "screenon", &flash8) == ESP_OK ) { cfg.screenon = flash8; - ESP_LOGI(TAG, "screenon = %i", flash8); + ESP_LOGI(TAG, "screenon = %d", flash8); } else { - ESP_LOGI(TAG, "screenon set to default %i", cfg.screenon); + ESP_LOGI(TAG, "screenon set to default %d", cfg.screenon); saveConfig(); } if( nvs_get_i8(my_handle, "countermode", &flash8) == ESP_OK ) { cfg.countermode = flash8; - ESP_LOGI(TAG, "countermode = %i", flash8); + ESP_LOGI(TAG, "countermode = %d", flash8); } else { - ESP_LOGI(TAG, "countermode set to default %i", cfg.countermode); + ESP_LOGI(TAG, "countermode set to default %d", cfg.countermode); saveConfig(); } if( nvs_get_i8(my_handle, "wifiscancycle", &flash8) == ESP_OK ) { cfg.wifiscancycle = flash8; - ESP_LOGI(TAG, "wifiscancycle = %i", flash8); + ESP_LOGI(TAG, "wifiscancycle = %d", flash8); } else { - ESP_LOGI(TAG, "WIFI scan cycle set to default %i", cfg.wifiscancycle); + ESP_LOGI(TAG, "WIFI scan cycle set to default %d", cfg.wifiscancycle); saveConfig(); } if( nvs_get_i8(my_handle, "wifichancycle", &flash8) == ESP_OK ) { cfg.wifichancycle = flash8; - ESP_LOGI(TAG, "wifichancycle = %i", flash8); + ESP_LOGI(TAG, "wifichancycle = %d", flash8); } else { - ESP_LOGI(TAG, "WIFI channel cycle set to default %i", cfg.wifichancycle); + ESP_LOGI(TAG, "WIFI channel cycle set to default %d", cfg.wifichancycle); saveConfig(); } if( nvs_get_i8(my_handle, "wifiant", &flash8) == ESP_OK ) { cfg.wifiant = flash8; - ESP_LOGI(TAG, "wifiantenna = %i", flash8); + ESP_LOGI(TAG, "wifiantenna = %d", flash8); } else { - ESP_LOGI(TAG, "WIFI antenna switch set to default %i", cfg.wifiant); + ESP_LOGI(TAG, "WIFI antenna switch set to default %d", cfg.wifiant); saveConfig(); } if( nvs_get_i8(my_handle, "vendorfilter", &flash8) == ESP_OK ) { cfg.vendorfilter = flash8; - ESP_LOGI(TAG, "vendorfilter = %i", flash8); + ESP_LOGI(TAG, "vendorfilter = %d", flash8); } else { - ESP_LOGI(TAG, "Vendorfilter mode set to default %i", cfg.vendorfilter); + ESP_LOGI(TAG, "Vendorfilter mode set to default %d", cfg.vendorfilter); saveConfig(); } if( nvs_get_i8(my_handle, "rgblum", &flash8) == ESP_OK ) { cfg.rgblum = flash8; - ESP_LOGI(TAG, "rgbluminosity = %i", flash8); + ESP_LOGI(TAG, "rgbluminosity = %d", flash8); } else { - ESP_LOGI(TAG, "RGB luminosity set to default %i", cfg.rgblum); + ESP_LOGI(TAG, "RGB luminosity set to default %d", cfg.rgblum); saveConfig(); } if( nvs_get_i8(my_handle, "blescantime", &flash8) == ESP_OK ) { cfg.blescantime = flash8; - ESP_LOGI(TAG, "blescantime = %i", flash8); + ESP_LOGI(TAG, "blescantime = %d", flash8); } else { - ESP_LOGI(TAG, "BLEscantime set to default %i", cfg.blescantime); + ESP_LOGI(TAG, "BLEscantime set to default %d", cfg.blescantime); saveConfig(); } if( nvs_get_i8(my_handle, "blescanmode", &flash8) == ESP_OK ) { cfg.blescan = flash8; - ESP_LOGI(TAG, "BLEscanmode = %i", flash8); + ESP_LOGI(TAG, "BLEscanmode = %d", flash8); } else { - ESP_LOGI(TAG, "BLEscanmode set to default %i", cfg.blescan); + ESP_LOGI(TAG, "BLEscanmode set to default %d", cfg.blescan); saveConfig(); } if( nvs_get_i16(my_handle, "rssilimit", &flash16) == ESP_OK ) { cfg.rssilimit = flash16; - ESP_LOGI(TAG, "rssilimit = %i", flash16); + ESP_LOGI(TAG, "rssilimit = %d", flash16); } else { - ESP_LOGI(TAG, "rssilimit set to default %i", cfg.rssilimit); + ESP_LOGI(TAG, "rssilimit set to default %d", cfg.rssilimit); saveConfig(); } diff --git a/src/globals.h b/src/globals.h index 158fecf0..7035c7d2 100644 --- a/src/globals.h +++ b/src/globals.h @@ -48,12 +48,11 @@ extern uint8_t mydata[]; extern uint64_t uptimecounter; extern unsigned long currentMillis ; extern osjob_t sendjob; -extern char display_lora[], display_lmic[], display_mem[]; +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 const uint32_t heapmem; #ifdef HAS_DISPLAY extern HAS_DISPLAY u8x8; diff --git a/src/lorawan.cpp b/src/lorawan.cpp index d0ffdd96..b4f09726 100644 --- a/src/lorawan.cpp +++ b/src/lorawan.cpp @@ -176,7 +176,7 @@ void onEvent (ev_t ev) { switch_lora(cfg.lorasf,cfg.txpower); // show effective LoRa parameters after join - ESP_LOGI(TAG, "ADR=%i, SF=%i, TXPOWER=%i", cfg.adrmode, cfg.lorasf, cfg.txpower); + ESP_LOGI(TAG, "ADR=%d, SF=%d, TXPOWER=%d", cfg.adrmode, cfg.lorasf, cfg.txpower); break; case EV_TXCOMPLETE: diff --git a/src/macsniff.cpp b/src/macsniff.cpp index 3595f18e..331feb35 100644 --- a/src/macsniff.cpp +++ b/src/macsniff.cpp @@ -27,7 +27,6 @@ bool mac_add(uint8_t *paddr, int8_t rssi, bool sniff_type) { bool added = false; uint32_t addr2int, vendor2int; // temporary buffer for MAC and Vendor OUI uint16_t hashedmac; // temporary buffer for generated hash value - uint8_t memlevel; // % of used heap mem // only last 3 MAC Address bytes are used for MAC address anonymization // but since it's uint32 we take 4 bytes to avoid 1st value to be 0 @@ -51,9 +50,6 @@ bool mac_add(uint8_t *paddr, int8_t rssi, bool sniff_type) { // Count only if MAC was not yet seen if (added) { - // Display heap memory left - memlevel = ESP.getFreeHeap() / heapmem * 100; - sprintf(display_mem, "%i%%", memlevel); // increment counter and one blink led if (sniff_type == MAC_SNIFF_WIFI ) { macs_wifi++; // increment Wifi MACs counter @@ -72,10 +68,10 @@ bool mac_add(uint8_t *paddr, int8_t rssi, bool sniff_type) { } // Log scan result - ESP_LOGI(TAG, "%s RSSI %ddBi -> MAC %s -> Hash %04X -> WiFi:%d BLTH:%d %s -> %d Bytes left", + ESP_LOGI(TAG, "%s %s RSSI %ddBi -> MAC %s -> Hash %04X -> WiFi:%d BLTH:%d -> %d Bytes left", + added ? "new " : "known", sniff_type==MAC_SNIFF_WIFI ? "WiFi":"BLTH", rssi, buff, hashedmac, macs_wifi, macs_ble, - added ? "new " : "known", ESP.getFreeHeap()); #ifdef VENDORFILTER diff --git a/src/main.cpp b/src/main.cpp index 2e8b8d21..8aff95ee 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -46,7 +46,7 @@ unsigned long previousDisplaymillis = currentMillis; // Display refresh for stat uint8_t DisplayState = 0; // globals for state machine uint16_t macs_total = 0, macs_wifi = 0, macs_ble = 0; // MAC counters globals for display uint8_t channel = 0; // wifi channel rotation counter global for display -char display_lora[16], display_lmic[16], display_mem[16]; // display buffers +char display_lora[16], display_lmic[16]; // display buffers led_states LEDState = LED_OFF; // LED state global for state machine led_states previousLEDState = LED_ON; // This will force LED to be off at boot since State is OFF unsigned long LEDBlinkStarted = 0; // When (in millis() led blink started) @@ -54,7 +54,6 @@ 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 -const uint32_t heapmem = ESP.getFreeHeap(); // free heap memory after start (:= 100%) std::set macs; // associative container holds total of unique MAC adress hashes (Wifi + BLE) @@ -314,15 +313,15 @@ uint64_t uptime() { u8x8.printf("%-16s", "BLTH:off"); #endif - // update free heap memory display (line 4) - u8x8.setCursor(11,4); - u8x8.printf("%-5s", display_mem); + // update free memory display (line 4) + u8x8.setCursor(10,4); + u8x8.printf("%4dKB", ESP.getFreeHeap() / 1024); // update RSSI limiter status & wifi channel display (line 5) u8x8.setCursor(0,5); u8x8.printf(!cfg.rssilimit ? "RLIM:off " : "RLIM:%-4d", cfg.rssilimit); u8x8.setCursor(11,5); - u8x8.printf("ch:%02i", channel); + u8x8.printf("ch:%02d", channel); // update LoRa status display (line 6) u8x8.setCursor(0,6); @@ -594,6 +593,13 @@ void loop() { updateDisplay(); #endif + // check free memory + if (ESP.getFreeHeap() <= MEM_LOW) { + do_send(&sendjob); // send count + reset_counters(); // clear macs container and reset all counters + reset_salt(); // get new salt for salting hashes + } + } /* end Aruino LOOP ------------------------------------------------------------ */ diff --git a/src/main.h b/src/main.h index 64a27267..8b0d5b60 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.23" // use max 10 chars here! +#define PROGVERSION "1.3.3" // use max 10 chars here! #define PROGNAME "PAXCNT" //--- Declarations --- diff --git a/src/paxcounter.conf b/src/paxcounter.conf index e981fc3c..ec8c455a 100644 --- a/src/paxcounter.conf +++ b/src/paxcounter.conf @@ -33,8 +33,8 @@ #define WIFI_CHANNEL_SWITCH_INTERVAL 50 // [seconds/100] -> 0,5 sec. // LoRa payload send cycle --> take care of duty cycle of LoRaWAN network! <-- -//#define SEND_SECS 120 // [seconds/2] -> 240 sec. -#define SEND_SECS 30 // [seconds/2] -> 60 sec. +#define SEND_SECS 120 // [seconds/2] -> 240 sec. +#define MEM_LOW 2048 // [Bytes] memory threshold triggering send cycle // Default LoRa Spreadfactor #define LORASFDEFAULT 9 // 7 ... 12 SF, according to LoRaWAN specs diff --git a/src/rcommand.cpp b/src/rcommand.cpp index fe73c8aa..90894149 100644 --- a/src/rcommand.cpp +++ b/src/rcommand.cpp @@ -74,22 +74,22 @@ void set_reset(int val) { void set_rssi(int val) { cfg.rssilimit = val * -1; - ESP_LOGI(TAG, "Remote command: set RSSI limit to %i", cfg.rssilimit); + ESP_LOGI(TAG, "Remote command: set RSSI limit to %d", cfg.rssilimit); }; void set_wifiscancycle(int val) { cfg.wifiscancycle = val; - ESP_LOGI(TAG, "Remote command: set Wifi scan cycle duration to %i seconds", cfg.wifiscancycle*2); + ESP_LOGI(TAG, "Remote command: set Wifi scan cycle duration to %d seconds", cfg.wifiscancycle*2); }; void set_wifichancycle(int val) { cfg.wifichancycle = val; - ESP_LOGI(TAG, "Remote command: set Wifi channel switch interval to %i seconds", cfg.wifichancycle/100); + ESP_LOGI(TAG, "Remote command: set Wifi channel switch interval to %d seconds", cfg.wifichancycle/100); }; void set_blescantime(int val) { cfg.blescantime = val; - ESP_LOGI(TAG, "Remote command: set BLE scan time to %i seconds", cfg.blescantime); + ESP_LOGI(TAG, "Remote command: set BLE scan time to %d seconds", cfg.blescantime); }; void set_countmode(int val) { @@ -126,7 +126,7 @@ void set_display(int val) { }; void set_lorasf(int val) { - ESP_LOGI(TAG, "Remote command: set LoRa SF to %i", val); + ESP_LOGI(TAG, "Remote command: set LoRa SF to %d", val); switch_lora(val, cfg.txpower); }; @@ -178,7 +178,7 @@ void set_rgblum(int val) { }; void set_lorapower(int val) { - ESP_LOGI(TAG, "Remote command: set LoRa TXPOWER to %i", val); + ESP_LOGI(TAG, "Remote command: set LoRa TXPOWER to %d", val); switch_lora(cfg.lorasf, val); }; @@ -195,7 +195,7 @@ void get_config (int val) { memcpy(sendData, &cfg, size); LMIC_setTxData2(RCMDPORT, sendData, size-1, 0); // send data unconfirmed on RCMD Port delete sendData; // free memory - ESP_LOGI(TAG, "%i bytes queued in send queue", size-1); + ESP_LOGI(TAG, "%d bytes queued in send queue", size-1); }; void get_uptime (int val) { @@ -205,7 +205,7 @@ void get_uptime (int val) { memcpy(sendData, (unsigned char*)&uptimecounter , size); LMIC_setTxData2(RCMDPORT, sendData, size-1, 0); // send data unconfirmed on RCMD Port delete sendData; // free memory - ESP_LOGI(TAG, "%i bytes queued in send queue", size-1); + ESP_LOGI(TAG, "%d bytes queued in send queue", size-1); }; void get_cputemp (int val) { @@ -216,7 +216,7 @@ void get_cputemp (int val) { memcpy(sendData, (unsigned char*)&temp, size); LMIC_setTxData2(RCMDPORT, sendData, size-1, 0); // send data unconfirmed on RCMD Port delete sendData; // free memory - ESP_LOGI(TAG, "%i bytes queued in send queue", size-1); + ESP_LOGI(TAG, "%d bytes queued in send queue", size-1); }; // assign previously defined functions to set of numeric remote commands