From da9ea6a35dd435429e089012d5c7e9be683c7599 Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Mon, 2 Apr 2018 21:02:22 +0200 Subject: [PATCH] main.cpp: bug fixed in loop count logic (issue #18) --- src/main.cpp | 19 ++++++++++--------- src/main.h | 31 ++++++++++++++++--------------- 2 files changed, 26 insertions(+), 24 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 7fa53199..dc5802b4 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -253,13 +253,6 @@ void wifi_sniffer_loop(void * pvParameters) { nloop++; // acutal number of wifi loops, controls cycle when data is sent - #ifdef BLECOUNTER // execute BLE count if BLE function is enabled - if (nloop % (WIFI_CHANNEL_MAX*2) == 0 ) { // once 2 full Wifi Channels scan, do a BLE scan - if (cfg.blescan) // execute BLE count if BLE function is enabled - BLECount(); - } - #endif - vTaskDelay(cfg.wifichancycle*10 / portTICK_PERIOD_MS); yield(); channel = (channel % WIFI_CHANNEL_MAX) + 1; // rotates variable channel 1..WIFI_CHANNEL_MAX @@ -274,9 +267,9 @@ void wifi_sniffer_loop(void * pvParameters) { u8x8.printf("MAC#: %-5i", wifis.size()); // duration of one wifi scan loop reached? then send data and begin new scan cycle - if( nloop >= ((100 / cfg.wifichancycle) * (cfg.wifiscancycle * 2)) ) { + if( nloop >= ( (100 / cfg.wifichancycle) * (cfg.wifiscancycle * 2)) +1 ) { u8x8.setPowerSave(!cfg.screenon); // set display on if enabled - nloop = 0; // reset wifi scan loop counter + nloop=0; channel=0; // reset wifi scan + channel loop counter do_send(&sendjob); // Prepare and execute LoRaWAN data upload vTaskDelay(500/portTICK_PERIOD_MS); yield(); @@ -314,6 +307,14 @@ void wifi_sniffer_loop(void * pvParameters) { yield(); u8x8.setPowerSave(1 && cfg.screensaver); // set display off if screensaver is enabled } // end of send data cycle + else { + #ifdef BLECOUNTER // execute BLE count if BLE function is enabled + if (nloop % (WIFI_CHANNEL_MAX * BLESCANCYCLE) == 0 ) { // once after BLESCANCYCLE Wifi scans, do a BLE scan + if (cfg.blescan) // execute BLE count if BLE function is enabled + BLECount(); + } + #endif + } // end of channel rotation loop } // end of infinite wifi scan loop } diff --git a/src/main.h b/src/main.h index 55e71be8..808ce5f6 100644 --- a/src/main.h +++ b/src/main.h @@ -1,34 +1,35 @@ // program version -#define PROGVERSION "1.2.8" // use max 10 chars here! +#define PROGVERSION "1.2.81" // use max 10 chars here! #define PROGNAME "PAXCNT" // Verbose enables serial output -#define VERBOSE 1 // comment out to silence the device, for mute use build option +#define VERBOSE 1 // comment out to silence the device, for mute use build option // 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 VENDORFILTER 1 // comment out if you want to count things, not people +#define BLECOUNTER 1 // comment out if you don't want BLE count // BLE scan time -#define BLESCANTIME 15 // [seconds] +#define BLESCANTIME 15 // [seconds] +#define BLESCANCYCLE 2 // BLE scan once after each wifi scans // WiFi Sniffer cycle interval -#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 SEND_SECS 30 // [seconds/2] -> 60 sec. // WiFi sniffer config -#define WIFI_CHANNEL_MIN 1 // start channel number where scan begings -#define WIFI_CHANNEL_MAX 13 // total channel number to scan -#define WIFI_MY_COUNTRY "EU" // for Wifi RF settings -#define WIFI_CHANNEL_SWITCH_INTERVAL 50 // [seconds/100] -> 0,5 sec. +#define WIFI_CHANNEL_MIN 1 // start channel number where scan begings +#define WIFI_CHANNEL_MAX 13 // total channel number to scan +#define WIFI_MY_COUNTRY "EU" // select locale for Wifi RF settings +#define WIFI_CHANNEL_SWITCH_INTERVAL 50 // [seconds/100] -> 0,5 sec. // Default LoRa Spreadfactor -#define LORASFDEFAULT 9 // 7 ... 12 -#define MAXLORARETRY 500 // maximum count of TX retries if LoRa busy -#define RCMDPORT 2 // LoRaWAN Port on which device listenes for remote commands +#define LORASFDEFAULT 9 // 7 ... 12 SF, according to LoRaWAN specs +#define MAXLORARETRY 500 // maximum count of TX retries if LoRa busy +#define RCMDPORT 2 // LoRaWAN Port on which device listenes for remote commands // Default RGB LED luminosity (in %) -#define RGBLUMINOSITY 50 // 50% +#define RGBLUMINOSITY 50 // 50% // LMIC settings // define hardware independent LMIC settings here, settings of standard library in /lmic/config.h will be ignored