aioblescan
==========
aioblescan is a Python 3/asyncio library to listen for BLE advertized
packets.
|PyPI version fury.io| |MIT license| |GITHUB-BADGE| |Downloads|
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 command:
::
aioblescan
or 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}
To check ATC_MiThermometer with `custom
firmware <https://github.com/atc1441/ATC_MiThermometer>`__ beacon
::
python3 -m aioblescan -A
You get
::
Temperature info {'mac address': 'a4:c1:38:40:52:38', 'temperature': 2.8, 'humidity': 62, 'battery': 72, 'battery_volts': 2.863, 'counter': 103, 'rssi': -76}
Temperature info {'mac address': 'a4:c1:38:40:52:38', 'temperature': 2.8, 'humidity': 62, 'battery': 72, 'battery_volts': 2.863, 'counter': 103, 'rssi': -77}
To check ThermoBeacon sensors
::
python3 -m aioblescan -T
You get
::
Temperature info {'mac address': '19:c4:00:00:0f:5d', 'max_temperature': 27.0625, 'min_temperature': 21.75, 'max_temp_ts': 0, 'min_temp_ts': 2309}
Temperature info {'mac address': '19:c4:00:00:0f:5d', 'temperature': 21.75, 'humidity': 49.5, 'battery_volts': 3234, 'counter': 2401, 'rssi': -67}
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.
To check Tilt hydrometer
::
python3 -m aioblescan --tilt
You will see the regular Bluetooth beacons from any Tilt in range:
::
{"uuid": "a495bb40c5b14b44b5121370f02d74de", "major": 70, "minor": 1054, "tx_power": 31, "rssi": -58, "mac": "xx:xx:xx:xx:xx:xx"}
{"uuid": "a495bb40c5b14b44b5121370f02d74de", "major": 70, "minor": 1054, "tx_power": 31, "rssi": -74, "mac": "xx:xx:xx:xx:xx:xx"}
{"uuid": "a495bb40c5b14b44b5121370f02d74de", "major": 70, "minor": 1054, "tx_power": 31, "rssi": -57, "mac": "xx:xx:xx:xx:xx:xx"}
Hit ``ctrl-c`` to stop the scan.
Interpreting the Tilt Data
--------------------------
The information from the tilt plugin is returned as a valid JSON:
::
{
"uuid": "a495bb40c5b14b44b5121370f02d74de",
"major": 69,
"minor": 1056,
"tx_power": 31,
"rssi": -49,
"mac": "xx:xx:xx:xx:xx:xx"
}
These keys may be interpreted as:
- **uuid**: Tilt name. The "40" in
a495bb\ ``40``\ c5b14b44b5121370f02d74de is an indication of the
color.
- 10: Red
- 20: Green
- 30: Black
- 40: Purple
- 50: Orange
- 60: Blue
- 70: Yellow
- 80: Pink
- **major**: Temp in degrees F.
- **minor**: Specific gravity x1000.
- **tx_power**: Weeks since battery change (0-152 when converted to
unsigned 8 bit integer). You will occasionally see ``-59`` which is
there to allow iOS to compute RSSI. This value should be discarded.
- **rssi**: Received Signal Strength Indication (RSSI) is a measurement
of the power present in the received radio signal. A lower negative
number is stronger.
- **mac**: Media Access Control (MAC) address of the device.
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 functions ... 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 advertised 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
.. |PyPI version fury.io| image:: https://badge.fury.io/py/aioblescan.svg
:target: https://pypi.python.org/pypi/aioblescan
.. |MIT license| image:: https://img.shields.io/badge/License-MIT-blue.svg
:target: https://lbesson.mit-licen
.. |GITHUB-BADGE| image:: https://github.com/frawau/aioblescan/workflows/black/badge.svg
:target: https://github.com/psf/black
.. |Downloads| image:: https://pepy.tech/badge/aioblescan/month
:target: https://pepy.tech/project/aioblescan
Raw data
{
"_id": null,
"home_page": "http://github.com/frawau/aioblescan",
"name": "aioblescan",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "bluetooth,advertising,hci,ble",
"author": "Fran\u00e7ois Wautier",
"author_email": "francois@wautier.eu",
"download_url": "https://files.pythonhosted.org/packages/45/15/faf503083bc5a2d81f1b17fbbe30d15f35217b6c5e944c771c8760354d59/aioblescan-0.2.14.tar.gz",
"platform": null,
"description": "aioblescan\n==========\n\naioblescan is a Python 3/asyncio library to listen for BLE advertized\npackets.\n\n|PyPI version fury.io| |MIT license| |GITHUB-BADGE| |Downloads|\n\nInstallation\n------------\n\nWe are on PyPi so\n\n::\n\n pip3 install aioblescan\n\nor\n\n::\n\n python3 -m pip install aioblescan\n\nHow to use\n----------\n\nEssentially, you create a function to process the incoming information\nand you attach it to the ``BTScanRequester``. You then create a\nBluetooth connection, you issue the scan command and wait for incoming\npackets and process them.\n\nYou can use Eddystone or RuuviWeather to retrieve specific information\n\nThe easiest way is to look at the ``__main__.py`` file.\n\nYou can run the command:\n\n::\n\n aioblescan\n\nor you can run the module with\n\n::\n\n python3 -m aioblescan\n\nAdd ``-h`` for help.\n\nTo see the RuuviTag weather information try:\n\n::\n\n python3 -m aioblescan -r\n\nYou will get\n\n::\n\n Weather info {'rssi': -64, 'pressure': 100300, 'temperature': 24, 'mac address': 'fb:86:84:dd:aa:bb', 'tx_power': -7, 'humidity': 36.0}\n Weather info {'rssi': -62, 'pressure': 100300, 'temperature': 24, 'mac address': 'fb:86:84:dd:aa:bb', 'tx_power': -7, 'humidity': 36.0}\n\nTo check Eddystone beacon\n\n::\n\n python3 -m aioblescan -e\n\nYou get\n\n::\n\n Google Beacon {'tx_power': -7, 'url': 'https://ruu.vi/#BEgYAMR8n', 'mac address': 'fb:86:84:dd:aa:bb', 'rssi': -52}\n Google Beacon {'tx_power': -7, 'url': 'https://ruu.vi/#BEgYAMR8n', 'mac address': 'fb:86:84:dd:aa:bb', 'rssi': -53}\n\nTo check ATC_MiThermometer with `custom\nfirmware <https://github.com/atc1441/ATC_MiThermometer>`__ beacon\n\n::\n\n python3 -m aioblescan -A\n\nYou get\n\n::\n\n Temperature info {'mac address': 'a4:c1:38:40:52:38', 'temperature': 2.8, 'humidity': 62, 'battery': 72, 'battery_volts': 2.863, 'counter': 103, 'rssi': -76}\n Temperature info {'mac address': 'a4:c1:38:40:52:38', 'temperature': 2.8, 'humidity': 62, 'battery': 72, 'battery_volts': 2.863, 'counter': 103, 'rssi': -77}\n\nTo check ThermoBeacon sensors\n\n::\n\n python3 -m aioblescan -T\n\nYou get\n\n::\n\n Temperature info {'mac address': '19:c4:00:00:0f:5d', 'max_temperature': 27.0625, 'min_temperature': 21.75, 'max_temp_ts': 0, 'min_temp_ts': 2309}\n Temperature info {'mac address': '19:c4:00:00:0f:5d', 'temperature': 21.75, 'humidity': 49.5, 'battery_volts': 3234, 'counter': 2401, 'rssi': -67}\n\nFor a generic advertise packet scanning\n\n::\n\n python3 -m aioblescan\n\nYou get\n\n::\n\n HCI Event:\n code:\n 3e\n length:\n 19\n LE Meta:\n code:\n 02\n Adv Report:\n num reports:\n 1\n ev type:\n generic adv\n addr type:\n public\n peer:\n 54:6c:0e:aa:bb:cc\n length:\n 7\n flags:\n Simul LE - BR/EDR (Host): False\n Simul LE - BR/EDR (Control.): False\n BR/EDR Not Supported: False\n LE General Disc.: True\n LE Limited Disc.: False\n Incomplete uuids:\n ff:30\n rssi:\n -67\n HCI Event:\n code:\n 3e\n length:\n 43\n LE Meta:\n code:\n 02\n Adv Report:\n num reports:\n 1\n ev type:\n no connection adv\n addr type:\n random\n peer:\n fb:86:84:dd:aa:bb\n length:\n 31\n flags:\n Simul LE - BR/EDR (Host): False\n Simul LE - BR/EDR (Control.): False\n BR/EDR Not Supported: False\n LE General Disc.: True\n LE Limited Disc.: True\n Complete uuids:\n fe:aa\n Advertised Data:\n Service Data uuid:\n fe:aa\n Adv Payload:\n 10:f9:03:72:75:75:2e:76:69:2f:23:42:45:77:59:41:4d:52:38:6e\n rssi:\n -59\n\nHere the first packet is from a Wynd device, the second from a Ruuvi Tag\n\naioblescan can also send EddyStone advertising. Try the -a flag when\nrunning the module.\n\nTo check Tilt hydrometer\n\n::\n\n python3 -m aioblescan --tilt\n\nYou will see the regular Bluetooth beacons from any Tilt in range:\n\n::\n\n {\"uuid\": \"a495bb40c5b14b44b5121370f02d74de\", \"major\": 70, \"minor\": 1054, \"tx_power\": 31, \"rssi\": -58, \"mac\": \"xx:xx:xx:xx:xx:xx\"}\n {\"uuid\": \"a495bb40c5b14b44b5121370f02d74de\", \"major\": 70, \"minor\": 1054, \"tx_power\": 31, \"rssi\": -74, \"mac\": \"xx:xx:xx:xx:xx:xx\"}\n {\"uuid\": \"a495bb40c5b14b44b5121370f02d74de\", \"major\": 70, \"minor\": 1054, \"tx_power\": 31, \"rssi\": -57, \"mac\": \"xx:xx:xx:xx:xx:xx\"}\n\nHit ``ctrl-c`` to stop the scan.\n\nInterpreting the Tilt Data\n--------------------------\n\nThe information from the tilt plugin is returned as a valid JSON:\n\n::\n\n {\n \"uuid\": \"a495bb40c5b14b44b5121370f02d74de\",\n \"major\": 69,\n \"minor\": 1056,\n \"tx_power\": 31,\n \"rssi\": -49,\n \"mac\": \"xx:xx:xx:xx:xx:xx\"\n }\n\nThese keys may be interpreted as:\n\n- **uuid**: Tilt name. The \"40\" in\n a495bb\\ ``40``\\ c5b14b44b5121370f02d74de is an indication of the\n color.\n\n - 10: Red\n - 20: Green\n - 30: Black\n - 40: Purple\n - 50: Orange\n - 60: Blue\n - 70: Yellow\n - 80: Pink\n\n- **major**: Temp in degrees F.\n- **minor**: Specific gravity x1000.\n- **tx_power**: Weeks since battery change (0-152 when converted to\n unsigned 8 bit integer). You will occasionally see ``-59`` which is\n there to allow iOS to compute RSSI. This value should be discarded.\n- **rssi**: Received Signal Strength Indication (RSSI) is a measurement\n of the power present in the received radio signal. A lower negative\n number is stronger.\n- **mac**: Media Access Control (MAC) address of the device.\n\nFAQ\n---\n\nWhy not use scapy?\n\n::\n\n Scapy is great and you can do\n\n import scapy.all as sa\n test=sa.BluetoothHCISocket(0)\n command=sa.HCI_Cmd_LE_Set_Scan_Enable(enable=1,filter_dups=0)\n chdr=sa.HCI_Command_Hdr(len=len(command))\n hdr=sa.HCI_Hdr(type=1)\n test.send(hdr / chdr / command)\n\n to get things going. But... the great thing with Scapy is that there is so\n many versions to choose from.... and not all have all the same functions ... and\n installation can be haphazard, with some version not installing at all. Also\n scapy inludes a lot of other protocols and could be an overkill... lastly it\n is never too late to learn...\n\nWhat can you track?\n\n::\n\n aioblescan will try to parse all the incoming advertised information. You can see\n the raw data when it does not know what to do. With Eddystone beacon you can see the\n URL, Telemetry and UID\n\n.. |PyPI version fury.io| image:: https://badge.fury.io/py/aioblescan.svg\n :target: https://pypi.python.org/pypi/aioblescan\n.. |MIT license| image:: https://img.shields.io/badge/License-MIT-blue.svg\n :target: https://lbesson.mit-licen\n.. |GITHUB-BADGE| image:: https://github.com/frawau/aioblescan/workflows/black/badge.svg\n :target: https://github.com/psf/black\n.. |Downloads| image:: https://pepy.tech/badge/aioblescan/month\n :target: https://pepy.tech/project/aioblescan\n\n\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Scanning Bluetooth for advertised info with asyncio.",
"version": "0.2.14",
"split_keywords": [
"bluetooth",
"advertising",
"hci",
"ble"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "2a4cb8e1a16c5baf299b540dd4a21c1b804651d9d7a1b2f459557d94f16c2baa",
"md5": "db33a019601d0315a99d0d2bf40be225",
"sha256": "1e38977bc207f658ac1e21db21a58e941ba9da6c362a889f4113d80e1cf86fbd"
},
"downloads": -1,
"filename": "aioblescan-0.2.14-py3-none-any.whl",
"has_sig": false,
"md5_digest": "db33a019601d0315a99d0d2bf40be225",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 27862,
"upload_time": "2023-01-07T10:02:00",
"upload_time_iso_8601": "2023-01-07T10:02:00.015481Z",
"url": "https://files.pythonhosted.org/packages/2a/4c/b8e1a16c5baf299b540dd4a21c1b804651d9d7a1b2f459557d94f16c2baa/aioblescan-0.2.14-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "4515faf503083bc5a2d81f1b17fbbe30d15f35217b6c5e944c771c8760354d59",
"md5": "10014cfd24b8f9f54099bbf7e2ea528a",
"sha256": "3a47c5292186ee87fc49cb076a5271c766510f44749b93ac4a32bbb4cb5258a0"
},
"downloads": -1,
"filename": "aioblescan-0.2.14.tar.gz",
"has_sig": false,
"md5_digest": "10014cfd24b8f9f54099bbf7e2ea528a",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 24937,
"upload_time": "2023-01-07T10:02:02",
"upload_time_iso_8601": "2023-01-07T10:02:02.157868Z",
"url": "https://files.pythonhosted.org/packages/45/15/faf503083bc5a2d81f1b17fbbe30d15f35217b6c5e944c771c8760354d59/aioblescan-0.2.14.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-01-07 10:02:02",
"github": true,
"gitlab": false,
"bitbucket": false,
"github_user": "frawau",
"github_project": "aioblescan",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "aioblescan"
}