GithubHelp home page GithubHelp logo

raspberry-bluetooth-demo's Introduction

raspberry-bluetooth-demo

This demo shows how to setup a simple bluetooth server in a Raspberry Pi so an Android Phone can connect to it.

Prerequisites

This demo assumes:

  • basic Linux (*nix also works too) command line knowledge
  • Python knowledge

This demo was tested using the Raspberry Pi 3 that comes with pi-bluetooth pre-loaded and working 'out of the box'. If you are using an older version set up pi-bluetooth before following this demo, multiple resources can be found online. Depending on your setup the following command should work:

sudo apt-get install pi-bluetooth

This demo uses Bluez, Linux's Bluetooth protocol stack, we'll be using PyBluez, a Python API for accesing the bluetooth resources using the bluez protocol.

Installation

install bluez

sudo apt-get install bluetooth bluez

install pyBluez

sudo apt-get install bluez python-bluez

Setup your Raspberry Pi

Make your device discoverable

sudo hciconfig hci0 piscan

Configure your device name

sudo hciconfig hci0 name 'Device Name' [change your device name to something else you fancy]

Scanning for devices

run the inquiry example:

sudo python /usr/share/doc/python-bluez/examples/simple/inquiry.py

The example may also be found here.

Running the Bluetooth Server

run the rfcomm-server example:

sudo python /usr/share/doc/python-bluez/examples/simple/rfcomm-server.py

The example may also be found here. After running the script the server will be waiting for an incoming connection.

Connecting from an Android Phone

There are several applications in the Google Play Store for bluetooth connectivity that may work. We'll be using BlueTerm as it supports the RFCOMM bluetooth protocol.

Steps:

  1. Download BlueTerm
  2. Scan for devices, if you've done everything correctly the Raspberry Pi should show up
  3. Connect
  4. Success! Send messages back and forth!

Credits

This demo would not have been possible thanks to the following posts and online resources:

Although this repo intends to be a summary of these resources, if you are stuck it might be useful to check them out.

Known Issues

Traceback (most recent call last):
  File "/usr/share/doc/python-bluez/examples/simple/rfcomm-server.py", line 20, in <module>
    profiles = [ SERIAL_PORT_PROFILE ], 
  File "/usr/lib/python2.7/dist-packages/bluetooth/bluez.py", line 176, in advertise_service
    raise BluetoothError (str (e))
bluetooth.btcommon.BluetoothError: (2, 'No such file or directory')

Possible fixes

  • make sure you are using sudo when running the python script
  • make sure you have the serial profile loaded. How to enable the serial profile.
  • Yor own fix? Make a pull request!

Important Note!

If something didn't work for you, you had to implement a weird fix or hack, or you think something could be explained better (maybe you found a typo, missing comma, or some weird wording (this is very much likely)) feel free to make a pull request!

raspberry-bluetooth-demo's People

Contributors

alejandrogarciasalas avatar utkarsh-vishnoi avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.