-
Notifications
You must be signed in to change notification settings - Fork 58
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
Showing
17 changed files
with
235 additions
and
34 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
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
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
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
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
"""Packets supported by the parser.""" | ||
from .eddystone import EddystoneUIDFrame, EddystoneURLFrame, EddystoneEncryptedTLMFrame, \ | ||
EddystoneTLMFrame | ||
from .ibeacon import IBeaconAdvertisement |
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,40 @@ | ||
"""Packet classes for iBeacon beacons.""" | ||
from ..utils import data_to_uuid | ||
|
||
class IBeaconAdvertisement(object): | ||
"""iBeacon advertisement.""" | ||
|
||
def __init__(self, data): | ||
self._uuid = data_to_uuid(data['uuid']) | ||
self._major = data['major'] | ||
self._minor = data['minor'] | ||
self._tx_power = data['tx_power'] | ||
|
||
@property | ||
def tx_power(self): | ||
"""Calibrated Tx power at 0 m.""" | ||
return self._tx_power | ||
|
||
@property | ||
def uuid(self): | ||
"""16-byte uuid.""" | ||
return self._uuid | ||
|
||
@property | ||
def major(self): | ||
"""2-byte major identifier.""" | ||
return self._major | ||
|
||
@property | ||
def minor(self): | ||
"""2-byte minor identifier.""" | ||
return self._minor | ||
|
||
@property | ||
def properties(self): | ||
"""Get beacon properties.""" | ||
return {'uuid': self.uuid, 'major': self.major, 'minor': self.minor} | ||
|
||
def __str__(self): | ||
return "IBeaconAdvertisement<tx_power: %d, uuid: %s, major: %d, minor: %d>" \ | ||
% (self.tx_power, self.uuid, self.major, self.minor) |
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
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
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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
"""Packets supported by the parser.""" | ||
from .eddystone import EddystoneFrame | ||
from .ibeacon import IBeaconAdvertisingPacket |
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,18 @@ | ||
"""All low level structures used for parsing eddystone packets.""" | ||
from construct import Struct, Byte, Const, Int8sl, Array, Int16ub | ||
|
||
from ..const import IBEACON_COMPANY_ID, IBEACON_PROXIMITY_TPYE | ||
|
||
# pylint: disable=invalid-name | ||
|
||
IBeaconAdvertisingPacket = Struct( | ||
"flags" / Const(b"\x02\x01\x06"), | ||
"length" / Const(b"\x1A"), | ||
"type" / Const(b"\xFF"), | ||
"company_id" / Const(IBEACON_COMPANY_ID), | ||
"beacon_type" / Const(IBEACON_PROXIMITY_TPYE), | ||
"uuid" / Array(16, Byte), | ||
"major" / Int16ub, | ||
"minor" / Int16ub, | ||
"tx_power" / Int8sl, | ||
) |
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
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
5 changes: 3 additions & 2 deletions
5
examples/scanner_example.py → examples/scanner_eddystone_example.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
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,13 @@ | ||
import time | ||
from beacontools import BeaconScanner, IBeaconFilter | ||
|
||
def callback(bt_addr, rssi, packet, additional_info): | ||
print("<%s, %d> %s %s" % (bt_addr, rssi, packet, additional_info)) | ||
|
||
# scan for all iBeacon advertisements from beacons with the specified uuid | ||
scanner = BeaconScanner(callback, | ||
device_filter=IBeaconFilter(uuid="e5b9e3a6-27e2-4c36-a257-7698da5fc140") | ||
) | ||
scanner.start() | ||
time.sleep(5) | ||
scanner.stop() |
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
Oops, something went wrong.