コード例 #1
0
 def test_multiple_filters2(self):
     callback = MagicMock()
     scanner = BeaconScanner(
         callback,
         device_filter=[
             EstimoteFilter(identifier="47a038d5eb032640",
                            protocol_version=2),
             EddystoneFilter(instance="000000000001")
         ],
         packet_filter=[EstimoteTelemetryFrameB, EddystoneUIDFrame])
     pkt = b"\x41\x3e\x41\x02\x01\x03\x01\x35\x94\xef\xcd\xd6\x1c\x19\x02\x01\x04\x03\x03\x9a"\
           b"\xfe\x17\x16\x9a\xfe\x22\x47\xa0\x38\xd5\xeb\x03\x26\x40\x01\xff\xff\xff\xff\x49"\
           b"\x25\x66\xbc\x2e\x50\xdd"
     scanner._mon.process_packet(pkt)
     pkt = b"\x41\x3e\x41\x02\x01\x03\x01\x35\x94\xef\xcd\xd6\x1c\x19\x02\x01\x04\x03\x03\x9a"\
           b"\xfe\x17\x16\x9a\xfe\x12\x47\xa0\x38\xd5\xeb\x03\x26\x40\x00\x00\x01\x41\x44\x47"\
           b"\xf0\x01\x00\x00\x00\xdd"
     scanner._mon.process_packet(pkt)
     pkt = b"\x41\x3e\x41\x02\x01\x03\x01\x35\x94\xef\xcd\xd6\x1c\x19\x02\x01\x06\x03\x03\xaa"\
           b"\xfe\x11\x16\xaa\xfe\x00\xe3\x12\x34\x56\x78\x90\x12\x34\x67\x89\x01\x00\x00\x00"\
           b"\x00\x00\x01\x00\x00\xdd"
     scanner._mon.process_packet(pkt)
     pkt = b"\x41\x3e\x41\x02\x01\x03\x01\x35\x94\xef\xcd\xd6\x1c\x19\x02\x01\x06\x03\x03\xaa"\
           b"\xfe\x11\x16\xaa\xfe\x00\xe3\x12\x34\x56\x78\x90\x12\x34\x67\x89\x01\x00\x00\x00"\
           b"\x00\x00\x02\x00\x00\xdd"
     scanner._mon.process_packet(pkt)
     pkt = b"\x41\x3e\x41\x02\x01\x03\x01\x35\x94\xef\xcd\xd6\x1c\x19\x02\x01\x06\x03\x03\xaa"\
           b"\xfe\x11\x16\xaa\xfe\x00\xe3\x12\x34\x56\x78\x90\x12\x34\x67\x89\x01\x00\x00\x00"\
           b"\x00\x00\x01\x00\x00\xdd"
     scanner._mon.process_packet(pkt)
     self.assertEqual(callback.call_count, 3)
コード例 #2
0
 def test_process_packet_estimote_device_filter(self):
     """Test processing of a estimote packet and callback execution with device filter."""
     callback = MagicMock()
     scanner = BeaconScanner(
         callback, device_filter=EstimoteFilter(protocol_version=2))
     pkt = b"\x41\x3e\x41\x02\x01\x03\x01\x35\x94\xef\xcd\xd6\x1c\x19\x02\x01\x04\x03\x03\x9a"\
           b"\xfe\x17\x16\x9a\xfe\x22\x47\xa0\x38\xd5\xeb\x03\x26\x40\x01\xff\xff\xff\xff\x49"\
           b"\x25\x66\xbc\x2e\x50\xdd"
     scanner._mon.process_packet(pkt)
     self.assertEqual(callback.call_count, 1)
     args = callback.call_args[0]
     self.assertEqual(args[0], "1c:d6:cd:ef:94:35")
     self.assertEqual(args[1], -35)
     self.assertIsInstance(args[2], EstimoteTelemetryFrameB)
     self.assertEqual(args[3], {
         "identifier": "47a038d5eb032640",
         "protocol_version": 2
     })
コード例 #3
0
 def test_multiple_filters(self):
     callback = MagicMock()
     scanner = BeaconScanner(
         callback,
         device_filter=EstimoteFilter(protocol_version=2),
         packet_filter=EstimoteTelemetryFrameB)
     pkt = b"\x41\x3e\x41\x02\x01\x03\x01\x35\x94\xef\xcd\xd6\x1c\x19\x02\x01\x04\x03\x03\x9a"\
           b"\xfe\x17\x16\x9a\xfe\x22\x47\xa0\x38\xd5\xeb\x03\x26\x40\x01\xff\xff\xff\xff\x49"\
           b"\x25\x66\xbc\x2e\x50\xdd"
     scanner._mon.process_packet(pkt)
     pkt = b"\x41\x3e\x41\x02\x01\x03\x01\x35\x94\xef\xcd\xd6\x1c\x19\x02\x01\x04\x03\x03\x9a"\
           b"\xfe\x17\x16\x9a\xfe\x12\x47\xa0\x38\xd5\xeb\x03\x26\x40\x00\x00\x01\x41\x44\x47"\
           b"\xf0\x01\x00\x00\x00\xdd"
     scanner._mon.process_packet(pkt)
     pkt = b"\x41\x3e\x41\x02\x01\x03\x01\x35\x94\xef\xcd\xd6\x1c\x19\x02\x01\x06\x03\x03\xaa"\
           b"\xfe\x11\x16\xaa\xfe\x00\xe3\x12\x34\x56\x78\x90\x12\x34\x67\x89\x01\x00\x00\x00"\
           b"\x00\x00\x01\x00\x00\xdd"
     scanner._mon.process_packet(pkt)
     pkt = b"\x41\x3e\x41\x02\x01\x03\x01\x35\x94\xef\xcd\xd6\x1c\x19\x02\x01\x06\x03\x03\xaa"\
           b"\xfe\x11\x16\xaa\xfe\x20\x00\x0b\x18\x13\x00\x00\x00\x14\x67\x00\x00\x2a\xc4\xe4"
     scanner._mon.process_packet(pkt)
     self.assertEqual(callback.call_count, 1)
コード例 #4
0
import time

from beacontools import BeaconScanner, EstimoteTelemetryFrameA, EstimoteTelemetryFrameB, EstimoteFilter


def callback(bt_addr, rssi, packet, additional_info):
    print("<%s, %d> %s %s" % (bt_addr, rssi, packet, additional_info))


# scan for all Estimote telemetry packets from a specific beacon
scanner = BeaconScanner(
    callback,
    packet_filter=[EstimoteTelemetryFrameA, EstimoteTelemetryFrameB],
    # remove the following line to see packets from all beacons
    device_filter=EstimoteFilter(identifier="47a038d5eb032640"))
scanner.start()
time.sleep(10)
scanner.stop()
コード例 #5
0
import time

from beacontools import BeaconScanner, EstimoteFilter


def callback(bt_addr, rssi, packet, additional_info):
    print("<%s, %d> %s %s" % (bt_addr, rssi, packet, additional_info))


scanner = BeaconScanner(
    callback, device_filter=EstimoteFilter(identifier="1efe427eb6f4bc2f"))
scanner.start()
time.sleep(10)
scanner.stop()