# Bluetooth LE Programming On Raspberry Pi

I'm looking at building up some Bluetooth LE programming expertise on Linux, specifically for use with Raspberry Pi 3 B+ and Pi Zero W models.

This is a compendium of libraries and tools that I'm looking at to build that skill on.

## DON'T FORGET!!!

On the Raspberry Pi Zero W, a user must be a member of the `bluetooth` group to work with tools like `bluetoothctl`. Set this up with:

```sh
$ usermod -aG bluetooth [username]
```

## General 

- [Everything You Need To Know to Set Up Bluetooth on the Raspberry Pi 3](https://lifehacker.com/everything-you-need-to-set-up-bluetooth-on-the-raspberr-1768482065)
- [BlueZ](http://www.bluez.org/) - core Bluetooth support for Linux
- [Ubuntu Core BlueZ documentation](https://docs.ubuntu.com/core/en/stacks/bluetooth/bluez/docs/)
- [An Intro to Bluetooth Programming](https://people.csail.mit.edu/albert/bluez-intro/index.html) - MIT CSAIL notes on developing for Bluetooth using BlueZ.

## Python

- [PyBluez](https://github.com/pybluez/pybluez)
- [bluepy](https://github.com/IanHarvey/bluepy)
- [pygatt](https://github.com/peplin/pygatt)
- [Adafruit_Python_BluefruitLE](https://github.com/adafruit/Adafruit_Python_BluefruitLE)
- [bluepy](https://github.com/IanHarvey/bluepy)

To get `pybluez` installed, I had to increase the size of the system swapfile (the `gattlib` dependency wouldn't compile). See [this](https://www.bitpi.co/2015/02/11/how-to-change-raspberry-pis-swapfile-size-on-rasbian/) for info on how to change the swapfile size.

Also has to fix a `gattlib` dependency, as described here: https://stackoverflow.com/questions/41463847/got-error-while-download-gattlib-via-pip3/52271293#52271293

Because `pybluez` requires root access, and because of the aforementioned issues, here's how I installed everything:

```
pip3 download gattlib
cd gattlib-0.20150805
sed -ie 's/boost_python-py34/boost_python-py35/' setup.py
sudo pip3 install .
sudo pip3 install pybluez\[ble\]
```

This ensures that root can see the packages, and that we get `gattlib` installed before `pybluez`.

## Ruby

- [ble](https://rubygems.org/gems/ble/versions/1.0.0)