emlid / bluetool

Bluetooth manager for Linux.
GNU General Public License v3.0
48 stars 26 forks source link

Bluetool

A simple Python API for Bluetooth D-Bus calls. Allows easy pairing, connecting and scanning. Also provides a TCP-to-RFCOMM socket bridge for data transfer.

Dependencies

The package was tested with Python 2.7

Installation

pip install bluetool

or clone and run make install

Usage

Examples

bluetooth = Bluetooth() bluetooth.scan() devices = bluetooth.get_available_devices() print(devices)

- Using the RFCOMM-TCP Bridge
```python
import signal
from bluetool import BluetoothServer

def handler(signum, frame):
    server.shutdown()

tcp_port = 8100
server = BluetoothServer(tcp_port)

signal.signal(signal.SIGINT, handler)
signal.signal(signal.SIGTERM, handler)

server.run()

class MyClient(Client):

def request_pin_code(self, dev_info):
    print(dev_info)
    return raw_input("Input pin code:")

def request_passkey(self, dev_info):
    print(dev_info)
    return raw_input("Input passkey:")

def request_confirmation(self, dev_info, *args):
    print(dev_info, args)
    return raw_input("Input 'yes' to accept request:") == "yes"

def request_authorization(self, dev_info):
    print(dev_info)
    return raw_input("Input 'yes' to accept request:") == "yes"

def handler(signum, frame): svr.shutdown()

svr = AgentSvr(client_class=MyClient)

signal.signal(signal.SIGINT, handler) signal.signal(signal.SIGTERM, handler)

svr.run()



### About the project

This package was written by [Aleksandr Aleksandrov](https://github.com/AD-Aleksandrov) working at [Emlid](https://emlid.com/).

The bluetool was originally written for the [Emlid Reach RTK receiver](https://emlid.com/reach/), but we decided to open source it, as there is no easy Python API for BT pairing/connecting. Feel free to add issues and submit pull requests.