Page 1 of 1

Bluetooth BLE C/C++ development

Posted: Wed Apr 25, 2018 4:46 pm
by PaulVdBergh
Hi All,

I'm currently working on a IoT project involving ESP32 modules and an RPi linux device. The ESP32 devices communicate to/from the RPi using MQTT (Mosquitto on the RPi, Paho on the ESP32). However, before this communication can start, the ESP's need to know the wifi SSID and password, the ip-address of the broker (aka RPi) and some device-specific settings. ATM this data is hard-coded into the ESP firmware. This is not the best way. A solution would be to use the ESP-IDF console component, but this requires some sort of wired connection. That's also not ideal for my situation... The best solution I can come up with is using bluetooth communication to set the ESP's parameters before participating in the MQTT system. I found documentation for the ESP side to solve this, but no info re the linux side.
So my simple question is where I can find info/tutorials/examples on how to implement BLE functionality in C/C++ on linux (Debian) ? I was googling the whole day to no avail (However, I found a lot of info about BLE in general, so no time is wasted ;) .

Thanks for your input.

Paul

Re: Bluetooth BLE C/C++ development

Posted: Wed Apr 25, 2018 4:54 pm
by fly135
Kolban has a library that contains C++ components for BLE communication. You can create a BLE characteristic that handles writes and notifications. Create a single service with that characteristic that recvs string commands on the write and uses string commands on the notify. Then you can define what those strings mean for passing info back and forth. I think you should keep the strings small. That part of the BLE is sort of magic to me. I think the packets are pretty small and mostly used up by a 128bit UUID, but somewhere in the lower layer it does seem to piece them together.

I had this task and struggled with it because it turned out my Samsung S5 and BLE on the ESP32 weren't cooperative pals. A change to the iPhone 6 fixed that. Although a quick test with nRF (get that app too) on an S7 revealed it should work.

Should also mention that Kolban's library handles the advertisements, which are necessary for a phone app to find your esp32.

edit: Here's a repo form another forum member that demonstrates BLE...

https://github.com/chegewara/esp32-ota-with-ble-setup

John A

Re: Bluetooth BLE C/C++ development

Posted: Wed Apr 25, 2018 5:01 pm
by PaulVdBergh
Thanks for your (fast) reply.

Does Kolban's code runs on Debian (Linux) ? or is it only the ESP-side of the story ?

Thanks,

Paul

Re: Bluetooth BLE C/C++ development

Posted: Wed Apr 25, 2018 5:31 pm
by fly135
PaulVdBergh wrote:Thanks for your (fast) reply.

Does Kolban's code runs on Debian (Linux) ? or is it only the ESP-side of the story ?

Thanks,

Paul
Oh sorry, I now realize you are trying to talk to the ESP from linux. You might find more examples of using a phone app to set up your ESP. No idea of how to program it in linux.

John A

Re: Bluetooth BLE C/C++ development

Posted: Thu Apr 26, 2018 12:13 am
by bobolink
For some reason, BLE on the Raspberry Pi has always been problematic.
I googled this: https://doc.qt.io/qt-5/qtbluetooth-index.html

non C/C++ solutions include BlueZ/Python or node.js https://github.com/noble/bleno
Hope someone else comes up with something