← Back to ratslair.com
aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--EZWIFI.c70
-rw-r--r--include/EZWIFI.h6
2 files changed, 46 insertions, 30 deletions
diff --git a/EZWIFI.c b/EZWIFI.c
index 9b84f2c..e4f2b13 100644
--- a/EZWIFI.c
+++ b/EZWIFI.c
@@ -1,38 +1,48 @@
#include "EZWIFI.h"
-/* void _wifi_csi_cb(void *ctx, wifi_csi_info_t *data) { */
-/* xSemaphoreTake(mutex, portMAX_DELAY); */
-/* std::stringstream ss; */
+pthread_mutex_t csi_mutex;
-/* wifi_csi_info_t d = data[0]; */
-/* char mac[20] = {0}; */
-/* sprintf(mac, "%02X:%02X:%02X:%02X:%02X:%02X", d.mac[0], d.mac[1], d.mac[2], d.mac[3], d.mac[4], d.mac[5]); */
+bool is_wifi_connected() {
+ return (xEventGroupGetBits(s_wifi_event_group) & BIT0);
+}
+
+void _wifi_csi_cb(void *ctx, wifi_csi_info_t *data) {
+ //pthread_mutex_lock(&csi_mutex);
-/* int data_len = data->len; */
+ wifi_csi_info_t d = data[0];
+ char mac[20] = {0};
+ sprintf(mac,"%02X:%02X:%02X:%02X:%02X:%02X", d.mac[0], d.mac[1], d.mac[2], d.mac[3], d.mac[4], d.mac[5]);
-/* int8_t *my_ptr; */
+ int data_len = data->len;
-/* my_ptr = data->buf; */
-/* for (int i = 0; i < data_len; i++) { */
-/* //ss << (int) my_ptr[i] << " "; */
-/* } */
+ int8_t *my_ptr;
-/* my_ptr = data->buf; */
-/* for (int i = 0; i < data_len / 2; i++) { */
-/* //ss << (int) sqrt(pow(my_ptr[i * 2], 2) + pow(my_ptr[(i * 2) + 1], 2)) << " "; */
-/* } */
+ if(strcmp(mac, "F0:24:F9:54:3B:88") == 0) {
+ my_ptr = data->buf;
+ printf("CSI DATA: [");
+ for (int i = 0; i < data_len / 2; i++) {
+ printf("(%d, %d)", my_ptr[i * 2], my_ptr[(i * 2) + 1]);
+ if(i < (data_len / 2) - 1) {
+ printf(", ");
+ }
+ // ESP_LOGI("CSI Data:", "%d:%d + i(%d)", i/2, my_ptr[i], my_ptr[i + 1]);
+ }
+ printf("]\n");
+ }
+ /* my_ptr = data->buf; */
+ /* for (int i = 0; i < data_len / 2; i++) { */
+ /* //ss << (int) sqrt(pow(my_ptr[i * 2], 2) + pow(my_ptr[(i * 2) + 1], 2)) << " "; */
+ /* } */
-/* my_ptr = data->buf; */
-/* for (int i = 0; i < data_len / 2; i++) { */
-/* //ss << (int) atan2(my_ptr[i*2], my_ptr[(i*2)+1]) << " "; */
-/* } */
-/* ss << "]\n"; */
-
-/* printf(ss.str().c_str()); */
-/* fflush(stdout); */
-/* vTaskDelay(0); */
-/* xSemaphoreGive(mutex); */
-/* } */
+ /* my_ptr = data->buf; */
+ /* for (int i = 0; i < data_len / 2; i++) { */
+ /* //ss << (int) atan2(my_ptr[i*2], my_ptr[(i*2)+1]) << " "; */
+ /* } */
+
+ //printf(ss.str().c_str());
+ //fflush(stdout);
+ //pthread_mutex_unlock(&csi_mutex);
+}
void wifi_event_handler(void* arg, esp_event_base_t event_base, int32_t event_id, void* event_data)
{
@@ -102,6 +112,8 @@ void setup_station(void)
void setup_softap(void)
{
+ pthread_mutex_init(&csi_mutex, NULL);
+
s_wifi_event_group = xEventGroupCreate();
ESP_ERROR_CHECK(nvs_flash_init());
@@ -138,6 +150,8 @@ void setup_softap(void)
ESP_ERROR_CHECK(esp_wifi_set_config(WIFI_IF_AP, &wifi_config));
ESP_ERROR_CHECK(esp_wifi_start());
+ // ESP_ERROR_CHECK(esp_wifi_set_bandwidth(WIFI_IF_STA, WIFI_BW40));
+
ESP_LOGI(TAG, "softap setup finished. SSID:%s password:%s", SSID, PASS);
}
@@ -216,7 +230,7 @@ void setup_csi(void) {
configuration_csi.manu_scale = 0;
ESP_ERROR_CHECK(esp_wifi_set_csi_config(&configuration_csi));
- //ESP_ERROR_CHECK(esp_wifi_set_csi_rx_cb(&_wifi_csi_cb, NULL));
+ ESP_ERROR_CHECK(esp_wifi_set_csi_rx_cb(&_wifi_csi_cb, NULL));
//_print_csi_csv_header();
diff --git a/include/EZWIFI.h b/include/EZWIFI.h
index e2ccf9d..b744de6 100644
--- a/include/EZWIFI.h
+++ b/include/EZWIFI.h
@@ -5,6 +5,8 @@
#include "esp_log.h"
#include "esp_mesh.h"
#include "nvs_flash.h"
+#include <pthread.h>
+#include <stdio.h>
#define SSID "CDIO"
#define PASS "CDIO_PASS"
@@ -31,9 +33,9 @@ static esp_netif_t *netif_sta = NULL;
static EventGroupHandle_t s_wifi_event_group;
-// void _print_csi_csv_header();
+bool is_wifi_connected();
-// void _wifi_csi_cb(void *ctx, wifi_csi_info_t *data);
+void _wifi_csi_cb(void *ctx, wifi_csi_info_t *data);
void wifi_event_handler(void* arg, esp_event_base_t event_base, int32_t event_id, void* event_data);