skip to Main Content

I am having acceleration sensors provided by a business partner which are sending about 20 BLE advertisements per second when being triggered.
I installed Bluez 5.66 and I am running a pydbus app which is dervied from this post
Active BLE Scanning (BlueZ) – Issue with DBus

Btw thanks to @uKbaz and all of his tutorials on that topic.

import argparse
from gi.repository import GLib
from pydbus import SystemBus
import datetime

DEVICE_INTERFACE = 'org.bluez.Device1'

remove_list = set()

def stop_scan():
    """Stop device discovery and quit event loop"""
    adapter.StopDiscovery()
    mainloop.quit()

def on_iface_added(owner, path, iface, signal, interfaces_and_properties):
    """
    Event handler for D-Bus interface added.
    Test to see if it is a new Bluetooth device
    """
    iface_path, iface_props = interfaces_and_properties
    if DEVICE_INTERFACE in iface_props:
        on_device_found(iface_path, iface_props[DEVICE_INTERFACE])

def on_properties_changed(owner, path, iface, signal, interfaces_and_properties):
    """
    Event handler for D-Bus interface properties changed.
    Manufacturing data or Service Data change
    """
    iface_path, iface_props, leftover = interfaces_and_properties
    if DEVICE_INTERFACE in interfaces_and_properties:
        on_device_found(path, iface_props)

def on_device_found(device_path, device_props):
    """
    Handle new Bluetooth device being discover.
    If it is a beacon of type iBeacon, Eddystone, AltBeacon
    then process it
    """
    address = device_props.get('Address')
    
    address_type = device_props.get('AddressType')
    name = device_props.get('Name')
    alias = device_props.get('Alias')
    paired = device_props.get('Paired')
    trusted = device_props.get('Trusted')
    rssi = device_props.get('RSSI')
    service_data = device_props.get('ServiceData')
    manufacturer_data = device_props.get('ManufacturerData')
    
    if address == 'D7:6F:3F:5E:F4:BF' or "D7_6F_3F_5E_F4_BF" in device_path:
    
        print(str(datetime.datetime.now()) + " MAC: " + str(address) + 
              " RSSI:" + str(rssi) + " MData:" + str(manufacturer_data))
        adapter.RemoveDevice(device_path)

if __name__ == '__main__':
    parser = argparse.ArgumentParser()
    parser.add_argument('-d', '--duration', type=int, default=0,
                        help='Duration of scan [0 for continuous]')
    args = parser.parse_args()
    bus = SystemBus()
    adapter = bus.get('org.bluez', '/org/bluez/hci0')
    #adapter = bus.get('org.bluez', '/org/bluez/hci1')
    bus.subscribe(iface='org.freedesktop.DBus.ObjectManager',
                  signal='InterfacesAdded',
                  signal_fired=on_iface_added)
    
    # bus.subscribe(iface='org.freedesktop.DBus.Properties',
    #               signal='PropertiesChanged',
    #               signal_fired=on_properties_changed)

    mainloop = GLib.MainLoop()

    if args.duration > 0:
        GLib.timeout_add_seconds(args.duration, stop_scan)
    adapter.SetDiscoveryFilter({'DuplicateData': GLib.Variant.new_boolean(True), 
                                "Transport":GLib.Variant.new_string("le")})
    
    adapter.StartDiscovery()

    try:
        print('ntUse CTRL-C to stop discoveryn')
        mainloop.run()
    except KeyboardInterrupt:
        stop_scan()

The app is scanning for new devices.
If a new device was found it is grabbing relevant data and removes the device from the devices list of the adapter so that it can be discovered again.
Generally the app works but I am only seeing one advertisement each 9-12 seconds which is by far too less.

Here is the latest output being split in timestamp, rssi, MAC and manufactruing data.
The first byte is a checksum, followed by an ID byte which is always 108 (0x6C) and a type byte which is always 5 (0x05) in my case.
The next four bytes are quite interesting because they represent the sent advertisement count since startup. As one can see I am missing of about 180..220 telegrams between two discoveries.

2023-12-14 12:29:43.101505 MAC: D7:6F:3F:5E:F4:BF RSSI:-42 MData:{22272: [4, 108, 5, 0, 0, 135, 40, 255, 6, 91, 219, 250, 26, 113, 63, 208, 95, 198, 254, 145, 167, 63, 252, 8, 61, 44, 64]}
2023-12-14 12:29:52.786266 MAC: D7:6F:3F:5E:F4:BF RSSI:-50 MData:{62720: [172, 108, 5, 0, 0, 135, 228, 6, 244, 242, 147, 225, 202, 207, 177, 231, 113, 8, 69, 128, 139, 156, 1, 191, 159, 180, 64]}
2023-12-14 12:30:03.416085 MAC: D7:6F:3F:5E:F4:BF RSSI:-54 MData:{46336: [155, 108, 5, 0, 0, 136, 178, 23, 254, 79, 104, 76, 238, 62, 128, 39, 134, 13, 60, 204, 68, 50, 229, 175, 192, 148, 64]}
2023-12-14 12:30:15.044914 MAC: D7:6F:3F:5E:F4:BF RSSI:-46 MData:{19712: [183, 108, 5, 0, 0, 137, 148, 255, 78, 78, 84, 9, 52, 187, 96, 8, 222, 234, 64, 19, 115, 152, 0, 13, 222, 72, 64]}
2023-12-14 12:30:25.915247 MAC: D7:6F:3F:5E:F4:BF RSSI:-42 MData:{57856: [63, 108, 5, 0, 0, 138, 104, 43, 102, 106, 174, 150, 40, 251, 252, 20, 128, 245, 178, 191, 247, 116, 194, 65, 222, 208, 64]}
2023-12-14 12:30:47.678187 MAC: D7:6F:3F:5E:F4:BF RSSI:-42 MData:{21504: [48, 108, 5, 0, 0, 140, 15, 0, 192, 220, 0, 5, 2, 47, 240, 20, 7, 190, 191, 160, 55, 8, 1, 127, 107, 188, 64]}
2023-12-14 12:30:58.415692 MAC: D7:6F:3F:5E:F4:BF RSSI:-52 MData:{43776: [37, 108, 5, 0, 0, 140, 223, 62, 128, 238, 232, 244, 19, 191, 227, 192, 28, 214, 77, 16, 223, 152, 46, 2, 78, 168, 64]}
2023-12-14 12:31:20.841068 MAC: D7:6F:3F:5E:F4:BF RSSI:-50 MData:{36352: [96, 108, 5, 0, 0, 142, 148, 210, 191, 112, 95, 76, 253, 1, 205, 91, 240, 1, 53, 160, 8, 13, 214, 63, 192, 76, 64]}

Firstly I thought maybe the scan window and/or interval need to be adapted but they are both set to 11,250ms which should lead to a continous scanning.
One thing I would like to test is changing the scan type to passiv which maybe could accelerate the discovering process but I couldnt find any function in the bluez docs to set it.
https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/doc

I also tried to keep the device once found and just check for PropertyChanges onwards which shall be triggered whenever manufacturer or service data is discovered (if I interprete the docs correctly). But it doesnt help either.
https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/doc/org.bluez.Adapter.rst

:bool DuplicateData (Default true):

        Disables duplicate detection of advertisement data.

        When enabled PropertiesChanged signals will be generated for
        either ManufacturerData and ServiceData everytime they are
        discovered.

Is it maybe a matter of hardware?
I have connected two BT dongles where only the first is used.
One dongle is from TP Link and one is from Asus but both are using the realtek chipset RTL8761B.

Does one of you have any further idea of how to catch more of the telegrams?
I know it wont be possible to catch all of them but maybe 80-90% would be perfect.

Many thanks to you!

++++++++ 1.EDIT ++++++++++++++++

Application log of Martijns code
here it can be seen that again only every ~10th second a telegram is recognized. Even though approx 200 telegrams have been sent in between when looking at the advertising count (see bytes #4..#7).

2024-01-11 07:30:55.881851 D7:6F:3F:5E:F4:BF RSSI:-50 MData:{23808: 137, 108, 5, 0, 0, 1, 190, 235, 205, 205, 171, 108, 25, 177, 157, 184, 76, 176, 122, 33, 195, 71, 234, 135, 205, 184, 64]}
2024-01-11 07:31:06.569596 D7:6F:3F:5E:F4:BF RSSI:-46 MData:{23552: [1, 108, 5, 0, 0, 2, 142, 255, 65, 124, 11, 248, 250, 50, 48, 99, 240, 210, 191, 61, 203, 87, 192, 201, 7, 252, 64]}
2024-01-11 07:31:17.409213 D7:6F:3F:5E:F4:BF RSSI:-54 MData:{768: [135, 108, 5, 0, 0, 3, 97, 0, 128, 172, 19, 250, 2, 176, 208, 207, 87, 194, 129, 158, 35, 10, 0, 95, 155, 160, 64]}
2024-01-11 07:31:28.438638 D7:6F:3F:5E:F4:BF RSSI:-50 MData:{15360: [31, 108, 5, 0, 0, 4, 55, 245, 70, 181, 172, 8, 7, 79, 240, 128, 111, 71, 128, 146, 37, 61, 7, 69, 242, 16, 64]}
2024-01-11 07:31:39.619840 D7:6F:3F:5E:F4:BF RSSI:-60 MData:{39680: [80, 108, 5, 0, 0, 5, 17, 26, 131, 220, 235, 111, 247, 237, 191, 227, 165, 185, 252, 240, 82, 220, 251, 194, 91, 232, 64]}

I had a look again to btmon in parallel. As I mentioned in my previous answer it seems that the device is only recognized again after discovering is restarted. And it obviously restarts every ~10 seconds which correlates to the application log. Check the time in seconds on the far right of the log.
So whenever the "device found" entry comes 7-10 seconds nothing happens. Then discovering is stopped and started again. After that the "device found" entry comes again.

= Note: Linux version 4.19.94 (aarch64)                                                    0.290215
= Note: Bluetooth subsystem version 2.22                                                   0.290224
= New Index: E8:48:B8:C8:20:00 (Primary,USB,hci1)                                   [hci1] 0.290227
= Open Index: E8:48:B8:C8:20:00                                                     [hci1] 0.290229
= Index Info: E8:48:B8:C8:20:00 (Realtek Semiconductor Corporation)                 [hci1] 0.290231
= New Index: 08:BF:B8:53:93:6F (Primary,USB,hci0)                                   [hci0] 0.290233
= Open Index: 08:BF:B8:53:93:6F                                                     [hci0] 0.290236
= Index Info: 08:BF:B8:53:93:6F (Realtek Semiconductor Corporation)                 [hci0] 0.290237
@ MGMT Open: bluetoothd (privileged) version 1.14                                 {0x0001} 0.290240
@ MGMT Command: Start Service Discovery (0x003a) plen 4                   {0x0001} [hci0] 19.365331
        Address type: 0x06
          LE Public
          LE Random
        RSSI: -100 dBm (0x9c)
        UUIDs: 0
< HCI Command: LE Set Random Address (0x08|0x0005) plen 6                       #1 [hci0] 19.370021
        Address: 22:B5:FC:0E:6F:36 (Non-Resolvable)
> HCI Event: Command Complete (0x0e) plen 4                                     #2 [hci0] 19.371953
      LE Set Random Address (0x08|0x0005) ncmd 2
        Status: Success (0x00)
< HCI Command: LE Set Extended Scan Parameters (0x08|0x0041) plen 8             #3 [hci0] 19.372013
        Own address type: Random (0x01)
        Filter policy: Accept all advertisement (0x00)
        PHYs: 0x01
        Entry 0: LE 1M
          Type: Active (0x01)
          Interval: 11.250 msec (0x0012)
          Window: 11.250 msec (0x0012)
> HCI Event: Command Complete (0x0e) plen 4                                     #4 [hci0] 19.373949
      LE Set Extended Scan Parameters (0x08|0x0041) ncmd 2
        Status: Success (0x00)
< HCI Command: LE Set Extended Scan Enable (0x08|0x0042) plen 6                 #5 [hci0] 19.373997
        Extended scan: Enabled (0x01)
        Filter duplicates: Enabled (0x01)
        Duration: 0 msec (0x0000)
        Period: 0.00 sec (0x0000)
> HCI Event: Command Complete (0x0e) plen 4                                     #6 [hci0] 19.375948
      LE Set Extended Scan Enable (0x08|0x0042) ncmd 2
        Status: Success (0x00)
@ MGMT Event: Command Complete (0x0001) plen 4                            {0x0001} [hci0] 19.376008
      Start Service Discovery (0x003a) plen 1
        Status: Success (0x00)
        Address type: 0x06
          LE Public
          LE Random
@ MGMT Event: Discovering (0x0013) plen 2                                 {0x0001} [hci0] 19.376023
        Address type: 0x06
          LE Public
          LE Random
        Discovery: Enabled (0x01)
> HCI Event: LE Meta Event (0x3e) plen 57                                       #7 [hci0] 22.322688
      LE Extended Advertising Report (0x0d)
        Num reports: 1
        Entry 0
          Event type: 0x0010
            Props: 0x0010
              Use legacy advertising PDUs
            Data status: Complete
          Legacy PDU Type: ADV_NONCONN_IND (0x0010)
          Address type: Random (0x01)
          Address: D7:6F:3F:5E:F4:BF (Static)
          Primary PHY: LE 1M
          Secondary PHY: No packets
          SID: no ADI field (0xff)
          TX power: 127 dBm
          RSSI: -40 dBm (0xd8)
          Periodic advertising interval: 0.00 msec (0x0000)
          Direct address type: Public (0x00)
          Direct address: 00:00:00:00:00:00 (OUI 00-00-00)
          Data length: 0x1f
        1e ff 00 8b 6e 6c 05 00 00 01 18 07 3c 90 97 f4  ....nl......<..
        fe bf 61 9c 74 87 ff d2 27 14 fd 7e 4b e4 40     ..a.t.....~K.@
        Company: not assigned (35584)
          Data: 6e6c0500000118073c9097f4febf619c7487ffd22714fd7e4be440
@ MGMT Event: Device Found (0x0012) plen 45                               {0x0001} [hci0] 22.322765
        LE Address: D7:6F:3F:5E:F4:BF (Static)
        RSSI: -40 dBm (0xd8)
        Flags: 0x00000004
          Not Connectable
        Data length: 31
        Company: not assigned (35584)
          Data: 6e6c0500000118073c9097f4febf619c7487ffd22714fd7e4be440
< HCI Command: LE Set Extended Scan Enable (0x08|0x0042) plen 6                 #8 [hci0] 29.788946
        Extended scan: Disabled (0x00)
        Filter duplicates: Disabled (0x00)
        Duration: 0 msec (0x0000)
        Period: 0.00 sec (0x0000)
> HCI Event: Command Complete (0x0e) plen 4                                     #9 [hci0] 29.790152
      LE Set Extended Scan Enable (0x08|0x0042) ncmd 2
        Status: Success (0x00)
@ MGMT Event: Discovering (0x0013) plen 2                                 {0x0001} [hci0] 29.790217
        Address type: 0x06
          LE Public
          LE Random
        Discovery: Disabled (0x00)
@ MGMT Command: Start Service Discovery (0x003a) plen 4                   {0x0001} [hci0] 30.366250
        Address type: 0x06
          LE Public
          LE Random
        RSSI: -100 dBm (0x9c)
        UUIDs: 0
< HCI Command: LE Set Random Address (0x08|0x0005) plen 6                      #10 [hci0] 30.366587
        Address: 2A:F7:88:72:42:9F (Non-Resolvable)
> HCI Event: Command Complete (0x0e) plen 4                                    #11 [hci0] 30.368112
      LE Set Random Address (0x08|0x0005) ncmd 2
        Status: Success (0x00)
< HCI Command: LE Set Extended Scan Parameters (0x08|0x0041) plen 8            #12 [hci0] 30.368157
        Own address type: Random (0x01)
        Filter policy: Accept all advertisement (0x00)
        PHYs: 0x01
        Entry 0: LE 1M
          Type: Active (0x01)
          Interval: 11.250 msec (0x0012)
          Window: 11.250 msec (0x0012)
> HCI Event: Command Complete (0x0e) plen 4                                    #13 [hci0] 30.370107
      LE Set Extended Scan Parameters (0x08|0x0041) ncmd 2
        Status: Success (0x00)
< HCI Command: LE Set Extended Scan Enable (0x08|0x0042) plen 6                #14 [hci0] 30.370152
        Extended scan: Enabled (0x01)
        Filter duplicates: Enabled (0x01)
        Duration: 0 msec (0x0000)
        Period: 0.00 sec (0x0000)
> HCI Event: Command Complete (0x0e) plen 4                                    #15 [hci0] 30.372108
      LE Set Extended Scan Enable (0x08|0x0042) ncmd 2
        Status: Success (0x00)
@ MGMT Event: Command Complete (0x0001) plen 4                            {0x0001} [hci0] 30.372166
      Start Service Discovery (0x003a) plen 1
        Status: Success (0x00)
        Address type: 0x06
          LE Public
          LE Random
@ MGMT Event: Discovering (0x0013) plen 2                                 {0x0001} [hci0] 30.372189
        Address type: 0x06
          LE Public
          LE Random
        Discovery: Enabled (0x01)
> HCI Event: LE Meta Event (0x3e) plen 57                                      #16 [hci0] 30.872077
      LE Extended Advertising Report (0x0d)
        Num reports: 1
        Entry 0
          Event type: 0x0010
            Props: 0x0010
              Use legacy advertising PDUs
            Data status: Complete
          Legacy PDU Type: ADV_NONCONN_IND (0x0010)
          Address type: Random (0x01)
          Address: D7:6F:3F:5E:F4:BF (Static)
          Primary PHY: LE 1M
          Secondary PHY: No packets
          SID: no ADI field (0xff)
          TX power: 127 dBm
          RSSI: -50 dBm (0xce)
          Periodic advertising interval: 0.00 msec (0x0000)
          Direct address type: Public (0x00)
          Direct address: 00:00:00:00:00:00 (OUI 00-00-00)
          Data length: 0x1f
        1e ff 00 5d 89 6c 05 00 00 01 be eb cd cd ab 6c  ...].l.........
        19 b1 9d b8 4c b0 7a 21 c3 47 ea 87 cd b8 40     ....L.z!.G....@
        Company: not assigned (23808)
          Data: 896c05000001beebcdcdab6c19b19db84cb07a21c347ea87cdb840
@ MGMT Event: Device Found (0x0012) plen 45                               {0x0001} [hci0] 30.872143
        LE Address: D7:6F:3F:5E:F4:BF (Static)
        RSSI: -50 dBm (0xce)
        Flags: 0x00000004
          Not Connectable
        Data length: 31
        Company: not assigned (23808)
          Data: 896c05000001beebcdcdab6c19b19db84cb07a21c347ea87cdb840
< HCI Command: LE Set Extended Scan Enable (0x08|0x0042) plen 6                #17 [hci0] 40.796957
        Extended scan: Disabled (0x00)
        Filter duplicates: Disabled (0x00)
        Duration: 0 msec (0x0000)
        Period: 0.00 sec (0x0000)
> HCI Event: Command Complete (0x0e) plen 4                                    #18 [hci0] 40.798618
      LE Set Extended Scan Enable (0x08|0x0042) ncmd 2
        Status: Success (0x00)
@ MGMT Event: Discovering (0x0013) plen 2                                 {0x0001} [hci0] 40.798705
        Address type: 0x06
          LE Public
          LE Random
        Discovery: Disabled (0x00)
@ MGMT Command: Start Service Discovery (0x003a) plen 4                   {0x0001} [hci0] 41.365743
        Address type: 0x06
          LE Public
          LE Random
        RSSI: -100 dBm (0x9c)
        UUIDs: 0
< HCI Command: LE Set Random Address (0x08|0x0005) plen 6                      #19 [hci0] 41.366052
        Address: 0D:AC:11:DE:10:91 (Non-Resolvable)
> HCI Event: Command Complete (0x0e) plen 4                                    #20 [hci0] 41.367594
      LE Set Random Address (0x08|0x0005) ncmd 2
        Status: Success (0x00)
< HCI Command: LE Set Extended Scan Parameters (0x08|0x0041) plen 8            #21 [hci0] 41.367646
        Own address type: Random (0x01)
        Filter policy: Accept all advertisement (0x00)
        PHYs: 0x01
        Entry 0: LE 1M
          Type: Active (0x01)
          Interval: 11.250 msec (0x0012)
          Window: 11.250 msec (0x0012)
> HCI Event: Command Complete (0x0e) plen 4                                    #22 [hci0] 41.369591
      LE Set Extended Scan Parameters (0x08|0x0041) ncmd 2
        Status: Success (0x00)
< HCI Command: LE Set Extended Scan Enable (0x08|0x0042) plen 6                #23 [hci0] 41.369639
        Extended scan: Enabled (0x01)
        Filter duplicates: Enabled (0x01)
        Duration: 0 msec (0x0000)
        Period: 0.00 sec (0x0000)
> HCI Event: Command Complete (0x0e) plen 4                                    #24 [hci0] 41.371591
      LE Set Extended Scan Enable (0x08|0x0042) ncmd 2
        Status: Success (0x00)
@ MGMT Event: Command Complete (0x0001) plen 4                            {0x0001} [hci0] 41.371650
      Start Service Discovery (0x003a) plen 1
        Status: Success (0x00)
        Address type: 0x06
          LE Public
          LE Random
@ MGMT Event: Discovering (0x0013) plen 2                                 {0x0001} [hci0] 41.371665
        Address type: 0x06
          LE Public
          LE Random
        Discovery: Enabled (0x01)
> HCI Event: LE Meta Event (0x3e) plen 57                                      #25 [hci0] 41.561585
      LE Extended Advertising Report (0x0d)
        Num reports: 1
        Entry 0
          Event type: 0x0010
            Props: 0x0010
              Use legacy advertising PDUs
            Data status: Complete
          Legacy PDU Type: ADV_NONCONN_IND (0x0010)
          Address type: Random (0x01)
          Address: D7:6F:3F:5E:F4:BF (Static)
          Primary PHY: LE 1M
          Secondary PHY: No packets
          SID: no ADI field (0xff)
          TX power: 127 dBm
          RSSI: -46 dBm (0xd2)
          Periodic advertising interval: 0.00 msec (0x0000)
          Direct address type: Public (0x00)
          Direct address: 00:00:00:00:00:00 (OUI 00-00-00)
          Data length: 0x1f
        1e ff 00 5c 01 6c 05 00 00 02 8e ff 41 7c 0b f8  ....l......A|.
        fa 32 30 63 f0 d2 bf 3d cb 57 c0 c9 07 fc 40     .20c...=.W....@
        Company: not assigned (23552)
          Data: 016c050000028eff417c0bf8fa323063f0d2bf3dcb57c0c907fc40
@ MGMT Event: Device Found (0x0012) plen 45                               {0x0001} [hci0] 41.561639
        LE Address: D7:6F:3F:5E:F4:BF (Static)
        RSSI: -46 dBm (0xd2)
        Flags: 0x00000004
          Not Connectable
        Data length: 31
        Company: not assigned (23552)
          Data: 016c050000028eff417c0bf8fa323063f0d2bf3dcb57c0c907fc40
< HCI Command: LE Set Extended Scan Enable (0x08|0x0042) plen 6                #26 [hci0] 51.804954
        Extended scan: Disabled (0x00)
        Filter duplicates: Disabled (0x00)
        Duration: 0 msec (0x0000)
        Period: 0.00 sec (0x0000)
> HCI Event: Command Complete (0x0e) plen 4                                    #27 [hci0] 51.806359
      LE Set Extended Scan Enable (0x08|0x0042) ncmd 2
        Status: Success (0x00)
@ MGMT Event: Discovering (0x0013) plen 2                                 {0x0001} [hci0] 51.806459
        Address type: 0x06
          LE Public
          LE Random
        Discovery: Disabled (0x00)
@ MGMT Command: Start Service Discovery (0x003a) plen 4                   {0x0001} [hci0] 52.366492
        Address type: 0x06
          LE Public
          LE Random
        RSSI: -100 dBm (0x9c)
        UUIDs: 0
< HCI Command: LE Set Random Address (0x08|0x0005) plen 6                      #28 [hci0] 52.366810
        Address: 39:3B:A3:C1:28:0D (Non-Resolvable)
> HCI Event: Command Complete (0x0e) plen 4                                    #29 [hci0] 52.368347
      LE Set Random Address (0x08|0x0005) ncmd 2
        Status: Success (0x00)
< HCI Command: LE Set Extended Scan Parameters (0x08|0x0041) plen 8            #30 [hci0] 52.368406
        Own address type: Random (0x01)
        Filter policy: Accept all advertisement (0x00)
        PHYs: 0x01
        Entry 0: LE 1M
          Type: Active (0x01)
          Interval: 11.250 msec (0x0012)
          Window: 11.250 msec (0x0012)
> HCI Event: Command Complete (0x0e) plen 4                                    #31 [hci0] 52.370345
      LE Set Extended Scan Parameters (0x08|0x0041) ncmd 2
        Status: Success (0x00)
< HCI Command: LE Set Extended Scan Enable (0x08|0x0042) plen 6                #32 [hci0] 52.370404
        Extended scan: Enabled (0x01)
        Filter duplicates: Enabled (0x01)
        Duration: 0 msec (0x0000)
        Period: 0.00 sec (0x0000)
> HCI Event: Command Complete (0x0e) plen 4                                    #33 [hci0] 52.372344
      LE Set Extended Scan Enable (0x08|0x0042) ncmd 2
        Status: Success (0x00)
@ MGMT Event: Command Complete (0x0001) plen 4                            {0x0001} [hci0] 52.372412
      Start Service Discovery (0x003a) plen 1
        Status: Success (0x00)
        Address type: 0x06
          LE Public
          LE Random
@ MGMT Event: Discovering (0x0013) plen 2                                 {0x0001} [hci0] 52.372427
        Address type: 0x06
          LE Public
          LE Random
        Discovery: Enabled (0x01)
> HCI Event: LE Meta Event (0x3e) plen 57                                      #34 [hci0] 52.401344
      LE Extended Advertising Report (0x0d)
        Num reports: 1
        Entry 0
          Event type: 0x0010
            Props: 0x0010
              Use legacy advertising PDUs
            Data status: Complete
          Legacy PDU Type: ADV_NONCONN_IND (0x0010)
          Address type: Random (0x01)
          Address: D7:6F:3F:5E:F4:BF (Static)
          Primary PHY: LE 1M
          Secondary PHY: No packets
          SID: no ADI field (0xff)
          TX power: 127 dBm
          RSSI: -54 dBm (0xca)
          Periodic advertising interval: 0.00 msec (0x0000)
          Direct address type: Public (0x00)
          Direct address: 00:00:00:00:00:00 (OUI 00-00-00)
          Data length: 0x1f
        1e ff 00 03 87 6c 05 00 00 03 61 00 80 ac 13 fa  .....l....a....
        02 b0 d0 cf 57 c2 81 9e 23 0a 00 5f 9b a0 40     ....W...#.._..@
        Company: World Moto Inc. (768)
          Data: 876c05000003610080ac13fa02b0d0cf57c2819e230a005f9ba040
@ MGMT Event: Device Found (0x0012) plen 45                               {0x0001} [hci0] 52.401391
        LE Address: D7:6F:3F:5E:F4:BF (Static)
        RSSI: -54 dBm (0xca)
        Flags: 0x00000004
          Not Connectable
        Data length: 31
        Company: World Moto Inc. (768)
          Data: 876c05000003610080ac13fa02b0d0cf57c2819e230a005f9ba040

2

Answers


  1. Chosen as BEST ANSWER

    I finally made it up to over 90% reception rate.

    Firstly I switched from Python to C code and used D.Youngs ble scanner with slight changes (see ble_scanner.c). With the help of this code and parameter settings I was able to scan in passive mode and to switch off the duplicate filter. This can also be seen in btmon which then leads up to a reception rate of 40%.

    Furthermore I was desperate enough to even exchange my USB dongle. I tried several ones from ASUS, tp-link, xtrust to finally Sabrent. With the Sabrent dongle I am now able to receive over 90% of my telegrams. Didnt even thought of those differences.

    Many thanks to all of you!


  2. ok, first of all, I don’t think you can get ALL advertisements using Bluez. But you can get close…

    Do this:

    • Only subscribe to PropertiesChanged signal and ignore InterfaceAdded. Also don’t do RemoveDevice…
    • Add an RSSI parameter to SetDiscoveryFilter with a value of -100
    • DuplicateData must have the value True…but you already had that.

    If you do the above, you should at least get several events per second.

    import argparse
    from gi.repository import GLib
    from pydbus import SystemBus
    import datetime
    
    DEVICE_INTERFACE = 'org.bluez.Device1'
    
    def stop_scan():
        """Stop device discovery and quit event loop"""
        adapter.StopDiscovery()
        mainloop.quit()
    
    def on_properties_changed(owner, path, iface, signal, interfaces_and_properties):
        iface_path, propsChanged, leftover = interfaces_and_properties
        if DEVICE_INTERFACE in interfaces_and_properties:
            on_device_found(path, propsChanged)
    
    def on_device_found(device_path, device_props):
        address = get_address(device_path)
        rssi = device_props.get('RSSI')
        service_data = device_props.get('ServiceData')
        manufacturer_data = device_props.get('ManufacturerData')
        
        if address == 'D7:6F:3F:5E:F4:BF':
            print(str(datetime.datetime.now()) + " " + str(address) + 
                  " RSSI:" + str(rssi) + " MData:" + str(manufacturer_data))
    
    def get_address(device_path):
        return device_path.split("/")[-1].replace("dev_", "").replace("_",":")
        
    if __name__ == '__main__':
        parser = argparse.ArgumentParser()
        parser.add_argument('-d', '--duration', type=int, default=0,
                            help='Duration of scan [0 for continuous]')
        args = parser.parse_args()
        bus = SystemBus()
        adapter = bus.get('org.bluez', '/org/bluez/hci0')    
        bus.subscribe(iface='org.freedesktop.DBus.Properties',
                       signal='PropertiesChanged',
                       arg0 = DEVICE_INTERFACE,
                       signal_fired=on_properties_changed)
    
        mainloop = GLib.MainLoop()
    
        if args.duration > 0:
            GLib.timeout_add_seconds(args.duration, stop_scan)
        adapter.SetDiscoveryFilter({"DuplicateData": GLib.Variant.new_boolean(True), 
                                    "Transport":GLib.Variant.new_string("le"), 
                                    "RSSI": GLib.Variant.new_int16(-100)})
        
        adapter.StartDiscovery()
    
        try:
            print('ntUse CTRL-C to stop discoveryn')
            mainloop.run()
        except KeyboardInterrupt:
            stop_scan()
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search