[devLogs] Bluetooth Development
From my limited experiences in middleware development and research, writing programs to establish a Bluetooth(BT) connection between 2 programs is non-trivial.
Some learning points from 2-3 weeks of BT research:
Not as simple as a client-server architecture, requires knowledge of Socket Programming, if building BT software at a much more granular level.
The BT software stack has its own BT-specific communication protocols like L2CAP and RFCOMM, akin to how serial communication has serial communication protocols like SPI, I2C, UART.
The nature of BT development is largely platform-specific - Linux has
BlueZ
has the official bluetooth stack for interactions involving linux devices (eg. RPi running raspbian)- This is the official API documentation for
BlueZ
- I have no idea how to read this, but after reading background information from textbooks and internet code examples, some words/functions are starting to make sense.
- This is the official API documentation for
There is a cross-platform library that is written in Python -
pybluez
. Online resources like Will investigate its effectiveness when used to write programs to establish connections with bluetooth devices, like the iPhone and iPad.The device ecosystem in a BT setting consists of central devices and peripheral devices. Central devices accept data from peripheral devices.
both central or peripheral devices can engage in the first phase of connection - device discovery - and broadcast their availability for connection and
MAC
address (BT mac address, different from internet MAC address)central devices share a master-slave connection model with peripheral devices.
Peripheral devices send data to central devices.
The device which engages in device discovery will systematically broadcast its
MAC
address to devices nearby, and systematically query these nearby devices for its device name (in plain string) and/orMAC
address.
Profiles in BT are specifications which can be implemented as APIs. In the official, fully-verbose BT spec, there is a profile spec that is specifically for developers who want to develop HID (human input devices, eg. emulating a BT keyboard interface).
- I just need to find a library/API which allows me to emulate keyboards.
Very useful help resources that leads to coding knowledge on BT:
Interesting examples (repos)
(BLE) Most useful forum conversation (+ repo by petzval): https://forums.raspberrypi.com/viewtopic.php?t=305045
(BT classic, audio streaming example) https://github.com/nkim-bitzap/bluetooth
Official C BlueZ code https://github.com/luetzel/bluez/blob/master/doc/device-api.txt
ESP32-specific resources:
- https://docs.espressif.com/projects/esp-idf/en/stable/esp32s3/api-guides/bluetooth.html#applications
Google search term: ble server on raspberry pi which acts as a keyboard
Highest-level specs:
Subscribe to my newsletter
Read articles from Carey Lzh directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by