libpax integration

This commit is contained in:
Michael Solinski 2021-03-02 18:36:34 +01:00
parent 731bbfb8d1
commit 3f3027aa69
13 changed files with 149 additions and 6 deletions

View File

@ -12,6 +12,9 @@
#include "sdcard.h" #include "sdcard.h"
#include "macsniff.h" #include "macsniff.h"
#include "reset.h" #include "reset.h"
#ifdef LIBPAX
#include <libpax_api.h>
#endif
extern Ticker cyclicTimer; extern Ticker cyclicTimer;

View File

@ -141,6 +141,9 @@ extern uint8_t volatile channel; // wifi channel rotation counter
extern uint8_t volatile rf_load; // RF traffic indicator extern uint8_t volatile rf_load; // RF traffic indicator
extern uint8_t batt_level; // display value extern uint8_t batt_level; // display value
extern uint16_t volatile macs_wifi, macs_ble; // display values extern uint16_t volatile macs_wifi, macs_ble; // display values
#ifdef LIBPAX
extern uint16_t volatile libpax_macs_ble, libpax_macs_wifi; // libpax values
#endif
extern bool volatile TimePulseTick; // 1sec pps flag set by GPS or RTC extern bool volatile TimePulseTick; // 1sec pps flag set by GPS or RTC
extern timesource_t timeSource; extern timesource_t timeSource;
extern hw_timer_t *displayIRQ, *matrixDisplayIRQ, *ppsIRQ; extern hw_timer_t *displayIRQ, *matrixDisplayIRQ, *ppsIRQ;

View File

@ -9,10 +9,18 @@
#include "display.h" #include "display.h"
#include "sdcard.h" #include "sdcard.h"
#if (COUNT_ENS) #if (COUNT_ENS)
#include "corona.h" #include "corona.h"
#endif #endif
#if (LIBPAX)
#include <libpax_api.h>
extern struct count_payload_t count_from_libpax;
#endif
extern Ticker sendTimer; extern Ticker sendTimer;
void SendPayload(uint8_t port); void SendPayload(uint8_t port);

View File

@ -89,6 +89,7 @@ lib_deps_basic =
lewisxhe/AXP202X_Library @ ^1.1.3 lewisxhe/AXP202X_Library @ ^1.1.3
geeksville/esp32-micro-sdcard @ ^0.1.1 geeksville/esp32-micro-sdcard @ ^0.1.1
256dpi/MQTT @ ^2.4.7 256dpi/MQTT @ ^2.4.7
https://github.com/dbSuS/libpax
lib_deps_all = lib_deps_all =
${common.lib_deps_basic} ${common.lib_deps_basic}
${common.lib_deps_lora} ${common.lib_deps_lora}
@ -105,6 +106,9 @@ build_flags_basic =
'-DPROGVERSION="${common.release_version}"' '-DPROGVERSION="${common.release_version}"'
'-Wno-unknown-pragmas' '-Wno-unknown-pragmas'
'-Wno-unused-variable' '-Wno-unused-variable'
'-D LIBPAX_WIFI'
'-D LIBPAX_BLE'
'-D LIBPAX_ARDUINO'
build_flags_sensors = build_flags_sensors =
-Llib/Bosch-BSEC/src/esp32/ -Llib/Bosch-BSEC/src/esp32/
-lalgobsec -lalgobsec

View File

@ -1,3 +1,4 @@
#ifndef LIBPAX
// some code snippets taken from // some code snippets taken from
// https://github.com/nkolban/esp32-snippets/tree/master/BLE/scanner // https://github.com/nkolban/esp32-snippets/tree/master/BLE/scanner
@ -300,3 +301,4 @@ void stop_BLEscan(void) {
ESP_LOGI(TAG, "Bluetooth scanner stopped"); ESP_LOGI(TAG, "Bluetooth scanner stopped");
#endif // BLECOUNTER #endif // BLECOUNTER
} // stop_BLEscan } // stop_BLEscan
#endif

View File

@ -134,11 +134,14 @@ uint32_t getFreeRAM() {
} }
void reset_counters() { void reset_counters() {
#if ((WIFICOUNTER) || (BLECOUNTER)) #if ((WIFICOUNTER) || (BLECOUNTER))
#ifndef LIBPAX
macs.clear(); // clear all macs container macs.clear(); // clear all macs container
macs_wifi = 0; macs_wifi = 0;
macs_ble = 0; macs_ble = 0;
renew_salt(); // get new salt renew_salt(); // get new salt
#endif
#ifdef HAS_DISPLAY #ifdef HAS_DISPLAY
dp_plotCurve(0, true); dp_plotCurve(0, true);
#endif #endif

View File

@ -262,7 +262,11 @@ void dp_drawPage(time_t t, bool nextpage) {
#if ((WIFICOUNTER) && (BLECOUNTER)) #if ((WIFICOUNTER) && (BLECOUNTER))
if (cfg.wifiscan) if (cfg.wifiscan)
#ifndef LIBPAX
dp_printf("WIFI:%-5d", macs_wifi); dp_printf("WIFI:%-5d", macs_wifi);
#else
dp_printf("WIFI:%-5d", libpax_macs_wifi);
#endif
else else
dp_printf("WIFI:off"); dp_printf("WIFI:off");
if (cfg.blescan) if (cfg.blescan)
@ -271,17 +275,29 @@ void dp_drawPage(time_t t, bool nextpage) {
dp_printf(" CWA:%-5d", cwa_report()); dp_printf(" CWA:%-5d", cwa_report());
else else
#endif #endif
#ifndef LIBPAX
dp_printf("BLTH:%-5d", macs_ble); dp_printf("BLTH:%-5d", macs_ble);
#else
dp_printf("BLTH:%-5d", libpax_macs_ble);
#endif
else else
dp_printf(" BLTH:off"); dp_printf(" BLTH:off");
#elif ((WIFICOUNTER) && (!BLECOUNTER)) #elif ((WIFICOUNTER) && (!BLECOUNTER))
if (cfg.wifiscan) if (cfg.wifiscan)
#ifndef LIBPAX
dp_printf("WIFI:%-5d", macs_wifi); dp_printf("WIFI:%-5d", macs_wifi);
#else
dp_printf("WIFI:%-5d", libpax_macs_wifi);
#endif
else else
dp_printf("WIFI:off"); dp_printf("WIFI:off");
#elif ((!WIFICOUNTER) && (BLECOUNTER)) #elif ((!WIFICOUNTER) && (BLECOUNTER))
if (cfg.blescan) if (cfg.blescan)
#ifndef LIBPAX
dp_printf("BLTH:%-5d", macs_ble); dp_printf("BLTH:%-5d", macs_ble);
#else
dp_printf("BLTH:%-5d", libpax_macs_ble);
#endif
#if (COUNT_ENS) #if (COUNT_ENS)
if (cfg.enscount) if (cfg.enscount)
dp_printf("(CWA:%d)", cwa_report()); dp_printf("(CWA:%d)", cwa_report());

View File

@ -90,9 +90,15 @@ triggers pps 1 sec impulse
configData_t cfg; // struct holds current device configuration configData_t cfg; // struct holds current device configuration
char lmic_event_msg[LMIC_EVENTMSG_LEN]; // display buffer for LMIC event message char lmic_event_msg[LMIC_EVENTMSG_LEN]; // display buffer for LMIC event message
uint8_t batt_level = 0; // display value uint8_t batt_level = 0; // display value
#ifndef LIBPAX
uint8_t volatile channel = WIFI_CHANNEL_MIN; // channel rotation counter uint8_t volatile channel = WIFI_CHANNEL_MIN; // channel rotation counter
#endif
uint8_t volatile rf_load = 0; // RF traffic indicator uint8_t volatile rf_load = 0; // RF traffic indicator
#ifndef LIBPAX
uint16_t volatile macs_wifi = 0, macs_ble = 0; // globals for display uint16_t volatile macs_wifi = 0, macs_ble = 0; // globals for display
#else
uint16_t volatile libpax_macs_ble, libpax_macs_wifi;
#endif
hw_timer_t *ppsIRQ = NULL, *displayIRQ = NULL, *matrixDisplayIRQ = NULL; hw_timer_t *ppsIRQ = NULL, *displayIRQ = NULL, *matrixDisplayIRQ = NULL;
@ -113,6 +119,17 @@ TimeChangeRule myDST = DAYLIGHT_TIME;
TimeChangeRule mySTD = STANDARD_TIME; TimeChangeRule mySTD = STANDARD_TIME;
Timezone myTZ(myDST, mySTD); Timezone myTZ(myDST, mySTD);
// libpax payload
#ifdef LIBPAX
struct count_payload_t count_from_libpax;
void process_count(void) {
printf("pax: %d; %d; %d;\n", count_from_libpax.pax, count_from_libpax.wifi_count, count_from_libpax.ble_count);
libpax_macs_ble = count_from_libpax.ble_count;
libpax_macs_wifi = count_from_libpax.wifi_count;
}
#endif
// local Tag for logging // local Tag for logging
static const char TAG[] = __FILE__; static const char TAG[] = __FILE__;
@ -298,9 +315,39 @@ void setup() {
if (RTC_runmode == RUNMODE_MAINTENANCE) if (RTC_runmode == RUNMODE_MAINTENANCE)
start_boot_menu(); start_boot_menu();
#ifndef LIBPAX
// start mac processing task // start mac processing task
ESP_LOGI(TAG, "Starting MAC processor..."); ESP_LOGI(TAG, "Starting MAC processor...");
macQueueInit(); macQueueInit();
#else
ESP_LOGI(TAG, "Starting libpax...");
#if (defined WIFICOUNTER || defined BLECOUNTER)
struct libpax_config_t configuration;
libpax_default_config(&configuration);
ESP_LOGI(TAG, "BLESCAN: %d", cfg.blescan);
ESP_LOGI(TAG, "WIFISCAN: %d", cfg.wifiscan);
if(!(cfg.blescan && cfg.wifiscan)) {
configuration.wificounter = cfg.wifiscan;
configuration.blecounter = cfg.blescan;
configuration.wifi_channel_map = WIFI_CHANNEL_ALL;
configuration.wifi_channel_switch_interval = cfg.wifichancycle;
configuration.wifi_rssi_threshold = cfg.rssilimit;
configuration.blescantime = cfg.blescantime;
int config_update = libpax_update_config(&configuration);
if(config_update != 0) {
ESP_LOGE(TAG, "Error in libpax configuration.");
} else {
libpax_counter_init(process_count, &count_from_libpax, 60*1000, 1);
libpax_counter_start();
}
} else {
ESP_LOGE(TAG, "Error in libpax configuration: Wifi and BLE are not supported at the same time!");
}
#endif
#endif
// start rcommand processing task // start rcommand processing task
ESP_LOGI(TAG, "Starting rcommand interpreter..."); ESP_LOGI(TAG, "Starting rcommand interpreter...");
@ -310,14 +357,18 @@ void setup() {
// or remove bluetooth stack from RAM, if option bluetooth is not compiled // or remove bluetooth stack from RAM, if option bluetooth is not compiled
#if (BLECOUNTER) #if (BLECOUNTER)
strcat_P(features, " BLE"); strcat_P(features, " BLE");
#ifndef LIBPAX
if (cfg.blescan) { if (cfg.blescan) {
ESP_LOGI(TAG, "Starting Bluetooth..."); ESP_LOGI(TAG, "Starting Bluetooth...");
start_BLEscan(); start_BLEscan();
} else } else
btStop(); btStop();
#endif
#else #else
// remove bluetooth stack to gain more free memory // remove bluetooth stack to gain more free memory
#ifndef LIBPAX
btStop(); btStop();
#endif
esp_bt_mem_release(ESP_BT_MODE_BTDM); esp_bt_mem_release(ESP_BT_MODE_BTDM);
esp_coex_preference_set( esp_coex_preference_set(
ESP_COEX_PREFER_WIFI); // configure Wifi/BT coexist lib ESP_COEX_PREFER_WIFI); // configure Wifi/BT coexist lib
@ -427,6 +478,7 @@ void setup() {
#if (WIFICOUNTER) #if (WIFICOUNTER)
strcat_P(features, " WIFI"); strcat_P(features, " WIFI");
#ifndef LIBPAX
// install wifi driver in RAM and start channel hopping // install wifi driver in RAM and start channel hopping
wifi_sniffer_init(); wifi_sniffer_init();
// start wifi sniffing, if enabled // start wifi sniffing, if enabled
@ -435,6 +487,8 @@ void setup() {
switch_wifi_sniffer(1); switch_wifi_sniffer(1);
} else } else
switch_wifi_sniffer(0); switch_wifi_sniffer(0);
#endif
#else #else
// remove wifi driver from RAM, if option wifi not compiled // remove wifi driver from RAM, if option wifi not compiled
esp_wifi_deinit(); esp_wifi_deinit();
@ -443,7 +497,9 @@ void setup() {
// initialize salt value using esp_random() called by random() in // initialize salt value using esp_random() called by random() in
// arduino-esp32 core. Note: do this *after* wifi has started, since // arduino-esp32 core. Note: do this *after* wifi has started, since
// function gets it's seed from RF noise // function gets it's seed from RF noise
#ifndef LIBPAX
reset_counters(); reset_counters();
#endif
// start state machine // start state machine
ESP_LOGI(TAG, "Starting Interrupt Handler..."); ESP_LOGI(TAG, "Starting Interrupt Handler...");

View File

@ -20,7 +20,7 @@
// MAC sniffing parameters // MAC sniffing parameters
#define MACFILTER 1 // set to 0 if you want to scan all devices, 1 to scan only devices with random MACs (aka smartphones) [default = 1] #define MACFILTER 1 // set to 0 if you want to scan all devices, 1 to scan only devices with random MACs (aka smartphones) [default = 1]
#define BLECOUNTER 1 // set to 0 if you do not want to install the BLE sniffer #define BLECOUNTER 0 // set to 0 if you do not want to install the BLE sniffer
#define WIFICOUNTER 1 // set to 0 if you do not want to install the WIFI sniffer #define WIFICOUNTER 1 // set to 0 if you do not want to install the WIFI sniffer
#define MAC_QUEUE_SIZE 50 // size of MAC processing buffer (number of MACs) [default = 50] #define MAC_QUEUE_SIZE 50 // size of MAC processing buffer (number of MACs) [default = 50]
@ -29,6 +29,9 @@
#define BLESCANWINDOW 80 // [milliseconds] scan window, see below, 3 .. 10240, default 80ms #define BLESCANWINDOW 80 // [milliseconds] scan window, see below, 3 .. 10240, default 80ms
#define BLESCANINTERVAL 80 // [illiseconds] scan interval, see below, 3 .. 10240, default 80ms = 100% duty cycle #define BLESCANINTERVAL 80 // [illiseconds] scan interval, see below, 3 .. 10240, default 80ms = 100% duty cycle
// Use libpax instead of default counting algorithms
#define LIBPAX 1
// Corona Exposure Notification Service(ENS) counter // Corona Exposure Notification Service(ENS) counter
#define COUNT_ENS 1 // count found number of devices which advertise Exposure Notification Service #define COUNT_ENS 1 // count found number of devices which advertise Exposure Notification Service
// set to 1 if you want to enable this function [default=0] // set to 1 if you want to enable this function [default=0]

View File

@ -72,6 +72,7 @@ void set_sleepcycle(uint8_t val[]) {
void set_wifichancycle(uint8_t val[]) { void set_wifichancycle(uint8_t val[]) {
cfg.wifichancycle = val[0]; cfg.wifichancycle = val[0];
#ifndef LIBAPX
// update Wifi channel rotation timer period // update Wifi channel rotation timer period
if (cfg.wifichancycle > 0) { if (cfg.wifichancycle > 0) {
if (xTimerIsTimerActive(WifiChanTimer) == pdFALSE) if (xTimerIsTimerActive(WifiChanTimer) == pdFALSE)
@ -88,10 +89,14 @@ void set_wifichancycle(uint8_t val[]) {
channel = WIFI_CHANNEL_MIN; channel = WIFI_CHANNEL_MIN;
ESP_LOGI(TAG, "Remote command: set Wifi channel hopping to off"); ESP_LOGI(TAG, "Remote command: set Wifi channel hopping to off");
} }
#else
// TODO update libpax configuration
#endif
} }
void set_blescantime(uint8_t val[]) { void set_blescantime(uint8_t val[]) {
cfg.blescantime = val[0]; cfg.blescantime = val[0];
#ifndef LIBPAX
ESP_LOGI(TAG, "Remote command: set BLE scan time to %.1f seconds", ESP_LOGI(TAG, "Remote command: set BLE scan time to %.1f seconds",
cfg.blescantime / float(100)); cfg.blescantime / float(100));
// stop & restart BLE scan task to apply new parameter // stop & restart BLE scan task to apply new parameter
@ -99,6 +104,9 @@ void set_blescantime(uint8_t val[]) {
stop_BLEscan(); stop_BLEscan();
start_BLEscan(); start_BLEscan();
} }
#else
// TODO update libpax configuration
#endif
} }
void set_countmode(uint8_t val[]) { void set_countmode(uint8_t val[]) {
@ -240,20 +248,28 @@ void set_loraadr(uint8_t val[]) {
void set_blescan(uint8_t val[]) { void set_blescan(uint8_t val[]) {
ESP_LOGI(TAG, "Remote command: set BLE scanner to %s", val[0] ? "on" : "off"); ESP_LOGI(TAG, "Remote command: set BLE scanner to %s", val[0] ? "on" : "off");
#ifndef LIBPAX
macs_ble = 0; // clear BLE counter macs_ble = 0; // clear BLE counter
cfg.blescan = val[0] ? 1 : 0; cfg.blescan = val[0] ? 1 : 0;
if (cfg.blescan) if (cfg.blescan)
start_BLEscan(); start_BLEscan();
else else
stop_BLEscan(); stop_BLEscan();
#else
// TODO update libpax configuration
#endif
} }
void set_wifiscan(uint8_t val[]) { void set_wifiscan(uint8_t val[]) {
ESP_LOGI(TAG, "Remote command: set WIFI scanner to %s", ESP_LOGI(TAG, "Remote command: set WIFI scanner to %s",
val[0] ? "on" : "off"); val[0] ? "on" : "off");
#ifndef LIBPAX
macs_wifi = 0; // clear WIFI counter macs_wifi = 0; // clear WIFI counter
cfg.wifiscan = val[0] ? 1 : 0; cfg.wifiscan = val[0] ? 1 : 0;
switch_wifi_sniffer(cfg.wifiscan); switch_wifi_sniffer(cfg.wifiscan);
#else
// TODO update libpax configuration
#endif
} }
void set_wifiant(uint8_t val[]) { void set_wifiant(uint8_t val[]) {

View File

@ -107,6 +107,7 @@ void enter_deepsleep(const uint64_t wakeup_sec, gpio_num_t wakeup_gpio) {
sendTimer.detach(); sendTimer.detach();
// switch off radio and other power consuming hardware // switch off radio and other power consuming hardware
#ifndef LIBPAX
#if (WIFICOUNTER) #if (WIFICOUNTER)
switch_wifi_sniffer(0); switch_wifi_sniffer(0);
#endif #endif
@ -114,6 +115,7 @@ void enter_deepsleep(const uint64_t wakeup_sec, gpio_num_t wakeup_gpio) {
stop_BLEscan(); stop_BLEscan();
btStop(); btStop();
#endif #endif
#endif
#if (HAS_SDS011) #if (HAS_SDS011)
sds011_sleep(void); sds011_sleep(void);
#endif #endif

View File

@ -57,7 +57,11 @@ void SendPayload(uint8_t port) {
// write data to sdcard, if present // write data to sdcard, if present
#if (HAS_SDCARD) #if (HAS_SDCARD)
if (port == COUNTERPORT) { if (port == COUNTERPORT) {
#ifndef LIBPAX
sdcardWriteData(macs_wifi, macs_ble sdcardWriteData(macs_wifi, macs_ble
#else
sdcardWriteData(libpax_macs_wifi, libpax_macs_ble
#endif
#if (COUNT_ENS) #if (COUNT_ENS)
, ,
cwa_report() cwa_report()
@ -87,9 +91,20 @@ void sendData() {
case COUNT_DATA: case COUNT_DATA:
payload.reset(); payload.reset();
#if !(PAYLOAD_OPENSENSEBOX) #if !(PAYLOAD_OPENSENSEBOX)
#ifndef LIBPAX
payload.addCount(macs_wifi, MAC_SNIFF_WIFI); payload.addCount(macs_wifi, MAC_SNIFF_WIFI);
if (cfg.blescan) #else
ESP_LOGI(TAG, "Sending libpax wifi count: %d", libpax_macs_wifi);
payload.addCount(libpax_macs_wifi, MAC_SNIFF_WIFI);
#endif
if (cfg.blescan) {
#ifndef LIBPAX
payload.addCount(macs_ble, MAC_SNIFF_BLE); payload.addCount(macs_ble, MAC_SNIFF_BLE);
#else
ESP_LOGI(TAG, "Sending libpax ble count: %d", libpax_macs_ble);
payload.addCount(libpax_macs_ble, MAC_SNIFF_BLE);
#endif
}
#endif #endif
#if (HAS_GPS) #if (HAS_GPS)
if (GPSPORT == COUNTERPORT) { if (GPSPORT == COUNTERPORT) {
@ -102,9 +117,19 @@ void sendData() {
} }
#endif #endif
#if (PAYLOAD_OPENSENSEBOX) #if (PAYLOAD_OPENSENSEBOX)
#ifndef LIBPAX
payload.addCount(macs_wifi, MAC_SNIFF_WIFI); payload.addCount(macs_wifi, MAC_SNIFF_WIFI);
if (cfg.blescan) #else
ESP_LOGI(TAG, "Sending libpax wifi count: %d", libpax_macs_wifi);
payload.addCount(libpax_macs_wifi, MAC_SNIFF_WIFI);
#endif
if (cfg.blescan) {
#ifndef LIBPAX
payload.addCount(macs_ble, MAC_SNIFF_BLE); payload.addCount(macs_ble, MAC_SNIFF_BLE);
#else
ESP_LOGI(TAG, "Sending libpax ble count: %d", libpax_macs_ble);
payload.addCount(libpax_macs_ble, MAC_SNIFF_BLE);
#endif
#endif #endif
#if (HAS_SDS011) #if (HAS_SDS011)
sds011_store(&sds_status); sds011_store(&sds_status);

View File

@ -1,3 +1,4 @@
#ifndef LIBPAX
// Basic Config // Basic Config
#include "globals.h" #include "globals.h"
#include "wifiscan.h" #include "wifiscan.h"
@ -103,3 +104,4 @@ void switch_wifi_sniffer(uint8_t state) {
esp_wifi_stop(); esp_wifi_stop();
} }
} }
#endif