Giter Site home page Giter Site logo

sraodev / bluetooth-service-rfcomm-python Goto Github PK

View Code? Open in Web Editor NEW
26.0 2.0 6.0 16 KB

This application connects two devices over Bluetooth and allows one to send messages to the other using json. Raspberry Pi Bluetooth interfacing with Linux via RFCOMM BT network

License: MIT License

Python 100.00%
pybluez bluetooth bluez raspberry-pi-3 python socket-programming json pickle python-3 python-bluetooth-service

bluetooth-service-rfcomm-python's Introduction

Bluetooth Service (PyBluez) with RFCOMM sockets

This application connects two devices over Bluetooth and allows one to send messages to the other using json. The sending device runs bleClient.py, and the receiving device runs bleServer.py

Getting Started

How to setup a bluetooth server in a Raspberry Pi so an Linux can connect to it.

Pre-quisites

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

Installation

sudo apt-get install python-pip python-dev ipython

sudo apt-get install bluetooth libbluetooth-dev

sudo apt-get install bluez-utils blueman

sudo apt-get install bluez python-bluez

sudo pip install pybluez`

You've installed the Python 2 version of the bluez bindings. Either run the script using python2 or install the Python 3 bindings. Since they aren't packaged, you would need to install them using pip:

sudo python3 -m pip install pybluez`

Setup your Raspberry Pi

Make your device discoverable

sudo hciconfig hci0 piscan

Scanning for devices run the inquiry example:

sudo python inquiry.py

Running the Bluetooth Server on RaspberryPi:

sudo python bleServer.py

Running the Bluetooth Client on Linux box:

sudo python bleClient.py

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.

As it turns out, the culprit is bluetoothd, the Bluetooth daemon. Using SDP with bluetoothd requires deprecated features for some silly reason, so to fix this, the daemon must be started in compatibility mode with bluetoothd -C (or bluetooth --compat).

You need to run the Bluetooth daemon in 'compatibility' mode. Edit /lib/systemd/system/bluetooth.service and add '-C' after 'bluetoothd'. Reboot.

sudo sdptool add SP

Or

Find location of bluetooth.service by:

systemctl status bluetooth.service

Then edit bluetooth.service and look for ExecStart=/usr/libexec/bluetooth/bluetoothd Append --compat at the end of this line, save, and then run

service bluetooth start

If all goes well, you should be able to successfully run

sudo sdptool browse local

Finally, reset the adapter:

sudo hciconfig -a hci0 reset

Contributing

Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are greatly appreciated. Please read the contribution guidelines first.

Reference

Bluetooth Programming with Python 3

Bluetooth programming with Python - PyBluez

Bluetooth for Programmers

Bluetooth Python extension module

bluetooth-service-rfcomm-python's People

Contributors

sraodev avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 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.