Skip to content

Commit

Permalink
fix issue dbinfrago#19
Browse files Browse the repository at this point in the history
  • Loading branch information
cyberman54 committed Oct 19, 2022
1 parent ba8d899 commit 5d57c69
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 24 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [1.0.2] - 2022-10-19
- Adapt Wifi country settings to ESP IDF v4.4 Wi-Fi API

## [1.0.1] - 2022-04-14
- Count randomized MACs only (Wifi and BLE)
- fix use LSB format to interprete BLE MACS
Expand Down
4 changes: 2 additions & 2 deletions lib/libpax/libpax_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ void libpax_default_config(struct libpax_config_t* configuration) {
memset(configuration, 0, sizeof(struct libpax_config_t));
configuration->blecounter = 0;
configuration->wificounter = 1;
configuration->wifi_my_country = 1;
strcpy(configuration->wifi_my_country, "01");
configuration->wifi_channel_map = 0b100010100100100;
configuration->wifi_channel_switch_interval = 50;
configuration->wifi_rssi_threshold = 0;
Expand Down Expand Up @@ -173,10 +173,10 @@ int libpax_counter_start() {
return -1;
}
if (current_config.wificounter) {
wifi_sniffer_init(current_config.wifi_channel_switch_interval);
set_wifi_country(current_config.wifi_my_country);
set_wifi_channels(current_config.wifi_channel_map);
set_wifi_rssi_filter(current_config.wifi_rssi_threshold);
wifi_sniffer_init(current_config.wifi_channel_switch_interval);
}
if (current_config.wificounter && current_config.blecounter) {
esp_wifi_set_ps(WIFI_PS_MIN_MODEM);
Expand Down
2 changes: 1 addition & 1 deletion lib/libpax/libpax_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ struct libpax_config_t {
// <- 13 ..........1 ->
// 0b1010000001001 would be Channel: 1, 4, 11, 13
uint8_t wificounter; // set to 0 if you do not want to install the WiFi sniffer
uint8_t wifi_my_country; // e.g 0 = "EU", etc. select locale for WiFi RF settings
char wifi_my_country[3]; // set country code for WiFi RF settings, e.g. "01", "DE", etc.
uint16_t wifi_channel_switch_interval; // [seconds/100] -> 0,5 sec.
int wifi_rssi_threshold; // Filter for how strong the wifi signal should be to be counted
int ble_rssi_threshold; // Filter for how strong the bluetooth signal should be to be counted
Expand Down
25 changes: 7 additions & 18 deletions lib/libpax/wifiscan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,7 @@ TimerHandle_t WifiChanTimer;
int initialized_wifi = 0;
int wifi_rssi_threshold = 0;
uint16_t channels_map = WIFI_CHANNEL_ALL;

#define WIFI_CHANNEL_MAX 13
// default values for country configuration
static wifi_country_t wifi_country = {"EU", 1,
WIFI_CHANNEL_MAX, 100,
WIFI_COUNTRY_POLICY_MANUAL};
static wifi_country_t country;

void wifi_noop_sniffer(void* buff, wifi_promiscuous_pkt_type_t type) {}

Expand All @@ -66,17 +61,16 @@ wifi_sniffer_packet_handler(void* buff, wifi_promiscuous_pkt_type_t type) {
void switchWifiChannel(TimerHandle_t xTimer) {
configASSERT(xTimer);
do { channel =
(channel % WIFI_CHANNEL_MAX) + 1; // rotate channels in bitmap
(channel % country.nchan) + 1; // rotate channels in bitmap
} while (!(channels_map >> (channel - 1) & 1));
esp_wifi_set_channel(channel, WIFI_SECOND_CHAN_NONE);
}

void set_wifi_country(uint8_t cc) {
switch(cc) {
case 1:
memcpy(wifi_country.cc, "EU", sizeof("EU"));
break;
}
void set_wifi_country(const char* country_code) {
ESP_ERROR_CHECK(
esp_wifi_set_country_code(country_code, true));
ESP_ERROR_CHECK(
esp_wifi_get_country(&country));
}

void set_wifi_channels(uint16_t set_channels_map) {
Expand All @@ -102,15 +96,12 @@ void wifi_sniffer_init(uint16_t wifi_channel_switch_interval) {
WIFI_PROMIS_FILTER_MASK_DATA};

ESP_ERROR_CHECK(esp_wifi_init(&wificfg)); // configure Wifi with cfg
ESP_ERROR_CHECK(
esp_wifi_set_country(&wifi_country)); // set locales for RF and channels
ESP_ERROR_CHECK(
esp_wifi_set_storage(WIFI_STORAGE_RAM)); // we don't need NVRAM
ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_NULL));
ESP_ERROR_CHECK(
esp_wifi_set_promiscuous_filter(&filter)); // set frame filter
ESP_ERROR_CHECK(esp_wifi_set_promiscuous_rx_cb(&wifi_sniffer_packet_handler));
ESP_ERROR_CHECK(esp_wifi_start()); // for esp_wifi v3.3
ESP_ERROR_CHECK(
esp_wifi_set_promiscuous(true)); // now switch on monitor mode

Expand All @@ -121,7 +112,6 @@ void wifi_sniffer_init(uint16_t wifi_channel_switch_interval) {
assert(WifiChanTimer);
xTimerStart(WifiChanTimer, 0);
}
ESP_ERROR_CHECK(esp_wifi_start());
esp_wifi_set_promiscuous(true);
initialized_wifi = 1;
#endif
Expand All @@ -134,7 +124,6 @@ void wifi_sniffer_stop() {
ESP_ERROR_CHECK(esp_wifi_set_promiscuous_rx_cb(&wifi_noop_sniffer));
ESP_ERROR_CHECK(
esp_wifi_set_promiscuous(false)); // now switch off monitor mode
ESP_ERROR_CHECK(esp_wifi_stop());
esp_wifi_deinit();
ESP_ERROR_CHECK(esp_coex_preference_set(ESP_COEX_PREFER_BT));
initialized_wifi = 0;
Expand Down
2 changes: 1 addition & 1 deletion lib/libpax/wifiscan.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ typedef struct {
uint8_t payload[0]; // network data ended with 4 bytes csum (CRC32)
} wifi_ieee80211_packet_t;

void set_wifi_country(uint8_t country_code);
void set_wifi_country(const char* country_code);
void set_wifi_channels(uint16_t channels_map);
void set_wifi_rssi_filter(int set_rssi_threshold);

Expand Down
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "libpax",
"version":"1.0.1",
"version":"1.0.2",
"keywords": "libpax",
"description": "Library for PAX counting using BLE and WiFi",
"repository":
Expand Down
2 changes: 1 addition & 1 deletion platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ default_envs = espidf
[env]
board = ttgo-t-beam
monitor_speed = 115200
platform = espressif32@3.5.0
platform = espressif32@5.2.0

[env:espidf]
framework = espidf
Expand Down

0 comments on commit 5d57c69

Please sign in to comment.