Wifi BLE coexistence using Arduino IDE

dhiraj_gehlot
Posts: 4
Joined: Thu Jul 30, 2020 11:23 am

Wifi BLE coexistence using Arduino IDE

Postby dhiraj_gehlot » Thu Jul 30, 2020 11:27 am

Hello Everyone,

I am new to Esp32 and currently using ESP32 NodeMCU-ESP32 with arduino IDE. Please forgive me if I have posted it in incorrect forum.

I am working on application which requires co-existence of BLE and Wifi.

Here's the data flow;

ESP32 act as Master -> connects to BLE device which provides data -> Data received by ESP32 from mobile via BLE -> ESP process the data -> Sends the data to server using wifi -> receive another data from server -> send to external device via BLE.
So ESP act as bridge between two device.

There are two parts:

a. Getting data from device via BLE

b. Posting data to server or reading data from server
I have tested both part individually and they worked perfectly fine. When I tried to merge that, its not working. In this merged code, the BLE device connects fine, also receiving data works, but it is unable to post the data to server. However, if I disable the BLE here, same code can post data properly. So I am slightly confident that it has something to do with radio sharing between BLE and Wifi.

As per this FAQ document:
https://www.espressif.com/sites/default ... Qs__EN.pdf
5.3.2. How do ESP32 Bluetooth states " Please note that if Option “Software controls WiFi/Bluetooth coexistence” is enabled, the BLE scan interval shall not exceed 0x100 slots (about 160 ms)."

Code: Select all

[Codebox=cpp file=Untitled.cpp]Pseudo code: 

#define CONFIG_SW_COEXIST_ENABLE 1
int scanTime = 5; //duration The duration in seconds for which to scan In seconds int scanWindow = 50; //In msec int scanInterval =100; // in Msec

void scanForDevices(){
  Serial.println("Scanning for Bluetooth devices...");
  // Retrieve a Scanner and set the callback we want to use to be informed when we
  // have detected a new device.  Specify that we want active scanning and start the
  // scan to run for 30 seconds.
  BLEScan* pBLEScan = BLEDevice::getScan();
  pBLEScan->setAdvertisedDeviceCallbacks(new AdvertisedDeviceCallbacks());
  pBLEScan->setActiveScan(true);
  pBLEScan->setInterval(scanInterval); //in Msec
  pBLEScan->setWindow(scanWindow); // in mSec
  pBLEScan->start(scanTime); // in seconds
}[/Codebox]
I am using above method to set the intervals as suggested by Document. Is this correct or am I missing something?

I also tried to disable BLE when wifi operation is happening using WiFi.mode (WIFI_OFF); btStart(); btStop(); by referring to wifiBluetoothSwitch Example from arduino

Complete code here : https://drive.google.com/file/d/1AINLN4 ... sp=sharing

As per datasheet, they both can coexist, can someone please guide me?

chegewara
Posts: 1183
Joined: Wed Jun 14, 2017 9:00 pm

Re: Wifi BLE coexistence using Arduino IDE

Postby chegewara » Fri Jul 31, 2020 8:25 am

Hi, if you set scan window to 0x100 what is scan interval?
If you set it also to 0x100 then radio is 100% occupied by bluetooth and no time for wifi.
The shorter interval you leave the more reliable is wifi connection, but you may start missing some ble packets.


You can also try to stop scan during wifi connection.

dhiraj_gehlot
Posts: 4
Joined: Thu Jul 30, 2020 11:23 am

Re: Wifi BLE coexistence using Arduino IDE

Postby dhiraj_gehlot » Fri Jul 31, 2020 1:26 pm

Thanks for the response :)
You can also try to stop scan during wifi connection.
Can I use the function mentioned below?
btStop(); or
advertisedDevice.getScan()->stop();
If you set it also to 0x100 then radio is 100% occupied by bluetooth and no time for wifi.
Understood. I will try lesser values and let you know the result.

dhiraj_gehlot
Posts: 4
Joined: Thu Jul 30, 2020 11:23 am

Re: Wifi BLE coexistence using Arduino IDE

Postby dhiraj_gehlot » Fri Jul 31, 2020 3:38 pm

I tried btstop() and btstart(). It works properly, however ESP32 resets everytime btstart() method is called.

chegewara
Posts: 1183
Joined: Wed Jun 14, 2017 9:00 pm

Re: Wifi BLE coexistence using Arduino IDE

Postby chegewara » Mon Aug 03, 2020 5:02 pm

Code: Select all

advertisedDevice.getScan()->stop();
This is just fine.

dhiraj_gehlot
Posts: 4
Joined: Thu Jul 30, 2020 11:23 am

Re: Wifi BLE coexistence using Arduino IDE

Postby dhiraj_gehlot » Tue Aug 04, 2020 4:47 am

advertisedDevice.getScan()->stop();
I tested this, I am unable to make POST call.
But when I use "btStop()" at the start of post call, it works. Problem is if I use btStart(), esp32 resets. If I don't use btStart() then esp32 is unable to receive data via BLE as its not advertised.

chegewara
Posts: 1183
Joined: Wed Jun 14, 2017 9:00 pm

Re: Wifi BLE coexistence using Arduino IDE

Postby chegewara » Fri Aug 07, 2020 9:15 pm

Im guessing you have issues with heap shortage, but after calling btStop you cant use bluetooth anymore:
https://github.com/espressif/arduino-es ... l-bt.c#L56

I dont see function that free bt memory, so btStart() should reinit it, but i would suggest to use this:
https://github.com/espressif/arduino-es ... e.cpp#L636

I never had to deinit library, so i dont know how it works in app.

Who is online

Users browsing this forum: No registered users and 15 guests