Merge pull request #32 from hallard/master

Fixed display bug
This commit is contained in:
Verkehrsrot 2018-04-05 21:16:24 +02:00 committed by GitHub
commit 5763606bee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 111 additions and 133 deletions

View File

@ -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

View File

@ -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)

View File

@ -1,6 +1,5 @@
/* configmanager persists runtime configuration using NVRAM of ESP32*/
#include "main.h"
#include "globals.h"
#include <nvs.h>
#include <nvs_flash.h>

View File

@ -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

View File

@ -1,5 +1,4 @@
// Basic Config
#include "main.h"
#include "globals.h"
// LMIC-Arduino LoRaWAN Stack
@ -11,8 +10,6 @@
#include <Wire.h> // 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";
@ -114,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();
@ -132,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);
@ -189,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
@ -235,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);
}
}

View File

@ -1,6 +1,5 @@
// Basic Config
#include "main.h"
#include "globals.h"
#ifdef BLECOUNTER
@ -31,15 +30,15 @@ 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 typebuff[8];
char buff[16]; // temporary buffer for printf
bool added = false;
uint32_t addr2int;
uint32_t vendor2int;
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 );
@ -50,33 +49,31 @@ 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
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);
}
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 );
} 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",
sniff_type==MAC_SNIFF_WIFI ? "WiFi":"BLE ",
rssi, buff, hashedmac,
(int) wifis.size(), (int) bles.size(),
added ? "New" : "Already seen");
#ifdef VENDORFILTER
} else {
@ -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

View File

@ -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);

View File

@ -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"

View File

@ -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

View File

@ -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

View File

@ -1,5 +1,4 @@
// Basic Config
#include "main.h"
#include "globals.h"
#ifdef HAS_RGB_LED