An Introduction to Bluetooth Programming

Albert Huang

Book News: Since its writing, this document has been expanded into a more complete text, published by Cambridge University Press. The book is titled Bluetooth Essentials for Programmers and provides a much more detailed introduction to Bluetooth. It also describes how to write Bluetooth programs targeted for the GNU/Linux, Windows XP, OS X, and Series 60 platforms. Examples are given in C, Python, and Java.

This tutorial on Bluetooth programming in GNU/Linux will continue to be freely distributed from this website, but if you find it useful, or would like to learn more about Bluetooth programming, please consider purchasing, borrowing, or otherwise obtaining a copy of the book. Cheers.


More information is available at the website:

Table of Contents
1. Introduction
1.1. About this booklet
1.2. Who this document is for
1.3. Obtaining BlueZ and PyBluez
2. Bluetooth Programming Introduced
2.1. Overview
2.2. Choosing a communication partner
2.2.1. Device Name
2.3. Choosing a transport protocol
2.3.1. RFCOMM + TCP
2.3.2. L2CAP + UDP
2.4. Port numbers and the Service Discovery Protocol
2.5. Establishing connections and transferring data
2.6. Bluetooth Profiles + RFCs
3. Bluetooth programming with Python - PyBluez
3.1. Choosing a communication partner
3.2. Communicating with RFCOMM
3.3. Communicating with L2CAP
3.4. Service Discovery Protocol
3.5. Advanced usage
3.5.1. Asynchronous device discovery
3.5.2. The _bluetooth module
3.6. Alternatives
3.6.1. Java
3.6.2. PyAffix
4. Bluetooth programming in C with BlueZ
4.1. Choosing a communication partner
4.1.1. Compilation
4.1.2. Explanation
4.2. RFCOMM sockets
4.2.1. Addressing structures
4.2.2. A note on byte ordering
4.2.3. Dynamically assigned port numbers
4.2.4. RFCOMM summary
4.3. L2CAP sockets
4.3.1. Maximum Transmission Unit
4.3.2. Unreliable sockets
4.4. Service Discovery Protocol
4.4.1. sdpd - The SDP daemon
4.4.2. Describing a service
4.4.3. Registering a service
4.5. Advanced BlueZ programming
4.6. Chapter Summary
List of Tables
2-1. A comparison of the requirements that would lead us to choose certain protocols. Best-effort streams communication is not shown because it reduces to best-effort datagram communication.
2-2. Port numbers and their terminology for various protocols
List of Examples
4-1. simplescan.c
4-2. rfcomm-server.c
4-3. rfcomm-client.c
4-4. l2cap-server.c
4-5. l2cap-client.c
4-6. set-flush-to.c
4-7. Step one of searching a device for a service with UUID 0xABCD
4-8. parsing and interpreting an SDP search result
4-9. Describing a service