Raspberry Pi running Wheezy (Debian 7)
There’s a few different way to figure out what distribution you have. You can do:$lsb_release -a
$cat /proc/version (didn’t work for me)
$cat /etc/*-releaseI’m sure there are other ways. Here are the results for all 3:
(Note: I tried getting this project going using Jessie (Debian 8) and had mixed results. Due to never having done this before, I initially interpreted those results as failure, and downgraded to Wheezy. I’m not 100% convinced that this wouldn’t work on Jessie or later. I’ll try to point that out where I can and make suggestions on what to do differently
Inateck Bluetooth 4.0 dongle
This is the exact one I bought. Let me just say that apparently it *really* matters which one you get. It obviously has to support BLE (Bluetooth 4.0). This was specifically recommended by the Raspberry Pi people.
The bluetooth stack
This is just the standard bluetooth tools that you can install from the Wheezy repository. There may be some version issues that I try to address below.
nodejs and npm
- Install the ‘bluetooth stack’ that comes with Wheezy. This was the first source of frustration. The version of bluez that shipped with Wheezy was 4.99x. The current version of bluez is 5.x, and that is what ships with Jessie. I guess there is some sort of problem with bleno due to a GATT server that is enabled by default in the 5.x version. It’s hard to tell if that was ever resolved or not by reading the conversations that went on on the Bleno site. If you are using Jessie, look into installing a lower version of Bluez.sudo apt-get install bluetooth bluez libbluetooth-dev libudev-dev
- After all that installs, you have to make sure bluetoothd is not running. Apparently this interferes with Bleno as well. To turn it off once do:sudo service bluetooth stopTo make that persist after a reboot you have to do:sudo update-rc.d bluetooth remove
- Install nodejs and npm:cd ~
tar xfv node-v5.5.0-linux-armv7l.tar.xz
sudo cp -R * /usr/local/This just downloads the pre-built binaries and copies them into /usr/local/. The nice thing about doing it this way is if you want to try out a different version, all you have to do is find the version number you want and change it. If you do these steps again, it will just overwrite the old one. (Ref: https://chip.hackster.io/inmyorbit/connect-a-mobile-application-to-your-c-h-i-p-using-ble-96fe96
- Update gcc and g++ to 4.9. This is crucial and Bleno will NOT install without doing this. It was very confusing because on Jessie, the Bleno install worked right away. On Wheezy, I was getting these weird compile errors that I wasn’t getting before. I was able to track the problem down to the c++ compiler, which is outdated on Wheezy. Then I found these instructions to update it and it magically just worked (I’m not a c++ guy so it wasn’t obvious to me).
- Edit /etc/apt/sources.list, replace wheezy with jessie: sudo nano /etc/apt/sources.list
- Update the package list to the Jessie packages: sudo apt-get update
- Install the newer versions: sudo apt-get install gcc-4.9 g++-4.9
- Edit /etc/apt/sources.list, replace jessie with wheezy: sudo nano /etc/apt/sources.list
- Update the packages back to the Wheezy packages list: sudo apt-get update
- Update the symlinks for gcc and g++ to use the newer version: cd /usr/bin; sudo ln -sf gcc-4.9 gcc; cd X11; sudo ln -sf g++4.9 g++
- Now you are ready to install Bleno:
- Do: sudo npm install bleno (You will get some, I don’t know, errors? complaints? from npm at various points, but it should work.)
- Reboot the pi just to be safe: sudo reboot
- After everything comes back up, make sure bluetoothd is not running: sudo service bluetooth stop
- Bring up the bluetooth interface: sudo hciconfig hci0 up
- And that’s it! Now you should be able to run the Bleno test peripheralcd node_modules/bleno //this was in my home directory, yours may be elsewhere
sudo node test.js
This is what Bleno looks like on the pi (peripheral) side:
And this is what it looks like on the iOS side. When lightBlue loads, you should see a service that corresponds to your pi’s hostname:
If you tap the one with your hostname, it will discover services on your pi. You should see one service with a long UUID of all F’s ending with a number, and a bunch of Characteristics that have the same naming convention.
Then you should be able to connect to the Characteristics and get a good sense of what Bleno can do.
In my next post, I’ll describe my efforts to write my own service and characteristics.
Source: Pi3: Getting BLE Up and Running