Bluetooth from Zig?

Hi,

I am trying to write a small program that to connects to a Bluetooth device and read/write/subscribe to GATT characteristics. I did manage to get something working using the c library bluez_inc, but I was wondering if you guys have some suggestions of what would be the best way to use Bluetooth from zig? Maybe some of you have already tried someting?

(note: I don’t need multi-platform, something that works on linux only is fine)

Hi Jomag, welcome to forum!

With which device do you want to receive the bluetooth signals? I’m using ESP32 devices and for what I’m doing UART is fast enough. And in my opinion it’s the simplest interface, even if you are using a raspi, but also with a normal pc. For example, the Waveshare ESP-32-C5 Wifi-Kit put the UART signal directly to USB and parallel to the GPIO pins.

Hi Jomag, welcome to forum!

Thanks :smiley:

With which device do you want to receive the bluetooth signals

I would like to connect to an electronic chessboard from my computer to read the placement of the chess pieces and turn leds on and off. I do not have much more information other that the characteristics UUIDs and byte patterns expected/returned by the board: GitHub - chessnutech/Chessnut_eBoards · GitHub

for what I’m doing UART is fast enough. And in my opinion it’s the simplest interface

Cool. I admit, I am not so sure how I would proceed in practice, and I’d appreciate some pointers :smiling_face:. In particular, how could I discover the device and write or subscribe to the right characteristic using UART?

I took a look at the website, and there’s an easier way. You can use a dongle, for example the Edimax BT-8500, and then program it with an L2CAP socket, without D-Bus. I don’t know of any zig module, though; you’ll have to do that yourself. :sweat_smile:

Edit: Personally, I would use this one with UART: ESP32-C5-MINI-KIT | WaveShare Documentation
There you can open /dev/ttyACM0 in Zig for example and read the stream.

Ok, thank you for the tips, I’ll explore this option :slight_smile: