nkolban / esp32-snippets

Sample ESP32 snippets and code fragments
https://leanpub.com/kolban-ESP32
Apache License 2.0
2.34k stars 712 forks source link

BLE Gateway - Impossible to use WiFi and BLE at the same time #502

Open TheBrunez opened 6 years ago

TheBrunez commented 6 years ago

Hi, as in the title I'm trying to create a BLE gateway. The problem is that if I am already connected to the WiFi the BLE part doesn't work.

Here is the main code, see also my FlowerCare library if necessary.

The following is the terminal output I'm able to obtain:

ets Jun  8 2016 00:22:57

rst:0x10 (RTCWDT_RTC_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0018,len:4
load:0x3fff001c,len:812
load:0x40078000,len:0
load:0x40078000,len:11404
entry 0x40078a28
Create flora 1
Create flora 2
Create flora 3
Connecting to FASTWEB-Brunelli
..Connected!
Setup done!
Get data flora 1
E (35770) BT: btc_gattc_call_handler()
chegewara commented 6 years ago

From provided logs if i being you i would try to see whats going on in this line: FC_1->getData();
because there is no print in this line: DEBUGLN(FC_1->dataStr());

I have few application where ble + wifi works great, but its different kind of app.

TheBrunez commented 6 years ago

After some testing I located the "error". The program blocks inside FC_1->getData(), at the call to _BLEClient->connect(*_addr) inside FlowerCare_BLE.cpp. Going deeper I found that it blocks inside BLEClient.cpp when calling m_semaphoreOpenEvt.wait("connect"). The problem is that despite I located the error I don't know what to do, can you help me?

chegewara commented 6 years ago

I would start with commenting out this line and see what would happend: m_semaphoreOpenEvt.wait("connect")

This wont fix the issue, maybe even cause some other issues but it can give you more info.

TheBrunez commented 6 years ago

I don't know if it is a good idea, but I can try it. I was hoping that someone else encountered this problem before and resolved it. I know that there is some applications that use BLE and Wifi at the same time (like this) but with arduino core I'm unable to get it working without modifying the "standard" BLE library for arduino core

chegewara commented 6 years ago

https://github.com/nkolban/esp32-snippets/blob/master/cpp_utils/tests/BLETests/SampleClientWithWiFi.cpp

johnhmacleod commented 6 years ago

I did run into an issue with BLE+WiFi and found that ensuring my BLE connection was complete before connecting to WiFi avoided the problem. That was a while ago (6 months perhaps) and I haven't retested since. Doing that, my BLE->WiFi gateway now runs happily for hours on end!

TheBrunez commented 6 years ago

Great, but my project works in a little different way. I have the WiFi always connected and then I have to connect to different BLE server in sequence. I will do more test and let you know if I found and solve the problem