Skip to content
Snippets Groups Projects
Commit 77a15ea6 authored by Marek Ištok's avatar Marek Ištok :speech_balloon:
Browse files

feature: add ping counting and name filtering

Related to digital-twin/twinzo/initiatives#4

Added counting of ping from unique & duplicate devices, this was we can
estimate how many of their pings are being captured per second.
Also added name filtering for our beacons, with the name "INFOTECH".
parent c9be64a7
No related branches found
No related tags found
No related merge requests found
Pipeline #764 failed
......@@ -15,12 +15,15 @@
#include <string>
#include <unordered_set>
#include <algorithm>
#define LOG_LOCAL_LEVEL ESP_LOG_DEBUG
static const char* TAG = "main";
std::unordered_set<std::string> devices;
uint8_t unique_pings = 0;
uint16_t total_pings = 0;
static esp_ble_scan_params_t ble_scan_params = {
.scan_type = BLE_SCAN_TYPE_ACTIVE,
......@@ -93,6 +96,8 @@ void app_main(void) {
ESP_LOGE(TAG, "set scan params error, error code = %x", ret);
}
unique_pings = 0;
total_pings = 0;
devices.clear();
// Set scan duration to 30s, we can control it with the delay below
esp_ble_gap_start_scanning(30);
......@@ -100,7 +105,10 @@ void app_main(void) {
vTaskDelay(pdMS_TO_TICKS(2000));
ESP_ERROR_CHECK(esp_ble_gap_stop_scanning());
vTaskDelay(1);
ESP_LOGI(TAG, "[%s]: Unique devices captured: %u", __func__, unique_pings);
ESP_LOGI(TAG, "[%s]: Total pings captured: %u", __func__, total_pings);
vTaskDelay(2);
ESP_LOGI(TAG, "[%s]: Slep", __func__);
esp_light_sleep_start();
ESP_LOGI(TAG, "[%s]: Wakey", __func__);
......@@ -133,17 +141,26 @@ static void esp_gap_cb(
snprintf(mac, 18, "%.2x %.2x %.2x %.2x %.2x %.2x",
addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]);
if (devices.find(mac) == devices.end()) {
devices.insert(mac);
adv_name = esp_ble_resolve_adv_data(
scan_result->scan_rst.ble_adv,
ESP_BLE_AD_TYPE_NAME_CMPL,
&adv_name_len
);
ESP_LOGI(TAG, "%s (%ddBm, %.*s)",
mac, scan_result->scan_rst.rssi, adv_name_len, adv_name);
} else {
adv_name = esp_ble_resolve_adv_data(
scan_result->scan_rst.ble_adv,
ESP_BLE_AD_TYPE_NAME_CMPL,
&adv_name_len
);
if (adv_name_len > 0 && strncmp(
(char*) adv_name, "INFOTECH", std::min(adv_name_len, (uint8_t) 8)
) == 0
) {
if (devices.find(mac) == devices.end()) {
devices.insert(mac);
unique_pings += 1;
ESP_LOGI(TAG, "%s (%ddBm, %.*s)",
mac, scan_result->scan_rst.rssi, adv_name_len, adv_name);
}
// Also count duplicates here
total_pings += 1;
ESP_LOGD(TAG, "%s", mac);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment