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.

Facebooktwitterredditpinterestlinkedintumblrmail

One comment

  • First I want to say I’m a big fan of your open source work. I use actively your ESP32 WiFi Ble in one of my projects:
    https://github.com/martinberlin/Remora

    And I’m also making an Android application but I do not know have, so I’m making something similar based on your examples (And still supporting your ESP32 WiFi BLE app) but in Cordova. Also open source so other people can use it
    Just wanted to leave you my contact details to get in touch. And kind regards from another developer and electronics fan living in Berlin

    Reply

Leave a Reply

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

Free Link Directory