Bluetooth BLE C/C++ development

User avatar
PaulVdBergh
Posts: 58
Joined: Fri Feb 23, 2018 4:45 pm
Location: Brasschaat, Belgium

Bluetooth BLE C/C++ development

Postby PaulVdBergh » Wed Apr 25, 2018 4:46 pm

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

User avatar
fly135
Posts: 606
Joined: Wed Jan 03, 2018 8:33 pm
Location: Orlando, FL

Re: Bluetooth BLE C/C++ development

Postby fly135 » Wed Apr 25, 2018 4:54 pm

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

User avatar
PaulVdBergh
Posts: 58
Joined: Fri Feb 23, 2018 4:45 pm
Location: Brasschaat, Belgium

Re: Bluetooth BLE C/C++ development

Postby PaulVdBergh » Wed Apr 25, 2018 5:01 pm

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

User avatar
fly135
Posts: 606
Joined: Wed Jan 03, 2018 8:33 pm
Location: Orlando, FL

Re: Bluetooth BLE C/C++ development

Postby fly135 » Wed Apr 25, 2018 5:31 pm

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

bobolink
Posts: 98
Joined: Mon Feb 26, 2018 4:17 pm

Re: Bluetooth BLE C/C++ development

Postby bobolink » Thu Apr 26, 2018 12:13 am

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

Who is online

Users browsing this forum: Google [Bot] and 252 guests