Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
frawau committed Jun 24, 2017
0 parents commit e697e71
Show file tree
Hide file tree
Showing 7 changed files with 1,241 additions and 0 deletions.
20 changes: 20 additions & 0 deletions LICENSE.txt
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.
2 changes: 2 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
include *.txt setup.cfg
recursive-include *.txt *.py
54 changes: 54 additions & 0 deletions README.md
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
83 changes: 83 additions & 0 deletions aioblescan/__main__.py
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()
Loading

0 comments on commit e697e71

Please sign in to comment.