ESP32 Bluetooth Serial and BLE server running together

There is a new kid coming into the arduino-esp32 world. A Bluetooth Serial library that allows you to use Bluetooth (not BLE) like a serial port. This way you can connect the ESP32 over Bluetooth to an Android app like theĀ Serial Bluetooth Terminal and use it as a serial in/out interface.

The library is not yet in the arduino-esp32 repository, but I grabbed a preview from copercini’s repo. It is working fine, I could connect my Android tablet to my ESP32 over Bluetooth and send and receive messages between the two.

Now I wanted to integrate this into my weather station project, where I have already a BLE server running. And it didn’t work. I could get either the BLE server or the Bluetooth serial to work, but not both together.

The mistake I made was that I tried to initialize both in separate function calls. First it was like calling

and then calling

depending on the sequence I called the two functions the system either crashed or only one of the two services were working.

After a lot of trial and error and discussions with copercini I figured out the solution. The initialization of BLE and Bluetooth Serial must somehow be at the same time. The working solution:

The working sequence seems to be

The full code of the initialization routine can be found in my Github repo.


Leave a Reply

Your email address will not be published. Required fields are marked *

Free Link Directory