Giter VIP home page Giter VIP logo

ble-btlemon's Introduction

btlemon - Bluetooth Low Energy monitor for Linux

About

This tool provides address, signal strength (RSSI), and data of BLE devices scanned with hcitool.

Example usage:

  • execute sudo btlemonrun
  • in another shell execute sudo hcitool lescan --duplicates
  • output from hcitool:
40:40:51:17:2B:B1 (unknown)
4E:AF:83:1E:D6:2F (unknown)
4E:AF:83:1E:D6:2F (unknown)
  • example output from btlemon:
1589219961 40:40:51:17:2B:B1 -87 
1589219964 4E:AF:83:1E:D6:2F -54 0303AAFE1516AAFE00BFD7088787A44470A9FBD2000000000000
1589219964 4E:AF:83:1E:D6:2F -54

Check tools for convenient hcitool commands.

C library

Custom callback can be defined:

#include <stdio.h>
#include <math.h>
#include "btlemon.h"

static void callback(const uint8_t addr[6], const int8_t *rssi, const uint8_t *data, uint8_t data_len) {
  char addr_string[18];
  sprintf(addr_string, "%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X",
          addr[5], addr[4], addr[3],
          addr[2], addr[1], addr[0]);
  double distance = pow(10, (-60-*rssi)/20.);
  printf("addr: %s, distance: %.2f\n", addr_string, distance);
}

int main() {
  btlemon_set_callback(callback);
  return btlemon_run();
}

Python bindings

pybtlemon.so is compiled with CMake. Can be used as follows (remember to execute as root user, together with sudo hcitool lescan):

import pybtlemon


def callback(addr, rssi, data):
    print(f"addr: {addr}, distance: {10**((-60-rssi)/20):.2f}, data: {data}")


pybtlemon.set_callback(callback)
pybtlemon.run()

Compiling

Requires Bluez, in particular bluetooth.h and hci.h headers. On Ubuntu 18.04 these headers are packaged in libbluetooth-dev. Python bindings require Python 3.

mkdir -p build
cd build
cmake ..
make

ble-btlemon's People

Contributors

kbobrowski avatar

Watchers

 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.