完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
我在使用ESP32-C3尝试获取CSI信息的时候,CSI的回调函数往往只能被执行一次或着一次都不会被执行(像是没收到CSI?)。
我使用的开发板是ESP32-C3和ESP32-WROOM模组,idf是4.4版本,代码是基于idf中exampleswifigetting_startedstation例程改写的,具体方式是在WIFI_EVENT_STA_START事件后依次调用esp_wifi_set_csi(1)、esp_wifi_set_csi_config(&configuration_csi)、esp_wifi_set_csi_rx_cb(&_wifi_csi_cb, NULL)。但似乎最终并没有正确收到CSI。 我参考了https://stevenmhernandez.github.io/ESP32-CSI-Tool/的代码,但直接编译该tool-kit代码现象也是没有收到CSI。 CSI的功能具体需要怎么使用呢?在idf文档里也没有找到相关资料。 我的代码如下,除了用注释和*标出来的以外,都是station例程里的内容(因为具体是哪里的问题也不知道只能全放上来了): Code: Select all #define EXAMPLE_ESP_MAXIMUM_RETRY CONFIG_ESP_MAXIMUM_RETRY/* FreeRTOS event group to signal when we are connected*/static EventGroupHandle_t s_wifi_event_group;/* The event group allows multiple bits for each event, but we only care about two events: * - we are connected to the AP with an IP * - we failed to connect after the maximum amount of retries */#define WIFI_CONNECTED_BIT BIT0#define WIFI_FAIL_BIT BIT1static const char *TAG = "wifi station";static int s_retry_num = 0;void csi_init(void);static void event_handler(void* arg, esp_event_base_t event_base, int32_t event_id, void* event_data){ if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_START) { csi_init();//*********************************************************************************** esp_wifi_connect(); } else if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_DISCONNECTED) { if (s_retry_num < EXAMPLE_ESP_MAXIMUM_RETRY) { esp_wifi_connect(); s_retry_num++; ESP_LOGI(TAG, "retry to connect to the AP"); } else { xEventGroupSetBits(s_wifi_event_group, WIFI_FAIL_BIT); } ESP_LOGI(TAG,"connect to the AP fail"); } else if (event_base == IP_EVENT && event_id == IP_EVENT_STA_GOT_IP) { ip_event_got_ip_t* event = (ip_event_got_ip_t*) event_data; ESP_LOGI(TAG, "got ip:" IPSTR, IP2STR(&event->ip_info.ip)); s_retry_num = 0; xEventGroupSetBits(s_wifi_event_group, WIFI_CONNECTED_BIT); }}//***********************************************************************************void _wifi_csi_cb(void *ctx, wifi_csi_info_t *data) { 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]); printf("CSI_DATA,"); printf("%s,", mac); // https://github.com/espressif/esp-idf/blob/9d0ca60398481a44861542638cfdc1949bb6f312/components/esp_wifi/include/esp_wifi_types.h#L314 printf("%d,", d.rx_ctrl.rssi); 。。。 printf("n"); vTaskDelay(0);}void _print_csi_csv_header() { char *header_str = "type,role,mac,rssi,rate,sig_mode,mcs,bandwidth,smoothing,not_sounding,aggregation,stbc,fec_coding,sgi,noise_floor,ampdu_cnt,channel,secondary_channel,local_timestamp,ant,sig_len,rx_state,real_time_set,real_timestamp,len,CSI_DATAn"; printf(header_str);}void csi_init() { ESP_ERROR_CHECK(esp_wifi_set_csi(1)); // @See: https://github.com/espressif/esp-idf/blob/master/components/esp_wifi/include/esp_wifi_types.h#L401 wifi_csi_config_t configuration_csi; configuration_csi.lltf_en = 1; configuration_csi.htltf_en = 1; configuration_csi.stbc_htltf2_en = 1; configuration_csi.ltf_merge_en = 1; configuration_csi.channel_filter_en = 1; 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)); _print_csi_csv_header();}//***********************************************************************************void wifi_init_sta(void){ s_wifi_event_group = xEventGroupCreate(); ESP_ERROR_CHECK(esp_netif_init()); ESP_ERROR_CHECK(esp_event_loop_create_default()); esp_netif_create_default_wifi_sta(); wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT(); cfg.csi_enable = 1;//*********************************************************************************** ESP_ERROR_CHECK(esp_wifi_init(&cfg)); esp_wifi_set_ps(WIFI_PS_NONE); esp_event_handler_instance_t instance_any_id; esp_event_handler_instance_t instance_got_ip; ESP_ERROR_CHECK(esp_event_handler_instance_register(WIFI_EVENT, ESP_EVENT_ANY_ID, &event_handler, NULL, &instance_any_id)); ESP_ERROR_CHECK(esp_event_handler_instance_register(IP_EVENT, IP_EVENT_STA_GOT_IP, &event_handler, NULL, &instance_got_ip)); wifi_config_t wifi_config = { .sta = { .ssid = EXAMPLE_ESP_WIFI_SSID, .password = EXAMPLE_ESP_WIFI_PASS, .channel = 8,//*********************************************************************************** /* Setting a password implies station will connect to all security modes including WEP/WPA. * However these modes are deprecated and not advisable to be used. Incase your Access point * doesn't support WPA2, these mode can be enabled by commenting below line */ }, }; ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA) ); ESP_ERROR_CHECK(esp_wifi_set_config(WIFI_IF_STA, &wifi_config) ); ESP_ERROR_CHECK(esp_wifi_start() ); ESP_LOGI(TAG, "wifi_init_sta finished."); /* Waiting until either the connection is established (WIFI_CONNECTED_BIT) or connection failed for the maximum * number of re-tries (WIFI_FAIL_BIT). The bits are set by event_handler() (see above) */ EventBits_t bits = xEventGroupWaitBits(s_wifi_event_group, WIFI_CONNECTED_BIT | WIFI_FAIL_BIT, pdFALSE, pdFALSE, portMAX_DELAY); /* xEventGroupWaitBits() returns the bits before the call returned, hence we can test which event actually * happened. */ if (bits & WIFI_CONNECTED_BIT) { ESP_LOGI(TAG, "connected to ap SSID:%s password:%s", EXAMPLE_ESP_WIFI_SSID, EXAMPLE_ESP_WIFI_PASS); } else if (bits & WIFI_FAIL_BIT) { ESP_LOGI(TAG, "Failed to connect to SSID:%s, password:%s", EXAMPLE_ESP_WIFI_SSID, EXAMPLE_ESP_WIFI_PASS); } else { ESP_LOGE(TAG, "UNEXPECTED EVENT"); } /* The event will not be processed after unregister */ ESP_ERROR_CHECK(esp_event_handler_instance_unregister(IP_EVENT, IP_EVENT_STA_GOT_IP, instance_got_ip)); ESP_ERROR_CHECK(esp_event_handler_instance_unregister(WIFI_EVENT, ESP_EVENT_ANY_ID, instance_any_id)); vEventGroupDelete(s_wifi_event_group);}void app_main(void){ //Initialize NVS esp_err_t ret = nvs_flash_init(); if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) { ESP_ERROR_CHECK(nvs_flash_erase()); ret = nvs_flash_init(); } ESP_ERROR_CHECK(ret); ESP_LOGI(TAG, "ESP_WIFI_MODE_STA"); wifi_init_sta();} 日志如下,在619行的时候收到了一条CSI,后续就没反应了,最后显示连接到路由器后一直没有其他输出了。Code: Select all I (439) wifi_init: tcp mbox: 6I (439) wifi_init: tcp tx win: 5744I (449) wifi_init: tcp rx win: 5744I (449) wifi_init: tcp mss: 1440I (449) wifi_init: WiFi IRAM OP enabledI (459) wifi_init: WiFi RX IRAM OP enabledI (459) wifi:Set ps type: 0I (469) phy_init: phy_version 500,985899c,Apr 19 2021,16:05:08I (579) wifi:set rx active PTI: 0, rx ack PTI: 0, and default PTI: 0I (589) wifi:mode : sta (7c:df:a1:66:d4:50)I (589) wifi:enable tsftype,role,mac,rssi,rate,sig_mode,mcs,bandwidth,smoothing,not_sounding,aggregation,stbc,fec_coding,sgi,noise_floor,ampdu_cnt,channel,secondary_channel,local_timestamp,ant,sig_len,rx_state,real_time_set,real_timestamp,len,CSI_DATAI (609) wifi station: wifi_init_sta finished.I (609) wifi:new:<1,1>, old:<1,0>, ap:<255,255>, sta:<1,1>, prof:1I (619) wifi:state: init -> auth (b0)CSI_DATA,0E:96:E6:79:97:B1,-74,11,0,0,0,0,0,0,0,0,0,-96,0,1,1,611964,0,419,0,I(629) wifi:state: auth -> assoc (0)I (639) wifi:state: assoc -> run (10)I (649) wifi:connected with TP-LINK_235, aid = 2, channel 1, 40U, bssid = 34:96:72:38:fb:70I (649) wifi:security: WPA2-PSK, phy: bgn, rssi: -49I (649) wifi:pm start, type: 0I (659) wifi:set rx beacon pti, rx_bcn_pti: 0, bcn_timeout: 0, mt_pti: 25000, mt_time: 10000W (669) wifi:idx:0 (ifx:0, 34:96:72:38:fb:70), tid:0, ssn:0, winSize:64I (699) wifi:BcnInt:102400, DTIM:1I (1349) esp_netif_handlers: sta ip: 192.168.2.102, mask: 255.255.255.0, gw: 192.168.2.1I (1349) wifi station: got ip:192.168.2.102I (1349) wifi station: connected to ap SSID:*** password:*** |
|
相关推荐
1个回答
|
|
以下是一些建议和可能的原因:
1. **检查ESP-IDF版本**:确保您使用的ESP-IDF版本支持ESP32-C3。您提到使用的是4.4版本,建议您查看ESP-IDF的文档以确认是否支持ESP32-C3。 2. **检查示例代码**:确保您使用的示例代码是针对ESP32-C3的,而不是针对其他型号的ESP32。有时候,示例代码可能不完全适用于不同的硬件。 3. **检查CSI配置**:确保您的CSI配置是正确的。检查`configuration_csi`结构体中的参数设置,确保它们与您的硬件和需求相匹配。 4. **检查回调函数**:确保您的回调函数`_wifi_csi_cb`是正确的,并且没有错误。检查函数内部的逻辑,确保它能够正确处理接收到的CSI数据。 5. **检查硬件连接**:确保您的ESP32-C3和ESP32-WROOM模块之间的硬件连接是正确的。错误的连接可能导致信号传输问题,从而影响CSI的接收。 6. **检查信号质量**:CSI的接收可能受到信号质量的影响。确保您的设备处于良好的信号环境中,以便更好地接收CSI数据。 7. **检查ESP-IDF日志**:在您的代码中添加日志输出,以便在调试过程中查看ESP-IDF的运行情况。这可以帮助您找到问题所在。 |
|
|
|
只有小组成员才能发言,加入小组>>
598 浏览 1 评论
552浏览 6评论
461浏览 5评论
有没有办法在不使用混杂模式的情况下实现Wifi驱动程序接收缓冲区访问中断呢?
443浏览 5评论
445浏览 4评论
415浏览 4评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-23 23:32 , Processed in 0.890840 second(s), Total 81, Slave 64 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号