The PyBlueZ library provides an easy to use interface for communicating over Bluetooth in Python. While Python has native support for Bluetooth with its sockets interface, it is only available for Python v3.3 and up. In addition the PyBlueZ provides a lower-level interface for Bluetooth that can be used to do more Bluetooth-specific operations such as getting the RSSI value of a Blueooth device.
For the real-world testing component of the CoLo Project, we needed a two-way connection among each of the robots in order for them to communicate information. Since WiFi was reserved for other purposes, we resorted to using Bluetooth to create a P2P connection between each of the robots. The PyBlueZ module provides a high-level socket interface for establishing a connection between two Bluetooth devices. With this method, one of the devices acts as the server listening on a specified port for incoming connections. Another device acts as the client that attempts to connect to the server on the same port. Once the connection is accepted by the server, both the client and the server can send and receive messages with each other.
Using the socket interface provided by PyBlueZ, we have the choice of two different transport protocols: RFCOMM and L2CAP. This article by Albert Huang provides an overview of each protocol and their respective use cases. For our project we settled on using L2CAP for its configurability and more importantly the number of unique ports it supports. While RFCOMM allows for at most 30 open ports at any given time, L2CAP provides ~15,000 unreserved ports. For our project we need a connection between each robot which totals up to \({\# robots}\choose{2}\) connections. Since each robot must be able to connect to any other robot, all robots except for two (one client only and one server only) must act as both the client and the server. This means that to allow any arbitrary robot to communicate to any other robot we need \(2{{\# robots}\choose{2}} - 2\). Since the added complexity of maintaining two robots with a different configuration does not outweigh the benefit of saving 2 connections, we instead use each connection only in a single direction to send messages from a client to a server. In this arrangement we use \(2{{\# robots}\choose{2}}\) ports. If we were to use RFCOMM with its limit of 30 ports, we could only support up to 6 robots connected simultaneously, L2CAP on the other hand could theoretically support up to \(\lfloor\frac{1+\sqrt{60001}}{2}\rfloor=122\) robots.