问题
I am trying to build a esp32 application, where I have bluetooth and wifi enabled at the same time.
Bluetooth is used with the a2dp profile, where the esp is a sink. After receiving the data, it should be published over a UDP socket as a broadcast to the network.
The problem is the antenna. Both bt and wifi are sharing it. The a2dp stream seems to permanently acquiring the antenna and releasing it very rarely (~2 packages/min, I have ~3000 packages/min).
So my question: Is there some kind of semaphore, which can be acquired to have the full control over the antenna? So my socket would be able to send the data to the network?
I am using my esp32 with freeRTOS. The freeRTOS lib is written in C, but I am trying to wrap everything in C++. Still I think this problem is related to a C lib so I tag it with C.
I am open for any suggestions how to build that. Thanks in advance.
UPDATE:
I am using release/v3.3
from the official esp-idf
repo.
I have: CONFIG_SW_COEXIST_ENABLE=y
and CONFIG_SW_COEXIST_PREFERENCE_WIFI=y
I can't find CONFIG_ESP32_WIFI_SW_COEXIST_ENABLE
in my config.
The mentioned configuration doesn't work.
I tried reading the post, but can't find any "scan_window
" or "scan_interval
" in my lib. It was written that it is somewhere in the gap_api
but can't find it.
Here is my code + config: https://github.com/Dimfred/esp32_bt_streamer
The socket client task, which should broadcast the a2dp_msg
, is started here:
https://github.com/Dimfred/esp32_bt_streamer/blob/master/main/app/event_handler.cpp#L22
All events popped from station/access point/bluetooth/a2dp are all caught in event_handler.hpp/cpp
回答1:
As you saw, Bluetooth has higher priority on WIFI.
Have a look at CONFIG_SW_COEXIST_ENABLE and make sure it is enabled. You also need to configure CONFIG_SW_COEXIST_PREFERENCE to WIFI. Please see the page for additional flags that you could update depending on your application.
If you want to leave the hardware responsible for handling the co-existing devices (BL and WIFI), you can disable CONFIG_SW_COEXIST_ENABLE
and reduce the scan window and increase the scan interval of the BL to leave time for WIFI to get access to the antenna. See this post for more details.
To answer your original question about a possible semaphore/mutex. I doubt there is one accessible for you to use and I would leave the API (software) handling the co-existing modules accessing the antenna. But you can always checkout what the code is doing once CONFIG_SW_COEXIST_ENABLE
is set (the flag is renamed to CONFIG_ESP32_WIFI_SW_COEXIST_ENABLE
). See https://github.com/espressif/esp-idf/blob/81ca1c01395f604972fbf141cfbe49764a746023/components/esp_wifi/src/phy_init.c
来源:https://stackoverflow.com/questions/55865909/acquire-a-semaphore-for-the-esp32-antenna-bluetooth-wifi-dualmode