forked from frawau/aioblescan
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit e697e71
Showing
7 changed files
with
1,241 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright © 2017 François Wautier | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of this | ||
oftware and associated documentation files (the "Software"), to deal in the Software | ||
without restriction, including without limitation the rights to use, copy, modify, | ||
merge, publish, distribute, sublicense, and/or sell copies of the Software, and to | ||
permit persons to whom the Software is furnished to do so, subject to the following | ||
conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all copies | ||
or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, | ||
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR | ||
PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE | ||
FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT ORxi | ||
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
include *.txt setup.cfg | ||
recursive-include *.txt *.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# 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 crate a bluetooth | ||
connection, you issue the scan command and wait for incoming events. | ||
|
||
You can use EddyStone or RuuviWeather to retrieve specific information | ||
|
||
|
||
The easiest way is to look at the __main__ file. You can run the module wuth | ||
|
||
python3 -m aioblescan | ||
|
||
"-h" for help. | ||
|
||
# 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 some | ||
many versions to choose from.... and not all have all the same fuctions ... and | ||
installation can be haphazard, with some version not installing easely. 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
#!/usr/bin/env python3 | ||
# -*- coding:utf-8 -*- | ||
# | ||
# This application is an example on how to use aioblescan | ||
# | ||
# Copyright (c) 2017 François Wautier | ||
# | ||
# Permission is hereby granted, free of charge, to any person obtaining a copy | ||
# of this software and associated documentation files (the "Software"), to deal | ||
# in the Software without restriction, including without limitation the rights | ||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies | ||
# of the Software, and to permit persons to whom the Software is furnished to do so, | ||
# subject to the following conditions: | ||
# | ||
# The above copyright notice and this permission notice shall be included in all copies | ||
# or substantial portions of the Software. | ||
# | ||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | ||
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR | ||
# IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE | ||
import sys | ||
import asyncio | ||
import argparse | ||
import aioblescan as aiobs | ||
|
||
parser = argparse.ArgumentParser(description="Track BLE advertised packets") | ||
parser.add_argument("-e", "--eddy", action='store_true', default=False, | ||
help="Look specificaly for Eddystone messages.") | ||
parser.add_argument("-r","--ruuvi", action='store_true', default=False, | ||
help="Look only for Ruuvi tag Weather station messages") | ||
try: | ||
opts = parser.parse_args() | ||
except Exception as e: | ||
parser.error("Error: " + str(e)) | ||
sys.exit() | ||
|
||
def my_process(data): | ||
global opts | ||
|
||
ev=HCI_Event() | ||
xx=ev.decode(data) | ||
xx=aiobs.RuuviWeather(ev) | ||
if opts.eddy: | ||
xx=aiobs.EddyStone(ev) | ||
if xx: | ||
print("Google Beacon {}".format(xx)) | ||
elif opts.ruuvi: | ||
if xx: | ||
print("Weather info {}".format(xx)) | ||
else: | ||
ev.show(0) | ||
|
||
try: | ||
mydev=int(sys.argv[1]) | ||
except: | ||
mydev=0 | ||
|
||
|
||
event_loop = asyncio.get_event_loop() | ||
|
||
#First create and configure a raw socket | ||
mysocket = aiobs.create_bt_socket(mydev) | ||
|
||
#create a connection with the raw socket | ||
fac=event_loop.create_connection(BTScanRequester,sock=mysocket) | ||
#Start it | ||
conn,btctrl = event_loop.run_until_complete(fac) | ||
#Attach your processing | ||
btctrl.process=my_process | ||
#Probe | ||
btctrl.request() | ||
try: | ||
# event_loop.run_until_complete(coro) | ||
event_loop.run_forever() | ||
except KeyboardInterrupt: | ||
print('keyboard interrupt') | ||
finally: | ||
print('closing event loop') | ||
conn.close() | ||
event_loop.close() |
Oops, something went wrong.