import decode_beacon
import struct

# BlueZ message with 1 iBeacon advertisement
bz1 = ''.join([chr(int(c, 16)) for c in ("""04 3E 2A 02 01 03 00 EC F8 00 EE F3 0C 1E 02 01
04 1A FF 4C 00 02 15 8D EE FB B9 F7 38 42 97 80
40 96 66 8B B4 42 81 13 88 0F 4E C1 BB""".split())])
print decode_beacon.bluez_decode_beacons(bz1)

# BlueZ message with 2 iBeacon advertisements, the second without flags
bz2 = ''.join([chr(int(c, 16)) for c in ("""04 3E 4F 02 02
03 00 EC F8 00 EE F3 0C 1E 02 01
04 1A FF 4C 00 02 15 8D EE FB B9 F7 38 42 97 80
40 96 66 8B B4 42 81 13 88 0F 4E C1 BB
03 00 EC F8 00 EE F3 0D 1B
1A FF 4C 00 02 15 8D EE FB B9 F7 38 42 97 80
40 96 66 8B B4 42 81 13 88 0F 4F C1 B0
""".split())])

# BlueZ message with 1 iBeacon and 1 AltBeacon advertisement
print decode_beacon.bluez_decode_beacons(bz2)
bz3 = ''.join([chr(int(c, 16)) for c in ("""04 3E 50 02 02
03 00 EC F8 00 EE F3 0C 1E 02 01
04 1A FF 4C 00 02 15 8D EE FB B9 F7 38 42 97 80
40 96 66 8B B4 42 81 13 88 0F 4E C1 BB
03 00 EC F8 00 EE F3 0D 1C
1B FF 44 01 BE AC 8D EE FB B9 F7 38 42 97 80
40 96 66 8B B4 42 81 13 88 0F 4F C1 55
B1
""".split())])
print decode_beacon.bluez_decode_beacons(bz3)
示例#2
0
OGF_LE_CTL = 0x08
OCF_LE_SET_SCAN_ENABLE = 0x000C

try:
  # Open the bluetooth device
  sock = bluez.hci_open_dev(0)
  print "BLE scan started"
except:
  # Failed to open
  sock = None
  print "Failed to open BLE device."

if sock:
  # We have device access, start BLE scan
  cmd_pkt = struct.pack("<BB", 0x01, 0x00)
  bluez.hci_send_cmd(sock, OGF_LE_CTL, OCF_LE_SET_SCAN_ENABLE, cmd_pkt)
  # Loop
  while True:
    # Save the current filter setting
    old_filter = sock.getsockopt(bluez.SOL_HCI, bluez.HCI_FILTER, 14)
    # Set filter for getting HCI events
    flt = bluez.hci_filter_new()
    bluez.hci_filter_all_events(flt)
    bluez.hci_filter_set_ptype(flt, bluez.HCI_EVENT_PKT)
    sock.setsockopt(bluez.SOL_HCI, bluez.HCI_FILTER, flt)
    # Get and decode data
    print decode_beacon.bluez_decode_beacons(sock.recv(255))
    # Restore the filter setting
    sock.setsockopt(bluez.SOL_HCI, bluez.HCI_FILTER, old_filter)

示例#3
0
OGF_LE_CTL = 0x08
OCF_LE_SET_SCAN_ENABLE = 0x000C

try:
    # Open the bluetooth device
    sock = bluez.hci_open_dev(0)
    print "BLE scan started"
except:
    # Failed to open
    sock = None
    print "Failed to open BLE device."

if sock:
    # We have device access, start BLE scan
    cmd_pkt = struct.pack("<BB", 0x01, 0x00)
    bluez.hci_send_cmd(sock, OGF_LE_CTL, OCF_LE_SET_SCAN_ENABLE, cmd_pkt)
    # Loop
    while True:
        # Save the current filter setting
        old_filter = sock.getsockopt(bluez.SOL_HCI, bluez.HCI_FILTER, 14)
        # Set filter for getting HCI events
        flt = bluez.hci_filter_new()
        bluez.hci_filter_all_events(flt)
        bluez.hci_filter_set_ptype(flt, bluez.HCI_EVENT_PKT)
        sock.setsockopt(bluez.SOL_HCI, bluez.HCI_FILTER, flt)
        # Get and decode data
        print decode_beacon.bluez_decode_beacons(sock.recv(255))
        # Restore the filter setting
        sock.setsockopt(bluez.SOL_HCI, bluez.HCI_FILTER, old_filter)
示例#4
0
import decode_beacon
import struct

print "BlueZ message with 1 iBeacon advertisement"
bz1 = ''.join([
    chr(int(c, 16)) for c in ("""
04 3E 2A 02 01 03 00 EC F8 00 EE F3 0C 1E 02 01
04 1A FF 4C 00 02 15 8D EE FB B9 F7 38 42 97 80
40 96 66 8B B4 42 81 13 88 0F 4E C1 BB""".split())
])
print decode_beacon.bluez_decode_beacons(bz1)

print "BlueZ message with 2 iBeacon advertisements, the second without flags"
bz2 = ''.join([
    chr(int(c, 16)) for c in ("""
04 3E 4F 02 02
03 00 EC F8 00 EE F3 0C 1E 02 01
04 1A FF 4C 00 02 15 8D EE FB B9 F7 38 42 97 80
40 96 66 8B B4 42 81 13 88 0F 4E C1 BB
03 00 EC F8 00 EE F3 0D 1B
1A FF 4C 00 02 15 8D EE FB B9 F7 38 42 97 80
40 96 66 8B B4 42 81 13 88 0F 4F C1 B0
""".split())
])
print decode_beacon.bluez_decode_beacons(bz2)

print "BlueZ message with 1 iBeacon and 1 AltBeacon advertisement"
bz3 = ''.join([
    chr(int(c, 16)) for c in ("""
04 3E 50 02 02
03 00 EC F8 00 EE F3 0C 1E 02 01
示例#5
0
try:
  # Open the bluetooth device
  sock = bluez.hci_open_dev(0)
  print("BLE scan started")
except:
  # Failed to open
  sock = None
  print("Failed to open BLE device.")

if sock:
  # We have device access, start BLE scan
  cmd_pkt = struct.pack("<BB", 0x01, 0x00)
  bluez.hci_send_cmd(sock, OGF_LE_CTL, OCF_LE_SET_SCAN_ENABLE, cmd_pkt)
  # Loop
  while True:
    # Save the current filter setting
    old_filter = sock.getsockopt(bluez.SOL_HCI, bluez.HCI_FILTER, 14)
    # Set filter for getting HCI events
    flt = bluez.hci_filter_new()
    bluez.hci_filter_all_events(flt)
    bluez.hci_filter_set_ptype(flt, bluez.HCI_EVENT_PKT)
    sock.setsockopt(bluez.SOL_HCI, bluez.HCI_FILTER, flt)
    # Get and decode data
    beacondata = decode_beacon.bluez_decode_beacons(sock.recv(255))
    if beacondata or not SUPPRESS_EMPTY_OUTPUT:
      print(beacondata)
    # Restore the filter setting
    sock.setsockopt(bluez.SOL_HCI, bluez.HCI_FILTER, old_filter)