Giter Site home page Giter Site logo

bluetooth-proximity's Introduction

Bluetooth Proximity Detection

Python code for getting the RSSI value of a Bluetooth device by address. Based on the value returned, can determine the proximity of the device.

This code was ported to Python 3 based on this repository, primarily for use in Home Assistant.

Requirements

This code requires the bluetooth and python-bluez modules to be installed. On Ubuntu/Debian systems, this can usually be done with the following commands:

sudo apt-get install bluetooth
sudo apt-get install python-bluez

Note: Your system must also have a Bluetooth adapter.

Installation

git clone https://github.com/frederikbolding/bluetooth-proximity.git
cd bluetooth-proximity
sudo python setup.py install

Examples

test_address.py

This is a simple script to scan and output the RSSI value of a Bluetooth address in a loop. This can be used to test if the code is working on your setup and also to output the detected RSSI values as you move your Bluetooth device closer/further from the Bluetooth adapter.

Use Ctrl + C to exit the script or wait until number of loops has finished.

python test_address.py <bluetooth-address> [number-of-loops]

bluetooth_scanner.py

An example script that uses threads to scan for bluetooth addresses in a loop and invokes a callback function when the RSSI value is within a specified threshold.

Edit the script and set the BT_ADDR_LIST variable to the list of bluetooth addresses to scan.

Use Ctrl + C to exit the script.

python bluetooth_scanner.py

lnsm.py (Log Normal Shadowing Model)

An example script to scan & output the distance between two bluetooth devices using the RSSI value . The distance between the two devices is calculated using the Log-Normal Shadowing Model/Log-Distance Pathloss Model.

Use Ctrl + C to exit the script or wait until number of loops has finished. Recommended number of loops = 30

python lnsm.py <bluetooth-address> [number-of-loops]

Notes

  • The RSSI values returned will differ depending on your Bluetooth devices and your surroundings (e.g. are there walls/obstructions, multiple floors, etc).
  • Use the test script mentioned above to see what values are returned in your setup.
  • RSSI values may be positive or negative integers. You can use the absolute value (i.e. always positive) if you see both.

bluetooth-proximity's People

Contributors

dovidgef avatar ewenchou avatar frederikbolding avatar jonathanrjpereira 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.