removed 2 of 3 set arrays to save RAM
This commit is contained in:
parent
e41aaa45a0
commit
7f7dfaeec8
@ -3,8 +3,8 @@
|
|||||||
|
|
||||||
// std::set for unified array functions
|
// std::set for unified array functions
|
||||||
#include <set>
|
#include <set>
|
||||||
#include <array>
|
//#include <array>
|
||||||
#include <algorithm>
|
//#include <algorithm>
|
||||||
|
|
||||||
#ifdef HAS_DISPLAY
|
#ifdef HAS_DISPLAY
|
||||||
// OLED Display
|
// OLED Display
|
||||||
@ -49,15 +49,10 @@ extern uint32_t currentMillis ;
|
|||||||
extern osjob_t sendjob;
|
extern osjob_t sendjob;
|
||||||
extern char display_lora[], display_lmic[];
|
extern char display_lora[], display_lmic[];
|
||||||
extern int countermode, screensaver, adrmode, lorasf, txpower, rlim;
|
extern int countermode, screensaver, adrmode, lorasf, txpower, rlim;
|
||||||
|
extern uint16_t macs_total, macs_wifi, macs_ble; // MAC counters
|
||||||
extern bool joinstate;
|
extern bool joinstate;
|
||||||
extern std::set<uint16_t> wifis;
|
|
||||||
extern std::set<uint16_t> macs;
|
extern std::set<uint16_t> macs;
|
||||||
|
|
||||||
#ifdef HAS_DISPLAY
|
#ifdef HAS_DISPLAY
|
||||||
extern HAS_DISPLAY u8x8;
|
extern HAS_DISPLAY u8x8;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef BLECOUNTER
|
|
||||||
extern int scanTime;
|
|
||||||
extern std::set<uint16_t> bles;
|
|
||||||
#endif
|
|
||||||
|
@ -111,15 +111,13 @@ void do_send(osjob_t* j){
|
|||||||
uint8_t mydata[4];
|
uint8_t mydata[4];
|
||||||
uint16_t data;
|
uint16_t data;
|
||||||
// Sum of unique WIFI MACs seen
|
// Sum of unique WIFI MACs seen
|
||||||
data = (uint16_t) wifis.size();
|
mydata[0] = (macs_wifi & 0xff00) >> 8;
|
||||||
mydata[0] = (data & 0xff00) >> 8;
|
mydata[1] = macs_wifi & 0xff;
|
||||||
mydata[1] = data & 0xff;
|
|
||||||
|
|
||||||
#ifdef BLECOUNTER
|
#ifdef BLECOUNTER
|
||||||
// Sum of unique BLE MACs seen
|
// Sum of unique BLE MACs seen
|
||||||
data = (uint16_t) bles.size();
|
mydata[2] = (macs_ble & 0xff00) >> 8;
|
||||||
mydata[2] = (data & 0xff00) >> 8;
|
mydata[3] = macs_ble & 0xff;
|
||||||
mydata[3] = data & 0xff;
|
|
||||||
#else
|
#else
|
||||||
mydata[2] = 0;
|
mydata[2] = 0;
|
||||||
mydata[3] = 0;
|
mydata[3] = 0;
|
||||||
@ -128,8 +126,8 @@ void do_send(osjob_t* j){
|
|||||||
// Total BLE+WIFI unique MACs seen
|
// Total BLE+WIFI unique MACs seen
|
||||||
// TBD ?
|
// TBD ?
|
||||||
//data = (uint16_t) macs.size();
|
//data = (uint16_t) macs.size();
|
||||||
//mydata[4] = (data & 0xff00) >> 8;
|
//mydata[4] = (macs_total & 0xff00) >> 8;
|
||||||
//mydata[5] = data & 0xff;
|
//mydata[5] = macs_total & 0xff;
|
||||||
|
|
||||||
// Check if there is not a current TX/RX job running
|
// Check if there is not a current TX/RX job running
|
||||||
if (LMIC.opmode & OP_TXRXPEND) {
|
if (LMIC.opmode & OP_TXRXPEND) {
|
||||||
|
@ -53,13 +53,13 @@ bool mac_add(uint8_t *paddr, int8_t rssi, bool sniff_type) {
|
|||||||
// Insert only if it was not found on global count
|
// Insert only if it was not found on global count
|
||||||
if (added) {
|
if (added) {
|
||||||
if (sniff_type == MAC_SNIFF_WIFI ) {
|
if (sniff_type == MAC_SNIFF_WIFI ) {
|
||||||
|
macs_wifi++; // increment Wifi MACs counter
|
||||||
set_LED(COLOR_GREEN, 50, 0, 1);
|
set_LED(COLOR_GREEN, 50, 0, 1);
|
||||||
wifis.insert(hashedmac); // add hashed MAC to wifi container
|
|
||||||
}
|
}
|
||||||
#ifdef BLECOUNTER
|
#ifdef BLECOUNTER
|
||||||
else if (sniff_type == MAC_SNIFF_BLE ) {
|
else if (sniff_type == MAC_SNIFF_BLE ) {
|
||||||
|
macs_ble++; // increment BLE Macs counter
|
||||||
set_LED(COLOR_MAGENTA, 50, 0, 1);
|
set_LED(COLOR_MAGENTA, 50, 0, 1);
|
||||||
bles.insert(hashedmac); // add hashed MAC to BLE container
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@ -67,12 +67,7 @@ bool mac_add(uint8_t *paddr, int8_t rssi, bool sniff_type) {
|
|||||||
ESP_LOGI(TAG, "%s RSSI %ddBi -> MAC %s -> Hash %04X -> WiFi:%d BLTH:%d %s",
|
ESP_LOGI(TAG, "%s RSSI %ddBi -> MAC %s -> Hash %04X -> WiFi:%d BLTH:%d %s",
|
||||||
sniff_type==MAC_SNIFF_WIFI ? "WiFi":"BLTH",
|
sniff_type==MAC_SNIFF_WIFI ? "WiFi":"BLTH",
|
||||||
rssi, buff, hashedmac,
|
rssi, buff, hashedmac,
|
||||||
(int) wifis.size(),
|
macs_wifi,
|
||||||
#ifdef BLECOUNTER
|
|
||||||
(int) bles.size(),
|
|
||||||
#else
|
|
||||||
0,
|
|
||||||
#endif
|
|
||||||
added ? "new" : "known");
|
added ? "new" : "known");
|
||||||
|
|
||||||
#ifdef VENDORFILTER
|
#ifdef VENDORFILTER
|
||||||
|
51
src/main.cpp
51
src/main.cpp
@ -24,9 +24,6 @@ Refer to LICENSE.txt file in repository for more details.
|
|||||||
// Basic Config
|
// Basic Config
|
||||||
#include "globals.h"
|
#include "globals.h"
|
||||||
|
|
||||||
// std::set for unified array functions
|
|
||||||
#include <set>
|
|
||||||
|
|
||||||
// Does nothing and avoid any compilation error with I2C
|
// Does nothing and avoid any compilation error with I2C
|
||||||
#include <Wire.h>
|
#include <Wire.h>
|
||||||
|
|
||||||
@ -43,22 +40,23 @@ Refer to LICENSE.txt file in repository for more details.
|
|||||||
configData_t cfg; // struct holds current device configuration
|
configData_t cfg; // struct holds current device configuration
|
||||||
osjob_t sendjob, initjob; // LMIC
|
osjob_t sendjob, initjob; // LMIC
|
||||||
|
|
||||||
|
enum states {
|
||||||
|
LED_ON,
|
||||||
|
LED_OFF
|
||||||
|
};
|
||||||
|
|
||||||
// Initialize global variables
|
// Initialize global variables
|
||||||
char display_lora[16], display_lmic[16]; // display buffers
|
char display_lora[16], display_lmic[16]; // display buffers
|
||||||
uint64_t uptimecounter = 0;
|
uint64_t uptimecounter = 0; // timer global for uptime counter
|
||||||
uint32_t currentMillis = 0, previousDisplaymillis = 0;
|
uint32_t currentMillis = 0; // timer global for state machine
|
||||||
uint8_t DisplayState, LEDState = 0, LEDcount = 0;
|
uint8_t DisplayState, LEDcount = 0; // globals for state machine
|
||||||
uint16_t LEDBlinkduration = 0, LEDInterval = 0, color=COLOR_NONE;
|
uint16_t LEDBlinkduration = 0, LEDInterval = 0, color=COLOR_NONE; // state machine variables
|
||||||
uint8_t channel = 0; // wifi channel counter
|
uint16_t macs_total = 0, macs_wifi = 0, macs_ble = 0; // MAC counters globals for display
|
||||||
bool joinstate = false;
|
uint8_t channel = 0; // wifi channel rotation counter global for display
|
||||||
|
enum states LEDState = LED_OFF; // LED state global for state machine
|
||||||
|
bool joinstate = false; // LoRa network joined? global flag
|
||||||
|
|
||||||
std::set<uint16_t> macs; // associative container holds total of unique MAC adress hashes (Wifi + BLE)
|
std::set<uint16_t> macs; // associative container holds total of unique MAC adress hashes (Wifi + BLE)
|
||||||
std::set<uint16_t> wifis; // associative container holds unique Wifi MAC adress hashes
|
|
||||||
|
|
||||||
#ifdef BLECOUNTER
|
|
||||||
std::set<uint16_t> bles; // associative container holds unique BLE MAC adresses hashes
|
|
||||||
int scanTime;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// this variable will be changed in the ISR, and read in main loop
|
// this variable will be changed in the ISR, and read in main loop
|
||||||
static volatile bool ButtonTriggered = false;
|
static volatile bool ButtonTriggered = false;
|
||||||
@ -83,8 +81,8 @@ void set_LED (uint16_t set_color, uint16_t set_blinkduration, uint16_t set_inter
|
|||||||
color = set_color; // set color for RGB LED
|
color = set_color; // set color for RGB LED
|
||||||
LEDBlinkduration = set_blinkduration; // duration on
|
LEDBlinkduration = set_blinkduration; // duration on
|
||||||
LEDInterval = set_interval; // duration off - on - off
|
LEDInterval = set_interval; // duration off - on - off
|
||||||
LEDcount = set_count * 2; // number of blinks before LED off
|
LEDcount = set_count * 2; // number of on/off cycles before LED off
|
||||||
LEDState = set_count ? 1 : 0; // sets LED to off if 0 blinks
|
LEDState = set_count ? LED_ON : LED_OFF; // sets LED to off if 0 blinks
|
||||||
}
|
}
|
||||||
|
|
||||||
/* begin LMIC specific parts ------------------------------------------------------------ */
|
/* begin LMIC specific parts ------------------------------------------------------------ */
|
||||||
@ -250,10 +248,9 @@ void sniffer_loop(void * pvParameters) {
|
|||||||
// clear counter if not in cumulative counter mode
|
// clear counter if not in cumulative counter mode
|
||||||
if (cfg.countermode != 1) {
|
if (cfg.countermode != 1) {
|
||||||
macs.clear(); // clear all macs container
|
macs.clear(); // clear all macs container
|
||||||
wifis.clear(); // clear Wifi macs couner
|
macs_total = 0; // reset all counters
|
||||||
#ifdef BLECOUNTER
|
macs_wifi = 0;
|
||||||
bles.clear(); // clear BLE macs counter
|
macs_ble = 0;
|
||||||
#endif
|
|
||||||
salt_reset(); // get new salt for salting hashes
|
salt_reset(); // get new salt for salting hashes
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -358,12 +355,12 @@ uint64_t uptime() {
|
|||||||
snprintf(buff, sizeof(buff), "PAX:%-4d", (int) macs.size()); // convert 16-bit MAC counter to decimal counter value
|
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.draw2x2String(0, 0, buff); // display number on unique macs total Wifi + BLE
|
||||||
u8x8.setCursor(0,4);
|
u8x8.setCursor(0,4);
|
||||||
u8x8.printf("WIFI: %-4d", (int) wifis.size());
|
u8x8.printf("WIFI: %-4d", macs_wifi);
|
||||||
|
|
||||||
#ifdef BLECOUNTER
|
#ifdef BLECOUNTER
|
||||||
u8x8.setCursor(0,3);
|
u8x8.setCursor(0,3);
|
||||||
if (cfg.blescan)
|
if (cfg.blescan)
|
||||||
u8x8.printf("BLTH: %-4d", (int) bles.size());
|
u8x8.printf("BLTH: %-4d", macs_ble);
|
||||||
else
|
else
|
||||||
u8x8.printf("%-16s", "BLTH: off");
|
u8x8.printf("%-16s", "BLTH: off");
|
||||||
#endif
|
#endif
|
||||||
@ -387,6 +384,8 @@ uint64_t uptime() {
|
|||||||
|
|
||||||
void updateDisplay() {
|
void updateDisplay() {
|
||||||
// timed display refresh according to refresh cycle setting
|
// timed display refresh according to refresh cycle setting
|
||||||
|
uint32_t previousDisplaymillis = currentMillis;
|
||||||
|
|
||||||
if (currentMillis - previousDisplaymillis >= DISPLAYREFRESH_MS) {
|
if (currentMillis - previousDisplaymillis >= DISPLAYREFRESH_MS) {
|
||||||
refreshDisplay();
|
refreshDisplay();
|
||||||
previousDisplaymillis += DISPLAYREFRESH_MS;
|
previousDisplaymillis += DISPLAYREFRESH_MS;
|
||||||
@ -414,7 +413,7 @@ uint64_t uptime() {
|
|||||||
|
|
||||||
#ifdef HAS_LED
|
#ifdef HAS_LED
|
||||||
void switchLED() {
|
void switchLED() {
|
||||||
static bool previousLEDState;
|
enum states previousLEDState;
|
||||||
// led need to change state? avoid digitalWrite() for nothing
|
// led need to change state? avoid digitalWrite() for nothing
|
||||||
if (LEDState != previousLEDState) {
|
if (LEDState != previousLEDState) {
|
||||||
#ifdef LED_ACTIVE_LOW
|
#ifdef LED_ACTIVE_LOW
|
||||||
@ -434,9 +433,9 @@ uint64_t uptime() {
|
|||||||
|
|
||||||
void switchLEDstate() {
|
void switchLEDstate() {
|
||||||
if (!LEDcount) // no more blinks? -> switch off LED
|
if (!LEDcount) // no more blinks? -> switch off LED
|
||||||
LEDState = 0;
|
LEDState = LED_OFF;
|
||||||
else if (LEDInterval) // blinks left? -> toggle LED and decrement blinks
|
else if (LEDInterval) // blinks left? -> toggle LED and decrement blinks
|
||||||
LEDState = ((currentMillis % LEDInterval) < LEDBlinkduration) ? 1 : 0;
|
LEDState = ((currentMillis % LEDInterval) < LEDBlinkduration) ? LED_ON : LED_OFF;
|
||||||
} // switchLEDstate()
|
} // switchLEDstate()
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -65,10 +65,9 @@ void set_reset(int val) {
|
|||||||
case 1: // reset MAC counter
|
case 1: // reset MAC counter
|
||||||
ESP_LOGI(TAG, "Remote command: reset MAC counter");
|
ESP_LOGI(TAG, "Remote command: reset MAC counter");
|
||||||
macs.clear(); // clear all macs container
|
macs.clear(); // clear all macs container
|
||||||
wifis.clear(); // clear Wifi macs container
|
macs_total = 0; // reset all counters
|
||||||
#ifdef BLECOUNTER
|
macs_wifi = 0;
|
||||||
bles.clear(); // clear BLE macs container
|
macs_ble = 0;
|
||||||
#endif
|
|
||||||
salt_reset(); // get new 16bit salt
|
salt_reset(); // get new 16bit salt
|
||||||
sprintf(display_lora, "Reset counter");
|
sprintf(display_lora, "Reset counter");
|
||||||
break;
|
break;
|
||||||
@ -152,9 +151,7 @@ void set_blescan(int val) {
|
|||||||
switch (val) {
|
switch (val) {
|
||||||
case 0:
|
case 0:
|
||||||
cfg.blescan = 0;
|
cfg.blescan = 0;
|
||||||
#ifdef BLECOUNTER
|
macs_ble = 0; // clear BLE counter
|
||||||
bles.clear(); // clear BLE macs container
|
|
||||||
#endif
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
cfg.blescan = 1;
|
cfg.blescan = 1;
|
||||||
|
Loading…
Reference in New Issue
Block a user