From 549e9ef94451fb76d3f094554c150b938f7a9d85 Mon Sep 17 00:00:00 2001 From: Charles Date: Thu, 5 Apr 2018 08:46:59 +0200 Subject: [PATCH 01/11] removed unneeded #include --- src/configmanager.cpp | 1 - src/lorawan.cpp | 1 - src/rcommand.cpp | 1 - src/rgb_led.cpp | 1 - 4 files changed, 4 deletions(-) diff --git a/src/configmanager.cpp b/src/configmanager.cpp index ba39b8af..6227109e 100644 --- a/src/configmanager.cpp +++ b/src/configmanager.cpp @@ -1,6 +1,5 @@ /* configmanager persists runtime configuration using NVRAM of ESP32*/ -#include "main.h" #include "globals.h" #include #include diff --git a/src/lorawan.cpp b/src/lorawan.cpp index 6fde8a50..ee985e58 100644 --- a/src/lorawan.cpp +++ b/src/lorawan.cpp @@ -1,5 +1,4 @@ // Basic Config -#include "main.h" #include "globals.h" // LMIC-Arduino LoRaWAN Stack diff --git a/src/rcommand.cpp b/src/rcommand.cpp index 2e9ea33c..a0f3a535 100644 --- a/src/rcommand.cpp +++ b/src/rcommand.cpp @@ -3,7 +3,6 @@ // checks commands and executes each command with 1 argument per command // Basic Config -#include "main.h" #include "globals.h" // LMIC-Arduino LoRaWAN Stack diff --git a/src/rgb_led.cpp b/src/rgb_led.cpp index 58a31062..899ded9e 100644 --- a/src/rgb_led.cpp +++ b/src/rgb_led.cpp @@ -1,5 +1,4 @@ // Basic Config -#include "main.h" #include "globals.h" #ifdef HAS_RGB_LED From 66c4aa4a0c0bd51d69ccaf96129c0ffaeed5dcbf Mon Sep 17 00:00:00 2001 From: Charles Date: Thu, 5 Apr 2018 08:47:17 +0200 Subject: [PATCH 02/11] bump to v1.2.94 --- src/main.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main.h b/src/main.h index 16e8a293..ba1dbb68 100644 --- a/src/main.h +++ b/src/main.h @@ -1,5 +1,7 @@ +#pragma once + // program version - note: increment version after modifications to configData_t struct!! -#define PROGVERSION "1.2.93" // use max 10 chars here! +#define PROGVERSION "1.2.94" // use max 10 chars here! #define PROGNAME "PAXCNT" // Verbose enables serial output From 0e4c8facd0e9b376c5c5c6b43fb8c2f08f988bb3 Mon Sep 17 00:00:00 2001 From: Charles Date: Thu, 5 Apr 2018 08:47:41 +0200 Subject: [PATCH 03/11] make currentScanDevice extern --- src/macsniff.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/macsniff.h b/src/macsniff.h index fb00cd6d..9fa2496b 100644 --- a/src/macsniff.h +++ b/src/macsniff.h @@ -19,6 +19,8 @@ typedef struct { uint8_t payload[0]; /* network data ended with 4 bytes csum (CRC32) */ } wifi_ieee80211_packet_t; +extern uint16_t currentScanDevice; + uint16_t salt_reset(void); void BLECount(); void wifi_sniffer_init(void); From 428a29286cc80bea2b4296912436dd4a0ab442e9 Mon Sep 17 00:00:00 2001 From: Charles Date: Thu, 5 Apr 2018 08:48:08 +0200 Subject: [PATCH 04/11] Removed any display from mac_add --- src/macsniff.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/macsniff.cpp b/src/macsniff.cpp index 7d70a1c2..b8048fd7 100644 --- a/src/macsniff.cpp +++ b/src/macsniff.cpp @@ -1,6 +1,5 @@ // Basic Config -#include "main.h" #include "globals.h" #ifdef BLECOUNTER @@ -31,7 +30,7 @@ uint16_t salt_reset(void) { bool mac_add(uint8_t *paddr, int8_t rssi, bool sniff_type) { - char buff[32]; // temporary buffer for printf + char buff[16]; // temporary buffer for printf char typebuff[8]; bool added = false; uint32_t addr2int; @@ -69,8 +68,6 @@ bool mac_add(uint8_t *paddr, int8_t rssi, bool sniff_type) { } if (added) { // first time seen this WIFI or BLE MAC - 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 Wifi + BLE ESP_LOGI(TAG, "%s RSSI %ddBi -> Hash %04X -> WiFi:%d BLE:%d %s", typebuff, rssi, hashedmac, (int) wifis.size(), (int) bles.size(), buff ); @@ -93,11 +90,18 @@ bool mac_add(uint8_t *paddr, int8_t rssi, bool sniff_type) { class MyAdvertisedDeviceCallbacks: public BLEAdvertisedDeviceCallbacks { void onResult(BLEAdvertisedDevice advertisedDevice) { + int lastcount = (int) macs.size(); uint8_t *p = (uint8_t *) advertisedDevice.getAddress().getNative(); // Current devices seen on this scan session currentScanDevice++; - mac_add(p, advertisedDevice.getRSSI(), MAC_SNIFF_BLE); + // add this device and refresh display if it was not previously added + if ( mac_add(p, advertisedDevice.getRSSI(), MAC_SNIFF_BLE) ) { + char buff[16]; + snprintf(buff, sizeof(buff), "PAX:%d", (int) macs.size()); // convert 16-bit MAC counter to decimal counter value + u8x8.setCursor(0,0); + u8x8.draw2x2String(0, 0, buff); // display number on unique macs total Wifi + BLE + } u8x8.setCursor(12,3); u8x8.printf("%d", currentScanDevice); } @@ -115,9 +119,6 @@ void BLECount() { BLEScanResults foundDevices = pBLEScan->start(cfg.blescantime); int blenum=foundDevices.getCount(); ESP_LOGI(TAG, "BLE scan done, seen %d device(s)", blenum); - u8x8.clearLine(3); - u8x8.setCursor(0,3); - u8x8.printf("BLE#: %-4d %d", (int) bles.size(), currentScanDevice); } #endif From 17fab82cd7e50b331599c3efa40bf18973e3c603 Mon Sep 17 00:00:00 2001 From: Charles Date: Thu, 5 Apr 2018 08:48:24 +0200 Subject: [PATCH 05/11] Centralized display --- src/main.cpp | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index dbde51ef..bef03f58 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -22,7 +22,6 @@ Refer to LICENSE.txt file in repository for more details. */ // Basic Config -#include "main.h" #include "globals.h" // std::set for unified array functions @@ -254,13 +253,14 @@ void wifi_sniffer_init(void); void wifi_sniffer_set_channel(uint8_t channel); void wifi_sniffer_packet_handler(void *buff, wifi_promiscuous_pkt_type_t type); -//WiFi Sniffer Task -void wifi_sniffer_loop(void * pvParameters) { +// Sniffer Task +void sniffer_loop(void * pvParameters) { configASSERT( ( ( uint32_t ) pvParameters ) == 1 ); // FreeRTOS check uint8_t channel=0; + char buff[16]; int nloop=0, lorawait=0; - + while (true) { nloop++; // acutal number of wifi loops, controls cycle when data is sent @@ -270,12 +270,23 @@ void wifi_sniffer_loop(void * pvParameters) { channel = (channel % WIFI_CHANNEL_MAX) + 1; // rotates variable channel 1..WIFI_CHANNEL_MAX wifi_sniffer_set_channel(channel); ESP_LOGI(TAG, "Wifi set channel %d", channel); - u8x8.setCursor(0,5); - u8x8.printf(!cfg.rssilimit ? "RLIM: off" : "RLIM: %d", cfg.rssilimit); - u8x8.setCursor(11,5); - u8x8.printf("ch:%02i", channel); + + snprintf(buff, sizeof(buff), "PAX:%d", (int) macs.size()); // convert 16-bit MAC counter to decimal counter value + u8x8.setCursor(0,0); + u8x8.draw2x2String(0, 0, buff); // display number on unique macs total Wifi + BLE + //u8x8.clearLine(3); + u8x8.setCursor(0,3); + // We just state out of BLE scanning + if (currentScanDevice) { + u8x8.printf("BLE#: %-4d %d", (int) bles.size(), currentScanDevice); + } else { + u8x8.printf("BLE#: %-4d", (int) bles.size()); + } u8x8.setCursor(0,4); u8x8.printf("MAC#: %-5d", (int) wifis.size()); + u8x8.setCursor(0,5); + u8x8.printf(!cfg.rssilimit ? "RLIM: off" : "RLIM: %-3d", cfg.rssilimit); + u8x8.printf(" ch:%02i", channel); // duration of one wifi scan loop reached? then send data and begin new scan cycle if( nloop >= ( (100 / cfg.wifichancycle) * (cfg.wifiscancycle * 2)) +1 ) { @@ -358,7 +369,6 @@ void init_display(const char *Productname, const char *Version) { u8x8.begin(); u8x8.setFont(u8x8_font_chroma48medium8_r); #ifdef HAS_DISPLAY - Wire.setClock(100000); // experimental: reduce I2C bus speed to avoid display errors (must be done after begin) uint8_t buf[32]; u8x8.clear(); u8x8.setFlipMode(0); @@ -503,7 +513,7 @@ 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(wifi_sniffer_loop, "wifisniffer", 4096, ( void * ) 1, 1, NULL, 0); + xTaskCreatePinnedToCore(sniffer_loop, "wifisniffer", 4096, ( void * ) 1, 1, NULL, 0); #endif // Finally: kickoff first sendjob and join, then send initial payload "0000" From 89e4fb4d64dad570f7871aaa9cb94e4cf8bb7136 Mon Sep 17 00:00:00 2001 From: Charles Date: Thu, 5 Apr 2018 09:10:19 +0200 Subject: [PATCH 06/11] Updated doc to reflect code source --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 0fb86f77..154b79c3 100644 --- a/README.md +++ b/README.md @@ -81,8 +81,8 @@ Paxcounter generates identifiers for sniffed MAC adresses and collects them temp FPort1: - byte 1: 16-bit Wifi counter, MSB - byte 2: 16-bit Wifi counter, LSB + byte 1: 16-bit Total Wifi+BLE counter, MSB + byte 2: 16-bit Total Wifi+BLE counter, LSB byte 3: 16-bit BLE counter, MSB byte 4: 16-bit BLE counter, LSB From bc114e4d1f01212d298188e3703402f2f9c5d5cc Mon Sep 17 00:00:00 2001 From: Charles Date: Thu, 5 Apr 2018 09:56:26 +0200 Subject: [PATCH 07/11] Added board definition symbol --- platformio.ini | 11 ++++++++++- src/loraconf.sample.h | 8 ++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/platformio.ini b/platformio.ini index 4a4ef2f7..329190a2 100644 --- a/platformio.ini +++ b/platformio.ini @@ -37,6 +37,7 @@ build_flags = -std=c++11 ;override lora settings from LMiC library in lmic/config.h and use main.h instead -D_lmic_config_h_ + -Dheltec_wifi_lora_32 -include "src/main.h" -include "src/hal/heltec.h" ;FreeRTOS single core operation, switches off core 1 (see arduino-esp32/cores/esp32/main.cpp) @@ -47,7 +48,9 @@ platform = espressif32 board = esp32dev framework = arduino monitor_baud = 115200 -upload_speed = 921600 +; On my V1, upload does not works over default 115200 +upload_speed = 921600 +;upload_port = COM15 lib_deps = U8g2 ESP32 BLE Arduino@>=0.4.9 @@ -60,6 +63,7 @@ build_flags = -fexceptions -std=c++11 ;override lora settings from LMiC library in lmic/config.h and use main.h instead + -Dttgov1 -D_lmic_config_h_ -include "src/main.h" -include "src/hal/ttgov1.h" @@ -86,6 +90,7 @@ build_flags = -std=c++11 ;override lora settings from LMiC library in lmic/config.h and use main.h instead -D_lmic_config_h_ + -Dttgov2 -include "src/main.h" -include "src/hal/ttgov2.h" ;FreeRTOS single core operation, switches off core 1 (see arduino-esp32/cores/esp32/main.cpp) @@ -110,6 +115,7 @@ build_flags = -fexceptions -std=c++11 ;override lora settings from LMiC library in lmic/config.h and use main.h instead + -Dlopy -D_lmic_config_h_ -include "src/main.h" -include "src/hal/lopy.h" @@ -136,6 +142,7 @@ build_flags = -std=c++11 ;override lora settings from LMiC library in lmic/config.h and use main.h instead -D_lmic_config_h_ + -Dlopy4 -include "src/main.h" -include "src/hal/lopy4.h" ;FreeRTOS single core operation, switches off core 1 (see arduino-esp32/cores/esp32/main.cpp) @@ -161,6 +168,7 @@ build_flags = -std=c++11 ;override lora settings from LMiC library in lmic/config.h and use main.h instead -D_lmic_config_h_ + -Dlolin32lite_lora -include "src/main.h" -include "src/hal/lolin32lite_lora.h" ;FreeRTOS single core operation, switches off core 1 (see arduino-esp32/cores/esp32/main.cpp) @@ -186,6 +194,7 @@ build_flags = -std=c++11 ;override lora settings from LMiC library in lmic/config.h and use main.h instead -D_lmic_config_h_ + -Dlolin32_lora -include "src/main.h" -include "src/hal/lolin32_lora.h" ;FreeRTOS single core operation, switches off core 1 (see arduino-esp32/cores/esp32/main.cpp) diff --git a/src/loraconf.sample.h b/src/loraconf.sample.h index cbfd3d47..5a60a654 100644 --- a/src/loraconf.sample.h +++ b/src/loraconf.sample.h @@ -14,7 +14,15 @@ // 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 *** +#if defined (ttgov2) +static const u1_t DEVEUI[8]={ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02 }; +#elif defined (ttgov1) +static const u1_t DEVEUI[8]={ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }; +#elif defined (heltec_wifi_lora_32) +static const u1_t DEVEUI[8]={ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x32 }; +#else static const u1_t DEVEUI[8]={ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; +#endif // Note: Use msb format for APPEUI as in TTN console (cut & paste, for your convenience) // For TTN, APPEUI always starts with 0x70, 0xB3, 0xD5 From 114651d8c0aa1d05c9025846fa3533b689f63f75 Mon Sep 17 00:00:00 2001 From: Charles Date: Thu, 5 Apr 2018 14:33:30 +0200 Subject: [PATCH 08/11] Improved hash & salt --- src/macsniff.cpp | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/macsniff.cpp b/src/macsniff.cpp index b8048fd7..a5d48a12 100644 --- a/src/macsniff.cpp +++ b/src/macsniff.cpp @@ -38,7 +38,8 @@ bool mac_add(uint8_t *paddr, int8_t rssi, bool sniff_type) { uint16_t hashedmac; // Only last 3 MAC Address bytes are used bay MAC Address Anonymization - addr2int = ( (uint32_t)paddr[3] ) | ( (uint32_t)paddr[4] << 8 ) | ( (uint32_t)paddr[5] << 16 ); + // but since it's uint32 we take 4 bytes to avoid 1st value to be 0 + addr2int = ( (uint32_t)paddr[2] ) | ( (uint32_t)paddr[3] << 8 ) | ( (uint32_t)paddr[4] << 16 ) | ( (uint32_t)paddr[5] << 24 ); #ifdef VENDORFILTER vendor2int = ( (uint32_t)paddr[2] ) | ( (uint32_t)paddr[1] << 8 ) | ( (uint32_t)paddr[0] << 16 ); @@ -49,9 +50,9 @@ bool mac_add(uint8_t *paddr, int8_t rssi, bool sniff_type) { // salt and hash MAC, and if new unique one, store identifier in container and increment counter on display // https://en.wikipedia.org/wiki/MAC_Address_Anonymization - addr2int += (uint32_t) salt << 16; // add 16-bit salt to 24-bit MAC + addr2int += (uint32_t) salt; // add 16-bit salt to pseudo MAC snprintf(buff, sizeof(buff), "%08X", addr2int); // convert unsigned 32-bit salted MAC to 8 digit hex string - hashedmac = rokkit(buff, 5); // hash MAC string, use 5 chars to fit hash in uint16_t container + hashedmac = rokkit(&buff[3], 5); // hash MAC last string value, use 5 chars to fit hash in uint16_t container auto newmac = macs.insert(hashedmac); // add hashed MAC to total container if new unique added = newmac.second ? true:false; // true if hashed MAC is unique in container @@ -67,13 +68,10 @@ bool mac_add(uint8_t *paddr, int8_t rssi, bool sniff_type) { rgb_set_color(COLOR_NONE); } - if (added) { // first time seen this WIFI or BLE MAC - ESP_LOGI(TAG, "%s RSSI %ddBi -> Hash %04X -> WiFi:%d BLE:%d %s", - typebuff, rssi, hashedmac, - (int) wifis.size(), (int) bles.size(), buff ); - } else { // already seen WIFI or BLE MAC - ESP_LOGI(TAG, "%s RSSI %ddBi -> Hash %04X -> already seen", typebuff, rssi, hashedmac); - } + ESP_LOGI(TAG, "%s RSSI %ddBi -> MAC %s -> Hash %04X -> WiFi:%d BLE:%d %s", + typebuff, rssi, buff, hashedmac, + (int) wifis.size(), (int) bles.size(), + added ? "already seen" : "new"); #ifdef VENDORFILTER } else { From a37a567ab2fb2ecffcb003bae90fbbd07fa34696 Mon Sep 17 00:00:00 2001 From: Charles Date: Thu, 5 Apr 2018 14:34:39 +0200 Subject: [PATCH 09/11] Code optimization --- src/lorawan.cpp | 120 ++++++++++++++---------------------------------- 1 file changed, 35 insertions(+), 85 deletions(-) diff --git a/src/lorawan.cpp b/src/lorawan.cpp index ee985e58..1fc76e61 100644 --- a/src/lorawan.cpp +++ b/src/lorawan.cpp @@ -10,8 +10,6 @@ #include // Needed for 24AA02E64, does not hurt anything if included and not used #endif -uint8_t mydata[] = "0000"; - // Local logging Tag static const char *TAG = "lorawan"; @@ -113,6 +111,7 @@ void printKeys(void) { #endif // VERBOSE void do_send(osjob_t* j){ + uint8_t mydata[4]; uint16_t data; // Total BLE+WIFI unique MACs seen data = (uint16_t) macs.size(); @@ -131,52 +130,40 @@ void do_send(osjob_t* j){ //mydata[5] = data & 0xff; // Check if there is not a current TX/RX job running + u8x8.clearLine(7); if (LMIC.opmode & OP_TXRXPEND) { ESP_LOGI(TAG, "OP_TXRXPEND, not sending"); - u8x8.clearLine(7); u8x8.drawString(0, 7, "LORA BUSY"); } else { // Prepare upstream data transmission at the next possible time. - LMIC_setTxData2(1, mydata, sizeof(mydata)-1, (cfg.countermode & 0x02)); + LMIC_setTxData2(1, mydata, sizeof(mydata), (cfg.countermode & 0x02)); ESP_LOGI(TAG, "Packet queued"); - u8x8.clearLine(7); u8x8.drawString(0, 7, "PACKET QUEUED"); } // Next TX is scheduled after TX_COMPLETE event. } void onEvent (ev_t ev) { + char buff[24]=""; + switch(ev) { - case EV_SCAN_TIMEOUT: - ESP_LOGI(TAG, "EV_SCAN_TIMEOUT"); - u8x8.clearLine(7); - u8x8.drawString(0, 7, "SCAN TIMEOUT"); - break; - case EV_BEACON_FOUND: - ESP_LOGI(TAG, "EV_BEACON_FOUND"); - u8x8.clearLine(7); - u8x8.drawString(0, 7, "BEACON FOUND"); - break; - case EV_BEACON_MISSED: - ESP_LOGI(TAG, "EV_BEACON_MISSED"); - u8x8.clearLine(7); - u8x8.drawString(0, 7, "BEACON MISSED"); - break; - case EV_BEACON_TRACKED: - ESP_LOGI(TAG, "EV_BEACON_TRACKED"); - u8x8.clearLine(7); - u8x8.drawString(0, 7, "BEACON TRACKED"); - break; - case EV_JOINING: - ESP_LOGI(TAG, "EV_JOINING"); - u8x8.clearLine(7); - u8x8.drawString(0, 7, "JOINING"); - break; + case EV_SCAN_TIMEOUT: strcpy_P(buff, PSTR("SCAN TIMEOUT")); break; + case EV_BEACON_FOUND: strcpy_P(buff, PSTR("BEACON FOUND")); break; + case EV_BEACON_MISSED: strcpy_P(buff, PSTR( "BEACON MISSED")); break; + case EV_BEACON_TRACKED: strcpy_P(buff, PSTR("BEACON TRACKED")); break; + case EV_JOINING: strcpy_P(buff, PSTR("JOINING")); break; + case EV_LOST_TSYNC: strcpy_P(buff, PSTR("LOST TSYNC")); break; + case EV_RESET: strcpy_P(buff, PSTR("RESET")); break; + case EV_RXCOMPLETE: strcpy_P(buff, PSTR("RX COMPLETE")); break; + case EV_LINK_DEAD: strcpy_P(buff, PSTR("LINK DEAD")); break; + case EV_LINK_ALIVE: strcpy_P(buff, PSTR("LINK ALIVE")); break; + case EV_RFU1: strcpy_P(buff, PSTR("RFUI")); break; + case EV_JOIN_FAILED: strcpy_P(buff, PSTR("JOIN FAILED")); break; + case EV_REJOIN_FAILED: strcpy_P(buff, PSTR("REJOIN FAILED")); break; + case EV_JOINED: - ESP_LOGI(TAG, "EV_JOINED"); + strcpy_P(buff, PSTR("JOINED")); u8x8.clearLine(6); // erase "Join Wait" message from display, see main.cpp - u8x8.clearLine(7); - u8x8.drawString(0, 7, "JOINED"); // Disable link check validation (automatically enabled // during join, but not supported by TTN at this time). LMIC_setLinkCheckMode(0); @@ -188,35 +175,20 @@ void onEvent (ev_t ev) { // show effective LoRa parameters after join ESP_LOGI(TAG, "ADR=%i, SF=%i, TXPOWER=%i", cfg.adrmode, cfg.lorasf, cfg.txpower); break; - case EV_RFU1: - ESP_LOGI(TAG, "EV_RFU1"); - u8x8.clearLine(7); - u8x8.drawString(0, 7, "RFUI"); - break; - case EV_JOIN_FAILED: - ESP_LOGI(TAG, "EV_JOIN_FAILED"); - u8x8.clearLine(7); - u8x8.drawString(0, 7, "JOIN FAILED"); - break; - case EV_REJOIN_FAILED: - ESP_LOGI(TAG, "EV_REJOIN_FAILED"); - u8x8.clearLine(7); - u8x8.drawString(0, 7, "REJOIN FAILED"); - break; case EV_TXCOMPLETE: ESP_LOGI(TAG, "EV_TXCOMPLETE (includes waiting for RX windows)"); u8x8.clearLine(7); - u8x8.drawString(0, 7, "TX COMPLETE"); if (LMIC.txrxFlags & TXRX_ACK) { ESP_LOGI(TAG, "Received ack"); - u8x8.clearLine(7); u8x8.drawString(0, 7, "RECEIVED ACK"); - } + } else { + u8x8.drawString(0, 7, "TX COMPLETE"); + } if (LMIC.dataLen) { - ESP_LOGI(TAG, "Received %i bytes of payload", LMIC.dataLen); + ESP_LOGI(TAG, "Received %d bytes of payload", LMIC.dataLen); u8x8.clearLine(6); u8x8.setCursor(0, 6); - u8x8.printf("Rcvd %i bytes", LMIC.dataLen); + u8x8.printf("Rcvd %d bytes", LMIC.dataLen); u8x8.clearLine(7); u8x8.setCursor(0, 7); // LMIC.snr = SNR twos compliment [dB] * 4 @@ -234,38 +206,16 @@ void onEvent (ev_t ev) { } } break; - case EV_LOST_TSYNC: - ESP_LOGI(TAG, "EV_LOST_TSYNC"); - u8x8.clearLine(7); - u8x8.drawString(0, 7, "LOST TSYNC"); - break; - case EV_RESET: - ESP_LOGI(TAG, "EV_RESET"); - u8x8.clearLine(7); - u8x8.drawString(0, 7, "RESET"); - break; - case EV_RXCOMPLETE: - // data received in ping slot - ESP_LOGI(TAG, "EV_RXCOMPLETE"); - u8x8.clearLine(7); - u8x8.drawString(0, 7, "RX COMPLETE"); - break; - case EV_LINK_DEAD: - ESP_LOGI(TAG, "EV_LINK_DEAD"); - u8x8.clearLine(7); - u8x8.drawString(0, 7, "LINK DEAD"); - break; - case EV_LINK_ALIVE: - ESP_LOGI(TAG, "EV_LINK_ALIVE"); - u8x8.clearLine(7); - u8x8.drawString(0, 7, "LINK ALIVE"); - break; - default: - ESP_LOGI(TAG, "Unknown event"); - u8x8.clearLine(7); - u8x8.setCursor(0, 7); - u8x8.printf("UNKNOWN EVENT %d", ev); - break; + default: sprintf_P(buff, PSTR("UNKNOWN EVENT %d"), ev); break; } + + // Log & Display if asked + if (*buff) { + ESP_LOGI(TAG, "EV_%s", buff); + u8x8.clearLine(7); + u8x8.drawString(0, 7, buff); + } + + } From 01d617f61e605c297f5217965fedc9b4df3e4c66 Mon Sep 17 00:00:00 2001 From: Charles Date: Thu, 5 Apr 2018 14:35:53 +0200 Subject: [PATCH 10/11] Fixed display bug --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index bef03f58..c479e370 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -274,7 +274,7 @@ void sniffer_loop(void * pvParameters) { snprintf(buff, sizeof(buff), "PAX:%d", (int) macs.size()); // convert 16-bit MAC counter to decimal counter value u8x8.setCursor(0,0); u8x8.draw2x2String(0, 0, buff); // display number on unique macs total Wifi + BLE - //u8x8.clearLine(3); + u8x8.clearLine(3); u8x8.setCursor(0,3); // We just state out of BLE scanning if (currentScanDevice) { From 7fc0fc0a742a40c329aa4d218659b97bd9397810 Mon Sep 17 00:00:00 2001 From: Charles Date: Thu, 5 Apr 2018 16:26:25 +0200 Subject: [PATCH 11/11] Optimize add function, fixed New/Already Seen bug --- src/macsniff.cpp | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/src/macsniff.cpp b/src/macsniff.cpp index a5d48a12..5071a828 100644 --- a/src/macsniff.cpp +++ b/src/macsniff.cpp @@ -31,7 +31,6 @@ uint16_t salt_reset(void) { bool mac_add(uint8_t *paddr, int8_t rssi, bool sniff_type) { char buff[16]; // temporary buffer for printf - char typebuff[8]; bool added = false; uint32_t addr2int; uint32_t vendor2int; @@ -56,22 +55,25 @@ bool mac_add(uint8_t *paddr, int8_t rssi, bool sniff_type) { auto newmac = macs.insert(hashedmac); // add hashed MAC to total container if new unique added = newmac.second ? true:false; // true if hashed MAC is unique in container - if (sniff_type == MAC_SNIFF_WIFI ) { - rgb_set_color(COLOR_GREEN); - wifis.insert(hashedmac); // add hashed MAC to wifi container if new unique - strcpy(typebuff, "WiFi"); + // Insert only if it was not found on global count + if (added) { + if (sniff_type == MAC_SNIFF_WIFI ) { + rgb_set_color(COLOR_GREEN); + wifis.insert(hashedmac); // add hashed MAC to wifi container if new unique + } else if (sniff_type == MAC_SNIFF_BLE ) { + rgb_set_color(COLOR_MAGENTA); + bles.insert(hashedmac); // add hashed MAC to BLE container if new unique + } + // Not sure user will have time to see the LED + // TBD do light off further in the code rgb_set_color(COLOR_NONE); - } else if (sniff_type == MAC_SNIFF_BLE ) { - rgb_set_color(COLOR_MAGENTA); - bles.insert(hashedmac); // add hashed MAC to BLE container if new unique - strcpy(typebuff, "BLE "); - rgb_set_color(COLOR_NONE); - } - + } + ESP_LOGI(TAG, "%s RSSI %ddBi -> MAC %s -> Hash %04X -> WiFi:%d BLE:%d %s", - typebuff, rssi, buff, hashedmac, + sniff_type==MAC_SNIFF_WIFI ? "WiFi":"BLE ", + rssi, buff, hashedmac, (int) wifis.size(), (int) bles.size(), - added ? "already seen" : "new"); + added ? "New" : "Already seen"); #ifdef VENDORFILTER } else {