GithubHelp home page GithubHelp logo

schollz / aioblescan Goto Github PK

View Code? Open in Web Editor NEW

This project forked from frawau/aioblescan

0.0 3.0 0.0 36 KB

Python only library to scan and decode advertised BLE info. Uses asyncio. Can decode Ruuvi Tag.

License: MIT License

Python 100.00%

aioblescan's Introduction

aioblescan

aioblescan is a Python 3/asyncio library to listen for BLE advertized packets.

Installation

We are on PyPi so

 pip3 install aioblescan

or

 python3 -m pip install aioblescan

How to use

Essentially, you create a function to process the incoming information and you attach it to the BTScanRequester. You then create a Bluetooth connection, you issue the scan command and wait for incoming packets and process them.

You can use Eddystone or RuuviWeather to retrieve specific information

The easiest way is to look at the __main__.py file.

You can run the module with

python3 -m aioblescan

Add -h for help.

To see the RuuviTag weather information try:

python3 -m aioblescan -r

You will get

Weather info {'rssi': -64, 'pressure': 100300, 'temperature': 24, 'mac address': 'fb:86:84:dd:aa:bb', 'tx_power': -7, 'humidity': 36.0}
Weather info {'rssi': -62, 'pressure': 100300, 'temperature': 24, 'mac address': 'fb:86:84:dd:aa:bb', 'tx_power': -7, 'humidity': 36.0}

To check Eddystone beacon

python3 -m aioblescan -e

You get

Google Beacon {'tx_power': -7, 'url': 'https://ruu.vi/#BEgYAMR8n', 'mac address': 'fb:86:84:dd:aa:bb', 'rssi': -52}
Google Beacon {'tx_power': -7, 'url': 'https://ruu.vi/#BEgYAMR8n', 'mac address': 'fb:86:84:dd:aa:bb', 'rssi': -53}

For a generic advertise packet scanning

python3 -m aioblescan

You get

HCI Event:
    code:
        3e
    length:
        19
    LE Meta:
        code:
            02
        Adv Report:
            num reports:
                1
            ev type:
                generic adv
            addr type:
                public
            peer:
                54:6c:0e:aa:bb:cc
            length:
                7
            flags:
                Simul LE - BR/EDR (Host): False
                Simul LE - BR/EDR (Control.): False
                BR/EDR Not Supported: False
                LE General Disc.: True
                LE Limited Disc.: False
            Incomplete uuids:
                    ff:30
            rssi:
                -67
HCI Event:
    code:
        3e
    length:
        43
    LE Meta:
        code:
            02
        Adv Report:
            num reports:
                1
            ev type:
                no connection adv
            addr type:
                random
            peer:
                fb:86:84:dd:aa:bb
            length:
                31
            flags:
                Simul LE - BR/EDR (Host): False
                Simul LE - BR/EDR (Control.): False
                BR/EDR Not Supported: False
                LE General Disc.: True
                LE Limited Disc.: True
            Complete uuids:
                    fe:aa
            Advertised Data:
                Service Data uuid:
                    fe:aa
                Adv Payload:
                    10:f9:03:72:75:75:2e:76:69:2f:23:42:45:77:59:41:4d:52:38:6e
            rssi:
                -59

Here the first packet is from a Wynd device, the second from a Ruuvi Tag

aioblescan can also send EddyStone advertising. Try the -a flag when running the module.

FAQ

Why not use scapy?

Scapy is great and you can do

    import scapy.all as sa
    test=sa.BluetoothHCISocket(0)
    command=sa.HCI_Cmd_LE_Set_Scan_Enable(enable=1,filter_dups=0)
    chdr=sa.HCI_Command_Hdr(len=len(command))
    hdr=sa.HCI_Hdr(type=1)
    test.send(hdr / chdr / command)

to get things going. But... the great thing with Scapy is that there is so
many versions to choose from.... and not all have all the same fuctions ... and
installation can be haphazard, with some version not installing at all. Also
scapy inludes a lot of other protocols and could be an overkill... lastly it
is never too late to learn...

What can you track?

aioblescan will try to parse all the incoming advertized information. You can see
the raw data when it does not know what to do. With Eddystone beacon you can see the
URL, Telemetry and UID

aioblescan's People

Contributors

frawau avatar ukbaz avatar

Watchers

 avatar  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.