Page 1 of 1

My short ride with ble + wifi

Posted: Mon Nov 26, 2018 11:48 pm
by chegewara
As you all know i am playing a lot with Kolban's ble library. This time i decided to see how it is going to work with wifi coex. I build simple app that is scan for ble devices and at the same time allows to load web page with count of discovered devices. To do that i am using esp http server.
My beginnings were not very promising. Wifi has been disconnected very often with message that is suggesting radio sleep (i didnt know at the time we have power save option in wifi and we can turn of it)
https://github.com/espressif/esp-idf/bl ... ifi.h#L456
https://github.com/espressif/esp-idf/bl ... #L191-L195
Also i had very long times to load web page.

So i decided to play with menuconfig options:

Code: Select all

Software controls WiFi/Bluetooth coexistence. 
My first and last idea, since i had most problems wit wifi and http server, to try

Code: Select all

 WiFi/Bluetooth coexistence performance preference (WiFi)
It was perfect choice. Since now my app start running as i expected. My ble scan infinitely and i can load web page pretty quick to see results. Also there is no more wifi disconnection.

My next step was to add some more functionality. Because its only proof of concept app i decided to keep it very simple, even tho i have few functions:
- display count of discovered ble devices since last buffer clear,
- clear discovered ble devices buffer,
- display count of discovered ble devices in current http session,
- change ble scan interval and window.

As you can see its simple app. Http server part is not complicated, just few request handlers with sessions implemented. Sessions part is not complicated, keeps tracking number of discovered ble devices in current session. Session timeout is default value (300 seconds). Since web page is not complicated it is inline char array, and is displaying simple form and few paragraphs. Also very simple javascript is included. Form is to set ble interval and window parameters.

Now ble part. It is also very simple. Just scan for new ble devices and keep track of currently stored ble devices in cache. Allow to retrieve count number to display on web page and function to set interval and window. I have also functions to start and stop scan which are used during change of settings and when wifi disconnect event is triggered. Im not sure i need it any longer, but when i started i discovered that i have to stop ble scan to connect wifi to AP.

Now most interesting part IMO. esp http server is running without issues even when i perform infinite ble scan. My first test last for over a week and what i found intriguing is that i could in this configuration set ble scan window and interval values to the same interval. Why is it intriguing you may ask. Because in theory it should take whole radio time, which again IMO clearly proves that SW coexistence works very good in configuration wifi + ble. Of course it was not very extensive test, i was about 8-10 active ble devices at the same time around me, but i am really happy from results and i decided to share my experience in case that someone else wish to try with wifi + ble.