Reenable BLE Wifi switching for libpax
This commit is contained in:
parent
93dcace8bd
commit
d9cdeddecf
@ -12,7 +12,7 @@
|
|||||||
#include "sdcard.h"
|
#include "sdcard.h"
|
||||||
#include "macsniff.h"
|
#include "macsniff.h"
|
||||||
#include "reset.h"
|
#include "reset.h"
|
||||||
#ifdef LIBPAX
|
#if LIBPAX
|
||||||
#include <libpax_api.h>
|
#include <libpax_api.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -141,7 +141,7 @@ 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
|
#if LIBPAX
|
||||||
extern uint16_t volatile libpax_macs_ble, libpax_macs_wifi; // libpax values
|
extern uint16_t volatile libpax_macs_ble, libpax_macs_wifi; // libpax values
|
||||||
#endif
|
#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
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
#include "corona.h"
|
#include "corona.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if (LIBPAX)
|
#if LIBPAX
|
||||||
#include <libpax_api.h>
|
#include <libpax_api.h>
|
||||||
|
|
||||||
extern struct count_payload_t count_from_libpax;
|
extern struct count_payload_t count_from_libpax;
|
||||||
|
@ -89,7 +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
|
https://github.com/dbSuS/libpax#v0.1.1
|
||||||
lib_deps_all =
|
lib_deps_all =
|
||||||
${common.lib_deps_basic}
|
${common.lib_deps_basic}
|
||||||
${common.lib_deps_lora}
|
${common.lib_deps_lora}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#ifndef LIBPAX
|
#if !(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
|
||||||
|
|
||||||
|
@ -136,7 +136,7 @@ uint32_t getFreeRAM() {
|
|||||||
void reset_counters() {
|
void reset_counters() {
|
||||||
|
|
||||||
#if ((WIFICOUNTER) || (BLECOUNTER))
|
#if ((WIFICOUNTER) || (BLECOUNTER))
|
||||||
#ifndef LIBPAX
|
#if !(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;
|
||||||
|
@ -262,7 +262,7 @@ void dp_drawPage(time_t t, bool nextpage) {
|
|||||||
|
|
||||||
#if ((WIFICOUNTER) && (BLECOUNTER))
|
#if ((WIFICOUNTER) && (BLECOUNTER))
|
||||||
if (cfg.wifiscan)
|
if (cfg.wifiscan)
|
||||||
#ifndef LIBPAX
|
#if !(LIBPAX)
|
||||||
dp_printf("WIFI:%-5d", macs_wifi);
|
dp_printf("WIFI:%-5d", macs_wifi);
|
||||||
#else
|
#else
|
||||||
dp_printf("WIFI:%-5d", libpax_macs_wifi);
|
dp_printf("WIFI:%-5d", libpax_macs_wifi);
|
||||||
@ -275,7 +275,7 @@ 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
|
#if !(LIBPAX)
|
||||||
dp_printf("BLTH:%-5d", macs_ble);
|
dp_printf("BLTH:%-5d", macs_ble);
|
||||||
#else
|
#else
|
||||||
dp_printf("BLTH:%-5d", libpax_macs_ble);
|
dp_printf("BLTH:%-5d", libpax_macs_ble);
|
||||||
@ -284,7 +284,7 @@ void dp_drawPage(time_t t, bool nextpage) {
|
|||||||
dp_printf(" BLTH:off");
|
dp_printf(" BLTH:off");
|
||||||
#elif ((WIFICOUNTER) && (!BLECOUNTER))
|
#elif ((WIFICOUNTER) && (!BLECOUNTER))
|
||||||
if (cfg.wifiscan)
|
if (cfg.wifiscan)
|
||||||
#ifndef LIBPAX
|
#if !(LIBPAX)
|
||||||
dp_printf("WIFI:%-5d", macs_wifi);
|
dp_printf("WIFI:%-5d", macs_wifi);
|
||||||
#else
|
#else
|
||||||
dp_printf("WIFI:%-5d", libpax_macs_wifi);
|
dp_printf("WIFI:%-5d", libpax_macs_wifi);
|
||||||
@ -293,7 +293,7 @@ void dp_drawPage(time_t t, bool nextpage) {
|
|||||||
dp_printf("WIFI:off");
|
dp_printf("WIFI:off");
|
||||||
#elif ((!WIFICOUNTER) && (BLECOUNTER))
|
#elif ((!WIFICOUNTER) && (BLECOUNTER))
|
||||||
if (cfg.blescan)
|
if (cfg.blescan)
|
||||||
#ifndef LIBPAX
|
#if !(LIBPAX)
|
||||||
dp_printf("BLTH:%-5d", macs_ble);
|
dp_printf("BLTH:%-5d", macs_ble);
|
||||||
#else
|
#else
|
||||||
dp_printf("BLTH:%-5d", libpax_macs_ble);
|
dp_printf("BLTH:%-5d", libpax_macs_ble);
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#include "libpax_helpers.h"
|
#include "libpax_helpers.h"
|
||||||
|
|
||||||
// libpax payload
|
// libpax payload
|
||||||
#ifdef LIBPAX
|
#if LIBPAX
|
||||||
struct count_payload_t count_from_libpax;
|
struct count_payload_t count_from_libpax;
|
||||||
uint16_t volatile libpax_macs_ble, libpax_macs_wifi;
|
uint16_t volatile libpax_macs_ble, libpax_macs_wifi;
|
||||||
|
|
||||||
|
23
src/main.cpp
23
src/main.cpp
@ -91,11 +91,11 @@ 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
|
#if !(LIBPAX)
|
||||||
uint8_t volatile channel = WIFI_CHANNEL_MIN; // channel rotation counter
|
uint8_t volatile channel = WIFI_CHANNEL_MIN; // channel rotation counter
|
||||||
#endif
|
#endif
|
||||||
uint8_t volatile rf_load = 0; // RF traffic indicator
|
uint8_t volatile rf_load = 0; // RF traffic indicator
|
||||||
#ifndef LIBPAX
|
#if !(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
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -304,18 +304,17 @@ void setup() {
|
|||||||
if (RTC_runmode == RUNMODE_MAINTENANCE)
|
if (RTC_runmode == RUNMODE_MAINTENANCE)
|
||||||
start_boot_menu();
|
start_boot_menu();
|
||||||
|
|
||||||
#ifndef LIBPAX
|
#if !(LIBPAX)
|
||||||
// start mac processing task
|
// start mac processing task
|
||||||
ESP_LOGI(TAG, "Starting MAC processor...");
|
ESP_LOGI(TAG, "Starting MAC processor...");
|
||||||
macQueueInit();
|
macQueueInit();
|
||||||
#else
|
#else
|
||||||
ESP_LOGI(TAG, "Starting libpax...");
|
ESP_LOGI(TAG, "Starting libpax...");
|
||||||
#if (defined WIFICOUNTER || defined BLECOUNTER)
|
#if (defined WIFICOUNTER || defined BLECOUNTER)
|
||||||
struct libpax_config_t configuration;
|
struct libpax_config_t configuration;
|
||||||
libpax_default_config(&configuration);
|
libpax_default_config(&configuration);
|
||||||
ESP_LOGI(TAG, "BLESCAN: %d", cfg.blescan);
|
ESP_LOGI(TAG, "BLESCAN: %d", cfg.blescan);
|
||||||
ESP_LOGI(TAG, "WIFISCAN: %d", cfg.wifiscan);
|
ESP_LOGI(TAG, "WIFISCAN: %d", cfg.wifiscan);
|
||||||
if(!(cfg.blescan && cfg.wifiscan)) {
|
|
||||||
configuration.wificounter = cfg.wifiscan;
|
configuration.wificounter = cfg.wifiscan;
|
||||||
configuration.blecounter = cfg.blescan;
|
configuration.blecounter = cfg.blescan;
|
||||||
|
|
||||||
@ -331,9 +330,6 @@ ESP_LOGI(TAG, "Starting libpax...");
|
|||||||
} else {
|
} else {
|
||||||
init_libpax();
|
init_libpax();
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
ESP_LOGE(TAG, "Error in libpax configuration: Wifi and BLE are not supported at the same time!");
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -345,7 +341,7 @@ ESP_LOGI(TAG, "Starting libpax...");
|
|||||||
// 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 !(LIBPAX)
|
||||||
if (cfg.blescan) {
|
if (cfg.blescan) {
|
||||||
ESP_LOGI(TAG, "Starting Bluetooth...");
|
ESP_LOGI(TAG, "Starting Bluetooth...");
|
||||||
start_BLEscan();
|
start_BLEscan();
|
||||||
@ -354,14 +350,15 @@ ESP_LOGI(TAG, "Starting libpax...");
|
|||||||
#endif
|
#endif
|
||||||
#else
|
#else
|
||||||
// remove bluetooth stack to gain more free memory
|
// remove bluetooth stack to gain more free memory
|
||||||
#ifndef LIBPAX
|
#if !(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
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
// initialize gps
|
// initialize gps
|
||||||
#if (HAS_GPS)
|
#if (HAS_GPS)
|
||||||
strcat_P(features, " GPS");
|
strcat_P(features, " GPS");
|
||||||
@ -466,7 +463,7 @@ ESP_LOGI(TAG, "Starting libpax...");
|
|||||||
|
|
||||||
#if (WIFICOUNTER)
|
#if (WIFICOUNTER)
|
||||||
strcat_P(features, " WIFI");
|
strcat_P(features, " WIFI");
|
||||||
#ifndef LIBPAX
|
#if !(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
|
||||||
@ -485,7 +482,7 @@ ESP_LOGI(TAG, "Starting libpax...");
|
|||||||
// 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
|
#if !(LIBPAX)
|
||||||
reset_counters();
|
reset_counters();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@
|
|||||||
#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
|
// Use libpax instead of default counting algorithms
|
||||||
#define LIBPAX 1
|
#define LIBPAX 0
|
||||||
|
|
||||||
// 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
|
||||||
|
@ -97,7 +97,7 @@ void set_wifichancycle(uint8_t val[]) {
|
|||||||
|
|
||||||
void set_blescantime(uint8_t val[]) {
|
void set_blescantime(uint8_t val[]) {
|
||||||
cfg.blescantime = val[0];
|
cfg.blescantime = val[0];
|
||||||
#ifndef LIBPAX
|
#if !(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
|
||||||
@ -250,24 +250,19 @@ 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");
|
||||||
cfg.blescan = val[0] ? 1 : 0;
|
cfg.blescan = val[0] ? 1 : 0;
|
||||||
#ifndef LIBPAX
|
#if !(LIBPAX)
|
||||||
macs_ble = 0; // clear BLE counter
|
macs_ble = 0; // clear BLE counter
|
||||||
if (cfg.blescan)
|
if (cfg.blescan)
|
||||||
start_BLEscan();
|
start_BLEscan();
|
||||||
else
|
else
|
||||||
stop_BLEscan();
|
stop_BLEscan();
|
||||||
#else
|
#else
|
||||||
if(cfg.blescan) {
|
libpax_counter_stop();
|
||||||
cfg.wifiscan = 0;
|
libpax_config_t current_config;
|
||||||
// Restart of libpax while switching scannings does not work atm
|
libpax_get_current_config(¤t_config);
|
||||||
// libpax_counter_stop();
|
current_config.blecounter = cfg.blescan;
|
||||||
// libpax_config_t current_config;
|
libpax_update_config(¤t_config);
|
||||||
// libpax_get_current_config(¤t_config);
|
init_libpax();
|
||||||
// current_config.wificounter = 0;
|
|
||||||
// current_config.blecounter = 1;
|
|
||||||
// libpax_update_config(¤t_config);
|
|
||||||
// init_libpax();
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -275,21 +270,16 @@ 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");
|
||||||
cfg.wifiscan = val[0] ? 1 : 0;
|
cfg.wifiscan = val[0] ? 1 : 0;
|
||||||
#ifndef LIBPAX
|
#if !(LIBPAX)
|
||||||
macs_wifi = 0; // clear WIFI counter
|
macs_wifi = 0; // clear WIFI counter
|
||||||
switch_wifi_sniffer(cfg.wifiscan);
|
switch_wifi_sniffer(cfg.wifiscan);
|
||||||
#else
|
#else
|
||||||
if(cfg.wifiscan) {
|
libpax_counter_stop();
|
||||||
cfg.blescan = 0;
|
libpax_config_t current_config;
|
||||||
// Restart of libpax while switching scannings does not work atm
|
libpax_get_current_config(¤t_config);
|
||||||
// libpax_counter_stop();
|
current_config.wificounter = cfg.wifiscan;
|
||||||
// libpax_config_t current_config;
|
libpax_update_config(¤t_config);
|
||||||
// libpax_get_current_config(¤t_config);
|
init_libpax();
|
||||||
// current_config.wificounter = 1;
|
|
||||||
// current_config.blecounter = 0;
|
|
||||||
// libpax_update_config(¤t_config);
|
|
||||||
// init_libpax();
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -107,7 +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 !(LIBPAX)
|
||||||
#if (WIFICOUNTER)
|
#if (WIFICOUNTER)
|
||||||
switch_wifi_sniffer(0);
|
switch_wifi_sniffer(0);
|
||||||
#endif
|
#endif
|
||||||
|
@ -57,7 +57,7 @@ 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
|
#if !(LIBPAX)
|
||||||
sdcardWriteData(macs_wifi, macs_ble
|
sdcardWriteData(macs_wifi, macs_ble
|
||||||
#else
|
#else
|
||||||
sdcardWriteData(libpax_macs_wifi, libpax_macs_ble
|
sdcardWriteData(libpax_macs_wifi, libpax_macs_ble
|
||||||
@ -91,14 +91,14 @@ void sendData() {
|
|||||||
case COUNT_DATA:
|
case COUNT_DATA:
|
||||||
payload.reset();
|
payload.reset();
|
||||||
#if !(PAYLOAD_OPENSENSEBOX)
|
#if !(PAYLOAD_OPENSENSEBOX)
|
||||||
#ifndef LIBPAX
|
#if !(LIBPAX)
|
||||||
payload.addCount(macs_wifi, MAC_SNIFF_WIFI);
|
payload.addCount(macs_wifi, MAC_SNIFF_WIFI);
|
||||||
#else
|
#else
|
||||||
ESP_LOGI(TAG, "Sending libpax wifi count: %d", libpax_macs_wifi);
|
ESP_LOGI(TAG, "Sending libpax wifi count: %d", libpax_macs_wifi);
|
||||||
payload.addCount(libpax_macs_wifi, MAC_SNIFF_WIFI);
|
payload.addCount(libpax_macs_wifi, MAC_SNIFF_WIFI);
|
||||||
#endif
|
#endif
|
||||||
if (cfg.blescan) {
|
if (cfg.blescan) {
|
||||||
#ifndef LIBPAX
|
#if !(LIBPAX)
|
||||||
payload.addCount(macs_ble, MAC_SNIFF_BLE);
|
payload.addCount(macs_ble, MAC_SNIFF_BLE);
|
||||||
#else
|
#else
|
||||||
ESP_LOGI(TAG, "Sending libpax ble count: %d", libpax_macs_ble);
|
ESP_LOGI(TAG, "Sending libpax ble count: %d", libpax_macs_ble);
|
||||||
@ -117,14 +117,14 @@ void sendData() {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#if (PAYLOAD_OPENSENSEBOX)
|
#if (PAYLOAD_OPENSENSEBOX)
|
||||||
#ifndef LIBPAX
|
#if !(LIBPAX)
|
||||||
payload.addCount(macs_wifi, MAC_SNIFF_WIFI);
|
payload.addCount(macs_wifi, MAC_SNIFF_WIFI);
|
||||||
#else
|
#else
|
||||||
ESP_LOGI(TAG, "Sending libpax wifi count: %d", libpax_macs_wifi);
|
ESP_LOGI(TAG, "Sending libpax wifi count: %d", libpax_macs_wifi);
|
||||||
payload.addCount(libpax_macs_wifi, MAC_SNIFF_WIFI);
|
payload.addCount(libpax_macs_wifi, MAC_SNIFF_WIFI);
|
||||||
#endif
|
#endif
|
||||||
if (cfg.blescan) {
|
if (cfg.blescan) {
|
||||||
#ifndef LIBPAX
|
#if !(LIBPAX)
|
||||||
payload.addCount(macs_ble, MAC_SNIFF_BLE);
|
payload.addCount(macs_ble, MAC_SNIFF_BLE);
|
||||||
#else
|
#else
|
||||||
ESP_LOGI(TAG, "Sending libpax ble count: %d", libpax_macs_ble);
|
ESP_LOGI(TAG, "Sending libpax ble count: %d", libpax_macs_ble);
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#ifndef LIBPAX
|
#if !(LIBPAX)
|
||||||
// Basic Config
|
// Basic Config
|
||||||
#include "globals.h"
|
#include "globals.h"
|
||||||
#include "wifiscan.h"
|
#include "wifiscan.h"
|
||||||
|
Loading…
Reference in New Issue
Block a user