50ButtonsEach / fliclib-linux-hci

Flic SDK for Linux
305 stars 55 forks source link

Not connecting to Flic using Bluetooth v5 dongle #101

Closed hillstub closed 3 years ago

hillstub commented 3 years ago

Previously, I connected to the Flic buttons using a TP-LINK dongle, which did work but only over a distance of a couple of meters. I hoped that Bluetooth v5 might help to have them work over a longer distance, so I bought a Asus BT500 dongle.

I installed the newest firmware from Asus on my Raspberry Pi.

When I try to pair a new Flic button the simpleclient shows this error:

Please click and hold down your Flic button!
Found public button xx:xx:xx:xx:xx:xx XXXX, connecting...
Scan wizard done with status WizardFailedTimeout

btmon shows this output:

Bluetooth monitor ver 5.50
= Note: Linux version 5.4.79-v7l+ (armv7l)                            0.388511
= Note: Bluetooth subsystem version 2.22                              0.388522
= New Index: xx:xx:xx:xx:xx:xx (Primary,USB,hci0)              [hci0] 0.388529
= Open Index: xx:xx:xx:xx:xx:xx                                [hci0] 0.388534
= Index Info: xx:xx:xx:.. (Realtek Semiconductor Corporation)  [hci0] 0.388538
@ USER Open: flicd (privileged) version 2.22          {0x0001} [hci0] 0.388543
@ MGMT Open: btmon (privileged) version 1.14                 {0x0002} 0.389030
< HCI Command: LE Set Scan Enable (0x08|0x000c) plen 2     #1 [hci0] 70.200005
        Scanning: Enabled (0x01)
        Filter duplicates: Disabled (0x00)
> HCI Event: Command Complete (0x0e) plen 4                #2 [hci0] 70.202976
      LE Set Scan Enable (0x08|0x000c) ncmd 2
        Status: Success (0x00)
(...)
< HCI Command: LE Add Device To W.. (0x08|0x0011) plen 7  #753 [hci0] 13.750327
        Address type: Public (0x00)
        Address: xx:xx:xx:xx:xx:xx (OUI XX-XX-XX)
> HCI Event: Command Complete (0x0e) plen 4               #754 [hci0] 13.752202
      LE Add Device To White List (0x08|0x0011) ncmd 2
        Status: Success (0x00)
< HCI Command: LE Create Connect.. (0x08|0x000d) plen 25  #755 [hci0] 13.752329
        Scan interval: 60.000 msec (0x0060)
        Scan window: 30.000 msec (0x0030)
        Filter policy: White list is used (0x01)
        Peer address type: Public (0x00)
        Peer address: 00:00:00:00:00:00 (OUI 00-00-00)
        Own address type: Public (0x00)
        Min connection interval: 20.00 msec (0x0010)
        Max connection interval: 25.00 msec (0x0014)
        Connection latency: 0 (0x0000)
        Supervision timeout: 200 msec (0x0014)
        Min connection length: 0.000 msec (0x0000)
        Max connection length: 0.000 msec (0x0000)
> HCI Event: Command Status (0x0f) plen 4                 #756 [hci0] 13.755204
      LE Create Connection (0x08|0x000d) ncmd 2
        Status: Success (0x00)
> HCI Event: LE Meta Event (0x3e) plen 31                 #757 [hci0] 13.895224
      LE Enhanced Connection Complete (0x0a)
        Status: Success (0x00)
        Handle: 16
        Role: Master (0x00)
        Peer address type: Public (0x00)
        Peer address: xx:xx:xx:xx:xx:xx (OUI XX-XX-XX)
        Local resolvable private address: 00:00:00:00:00:00 (Non-Resolvable)
        Peer resolvable private address: 00:00:00:00:00:00 (Non-Resolvable)
        Connection interval: 22.50 msec (0x0012)
        Connection latency: 0 (0x0000)
        Supervision timeout: 200 msec (0x0014)
        Master clock accuracy: 0x00
< HCI Command: Vendor (0x3f|0x0019) plen 5                #758 [hci0] 13.895564
        01 10 00 02 00                                   .....           
> HCI Event: Command Complete (0x0e) plen 4               #759 [hci0] 13.897228
      Vendor (0x3f|0x0019) ncmd 2
        Status: Success (0x00)
> HCI Event: Disconnect Complete (0x05) plen 4            #760 [hci0] 14.019249
        Status: Success (0x00)
        Handle: 16
        **Reason: Connection Failed to be Established (0x3e)**
< HCI Command: Vendor (0x3f|0x0019) plen 5                #761 [hci0] 15.918248
        01 10 00 12 02                                   .....           
> HCI Event: Command Complete (0x0e) plen 4               #762 [hci0] 15.920511
      Vendor (0x3f|0x0019) ncmd 2
        Status: Success (0x00)
< HCI Command: Vendor (0x3f|0x0019) plen 2                #763 [hci0] 17.998247
        00 00                                            ..              
> HCI Event: Command Complete (0x0e) plen 4               #764 [hci0] 17.999804
      Vendor (0x3f|0x0019) ncmd 2
        Status: Success (0x00)
< HCI Command: LE Create Connecti.. (0x08|0x000e) plen 0  #765 [hci0] 23.752826
> HCI Event: Command Complete (0x0e) plen 4               #766 [hci0] 23.755627
      LE Create Connection Cancel (0x08|0x000e) ncmd 2
        **Status: Command Disallowed (0x0c)**

As is shown in the log it shows two errors: Reason: Connection Failed to be Established (0x3e) and Status: Command Disallowed (0x0c) (this last error keeps on showing).

Is there a way I can fix these errors and have these buttons work with my dongle?

Thanks in advance! Kind regards, Harmen

Emill commented 3 years ago

Hi. Could you include the full btmon log, from just before you start flicd? Also do you have a Flic 2 or first gen Flic?

hillstub commented 3 years ago

Thanks for looking into this!

I updated my original post with additional btmon log.

I have Flic 2 buttons.

Emill commented 3 years ago

Hm is that really the full log? There should be a bunch of packets in it. The first packet should be "Reset". Does your Flic 2 at any time when you press and hold it down flash green?

hillstub commented 3 years ago

Sorry about that. Below the full log (with some devices removed). The button does not flash green..

Bluetooth monitor ver 5.50
= Note: Linux version 5.4.79-v7l+ (armv7l)                             0.374057
= Note: Bluetooth subsystem version 2.22                               0.374067
= New Index: XX:XX:XX:XX:XX:XX (Primary,USB,hci0)               [hci0] 0.374073
@ MGMT Open: btmon (privileged) version 1.14                  {0x0001} 0.374569
@ RAW Open: flicd (privileged) version 2.22                  {0x0002} 30.234722
@ MGMT Event: Index Removed (0x0005) plen 0           {0x0001} [hci0] 30.235070
= Open Index: XX:XX:XX:XX:XX:XX                                [hci0] 30.248770
= Index Info: XX:XX:XX:.. (Realtek Semiconductor Corporation)  [hci0] 30.248796
@ RAW Close: flicd                                           {0x0002} 30.248823
@ USER Open: flicd (privileged) version 2.22          {0x0002} [hci0] 30.248833
< HCI Command: Reset (0x03|0x0003) plen 0                   #1 [hci0] 30.249100
> HCI Event: Command Complete (0x0e) plen 4                 #2 [hci0] 30.261605
      Reset (0x03|0x0003) ncmd 3
        Status: Success (0x00)
< HCI Command: Read Local Version I.. (0x04|0x0001) plen 0  #3 [hci0] 30.261797
> HCI Event: Command Complete (0x0e) plen 12                #4 [hci0] 30.264595
      Read Local Version Information (0x04|0x0001) ncmd 2
        Status: Success (0x00)
        HCI version: Reserved (0x0a) - Revision 2304 (0x0900)
        LMP version: Reserved (0x0a) - Subversion 11017 (0x2b09)
        Manufacturer: Realtek Semiconductor Corporation (93)
< HCI Command: LE Read Supported St.. (0x08|0x001c) plen 0  #5 [hci0] 30.264782
> HCI Event: Command Complete (0x0e) plen 12                #6 [hci0] 30.267595
      LE Read Supported States (0x08|0x001c) ncmd 2
        Status: Success (0x00)
        States: 0x000003ffffffffff
          Non-connectable Advertising State
          Scannable Advertising State
          Connectable Advertising State
          High Duty Cycle Directed Advertising State
          Passive Scanning State
          Active Scanning State
          Initiating State
            and Connection State (Master Role)
          Connection State (Slave Role)
          Non-connectable Advertising State
            and Passive Scanning State
          Scannable Advertising State
            and Passive Scanning State
          Connectable Advertising State
            and Passive Scanning State
          High Duty Cycle Directed Advertising State
            and Passive Scanning State
          Non-connectable Advertising State
            and Active Scanning State
          Scannable Advertising State
            and Active Scanning State
          Connectable Advertising State
            and Active Scanning State
          High Duty Cycle Directed Advertising State
            and Active Scanning State
          Non-connectable Advertising State
            and Initiating State
          Scannable Advertising State
            and Initiating State
          Non-connectable Advertising State
            and Connection State (Master Role)
          Scannable Advertising State
            and Connection State (Master Role)
          Non-connectable Advertising State
            and Connection State (Slave Role)
          Scannable Advertising State
            and Connection State (Slave Role)
          Passive Scanning State
            and Initiating State
          Active Scanning State
            and Initiating State
          Passive Scanning State
            and Connection State (Master Role)
          Active Scanning State
            and Connection State (Master Role)
          Passive Scanning State
            and Connection State (Slave Role)
          Active Scanning State
            and Connection State (Slave Role)
          Initiating State
            and Connection State (Master Role)
            and Master Role & Master Role
          Low Duty Cycle Directed Advertising State
          Low Duty Cycle Directed Advertising State
            and Passive Scanning State
          Low Duty Cycle Directed Advertising State
            and Active Scanning State
          Connectable Advertising State
            and Initiating State
            and Master Role & Slave Role
          High Duty Cycle Directed Advertising State
            and Initiating State
            and Master Role & Slave Role
          Low Duty Cycle Directed Advertising State
            and Initiating State
            and Master Role & Slave Role
          Connectable Advertising State
            and Connection State (Master Role)
            and Master Role & Slave Role
          High Duty Cycle Directed Advertising State
            and Connection State (Master Role)
            and Master Role & Slave Role
          Low Duty Cycle Directed Advertising State
            and Connection State (Master Role)
            and Master Role & Slave Role
          Connectable Advertising State
            and Connection State (Slave Role)
            and Master Role & Slave Role
          High Duty Cycle Directed Advertising State
            and Connection State (Slave Role)
            and Slave Role & Slave Role
          Low Duty Cycle Directed Advertising State
            and Connection State (Slave Role)
            and Slave Role & Slave Role
          Initiating State
            and Connection State (Slave Role)
            and Master Role & Slave Role
< HCI Command: Set Event Mask (0x03|0x0001) plen 8          #7 [hci0] 30.267746
        Mask: 0x2000000000018010
          Disconnection Complete
          Hardware Error
          Flush Occurred
          LE Meta
> HCI Event: Command Complete (0x0e) plen 4                 #8 [hci0] 30.270595
      Set Event Mask (0x03|0x0001) ncmd 2
        Status: Success (0x00)
< HCI Command: Set Controller To Ho.. (0x03|0x0031) plen 1  #9 [hci0] 30.270758
        Flow control: Off (0x00)
> HCI Event: Command Complete (0x0e) plen 4                #10 [hci0] 30.272596
      Set Controller To Host Flow Control (0x03|0x0031) ncmd 2
        Status: Success (0x00)
< HCI Command: Read BD ADDR (0x04|0x0009) plen 0           #11 [hci0] 30.272746
> HCI Event: Command Complete (0x0e) plen 10               #12 [hci0] 30.275594
      Read BD ADDR (0x04|0x0009) ncmd 2
        Status: Success (0x00)
        Address: XX:XX:XX:XX:XX:XX  (OUI XX-XX-XX)
< HCI Command: LE Read Buffer Size (0x08|0x0002) plen 0    #13 [hci0] 30.276290
> HCI Event: Command Complete (0x0e) plen 7                #14 [hci0] 30.278599
      LE Read Buffer Size (0x08|0x0002) ncmd 2
        Status: Success (0x00)
        Data packet length: 251
        Num data packets: 8
< HCI Command: LE Read White List... (0x08|0x000f) plen 0  #15 [hci0] 30.278756
> HCI Event: Command Complete (0x0e) plen 5                #16 [hci0] 30.281597
      LE Read White List Size (0x08|0x000f) ncmd 2
        Status: Success (0x00)
        Size: 32
< HCI Command: LE Clear White List (0x08|0x0010) plen 0    #17 [hci0] 30.281748
> HCI Event: Command Complete (0x0e) plen 4                #18 [hci0] 30.283597
      LE Clear White List (0x08|0x0010) ncmd 2
        Status: Success (0x00)
< HCI Command: LE Set Scan Paramet.. (0x08|0x000b) plen 7  #19 [hci0] 30.283746
        Type: Passive (0x00)
        Interval: 11.250 msec (0x0012)
        Window: 11.250 msec (0x0012)
        Own address type: Public (0x00)
        Filter policy: Accept all advertisement (0x00)
> HCI Event: Command Complete (0x0e) plen 4                #20 [hci0] 30.286599
      LE Set Scan Parameters (0x08|0x000b) ncmd 2
        Status: Success (0x00)
< HCI Command: LE Set Scan Enable (0x08|0x000c) plen 2     #21 [hci0] 36.978233
        Scanning: Enabled (0x01)
        Filter duplicates: Disabled (0x00)
> HCI Event: Command Complete (0x0e) plen 4                #22 [hci0] 36.980498
      LE Set Scan Enable (0x08|0x000c) ncmd 2
        Status: Success (0x00)
> HCI Event: LE Meta Event (0x3e) plen 43                  #38 [hci0] 37.126499
      LE Advertising Report (0x02)
        Num reports: 1
        Event type: Connectable undirected - ADV_IND (0x00)
        Address type: Public (0x00)
        Address: XX:XX:XX:XX:XX:XX (OUI XX-XX-XX)
        Data length: 31
        Flags: 0x06
          LE General Discoverable Mode
          BR/EDR Not Supported
        128-bit Service UUIDs (complete): 1 entry
          Vendor specific (xxx)
        Name (complete): Xxxx
        RSSI: -96 dBm (0xa0)
< HCI Command: LE Set Scan Enable (0x08|0x000c) plen 2     #39 [hci0] 37.126727
        Scanning: Disabled (0x00)
        Filter duplicates: Disabled (0x00)
> HCI Event: Command Complete (0x0e) plen 4                #40 [hci0] 37.129514
      LE Set Scan Enable (0x08|0x000c) ncmd 2
        Status: Success (0x00)
< HCI Command: LE Add Device To Wh.. (0x08|0x0011) plen 7  #41 [hci0] 37.129692
        Address type: Public (0x00)
        Address: XX:XX:XX:XX:XX:XX (OUI XX-XX-XX)
> HCI Event: Command Complete (0x0e) plen 4                #42 [hci0] 37.132519
      LE Add Device To White List (0x08|0x0011) ncmd 2
        Status: Success (0x00)
< HCI Command: LE Create Connection (0x08|0x000d) plen 25  #43 [hci0] 37.132701
        Scan interval: 60.000 msec (0x0060)
        Scan window: 30.000 msec (0x0030)
        Filter policy: White list is used (0x01)
        Peer address type: Public (0x00)
        Peer address: 00:00:00:00:00:00 (OUI 00-00-00)
        Own address type: Public (0x00)
        Min connection interval: 20.00 msec (0x0010)
        Max connection interval: 25.00 msec (0x0014)
        Connection latency: 0 (0x0000)
        Supervision timeout: 200 msec (0x0014)
        Min connection length: 0.000 msec (0x0000)
        Max connection length: 0.000 msec (0x0000)
> HCI Event: Command Status (0x0f) plen 4                  #44 [hci0] 37.135513
      LE Create Connection (0x08|0x000d) ncmd 2
        Status: Success (0x00)
> HCI Event: LE Meta Event (0x3e) plen 31                  #45 [hci0] 37.283532
      LE Enhanced Connection Complete (0x0a)
        Status: Success (0x00)
        Handle: 16
        Role: Master (0x00)
        Peer address type: Public (0x00)
        Peer address: XX:XX:XX:XX:XX:XX (OUI XX-XX-XX)
        Local resolvable private address: 00:00:00:00:00:00 (Non-Resolvable)
        Peer resolvable private address: 00:00:00:00:00:00 (Non-Resolvable)
        Connection interval: 22.50 msec (0x0012)
        Connection latency: 0 (0x0000)
        Supervision timeout: 200 msec (0x0014)
        Master clock accuracy: 0x00
< HCI Command: Vendor (0x3f|0x0019) plen 5                 #46 [hci0] 37.283995
        01 10 00 02 00                                   .....           
> HCI Event: Command Complete (0x0e) plen 4                #47 [hci0] 37.285537
      Vendor (0x3f|0x0019) ncmd 2
        Status: Success (0x00)
> HCI Event: Disconnect Complete (0x05) plen 4             #48 [hci0] 37.406551
        Status: Success (0x00)
        Handle: 16
        Reason: Connection Failed to be Established (0x3e)
< HCI Command: Vendor (0x3f|0x0019) plen 5                 #49 [hci0] 39.318230
        01 10 00 12 02                                   .....           
> HCI Event: Command Complete (0x0e) plen 4                #50 [hci0] 39.320796
      Vendor (0x3f|0x0019) ncmd 2
        Status: Success (0x00)
< HCI Command: Vendor (0x3f|0x0019) plen 2                 #51 [hci0] 41.398278
        00 00                                            ..              
> HCI Event: Command Complete (0x0e) plen 4                #52 [hci0] 41.401087
      Vendor (0x3f|0x0019) ncmd 2
        Status: Success (0x00)
< HCI Command: LE Create Connectio.. (0x08|0x000e) plen 0  #53 [hci0] 47.132122
> HCI Event: Command Complete (0x0e) plen 4                #54 [hci0] 47.134853
      LE Create Connection Cancel (0x08|0x000e) ncmd 2
        Status: Command Disallowed (0x0c)
Emill commented 3 years ago

"Connection Failed to be Established" means the Bluetooth controller did not get a response for the CONNECT_IND from the remote device. If you say the LED never shows green, that means the Flic 2 never detected a CONNECT_IND. I see your RSSI value from the scan is quite weak (-96 dBm). For reference, if devices are right next to each other you usually get something like -40 dBm. Within a few meters you usually get something like -70 dBm.

Our readme says "Generally small cheap USB dongles seem to have shorter range than those integrated inside computers." This in particular means those that are like 5 mm beyond from the USB contact itself. I guess these are primarily meant for wireless mice and keyboards you have within one meter. Computers with built-in Bluetooth tend to have far better range, and this includes Raspberry Pi 3/4. If you want a dongle with longer range, I can recommend http://www.senanetworks.com/ud100-g03.html.

hillstub commented 3 years ago

Thanks, Emill! When I keep the Flic 1-2 cm away from the dongle it's -40 dBm, but it still does not connect. I opted for a dongle as my Raspberry Pi is in a Flirc case, which sort of acts as a Faraday cage. I'll take your advice and buy a dongle like the one from Sena.

Thanks for your help!

hillstub commented 3 years ago

Just to close the loop: I bought a Parani UD100-G3 (hard to get by the way). With the (small) antenna that comes with it, the Flic buttons still did not connect. However, when I connected a larger antenna (TP-LINK TL-ANT2408C) it works pretty well. I'm still a bit surprised that such relatively heavy equipment is needed to make the buttons work, but I'm happy I've found a way - thanks!!

Would be nice in the future to have the buttons set-up a mesh network to expand the reach.

Emill commented 3 years ago

Glad you got it working!

We don't have any plans for meshing the buttons. Bluetooth Mesh only relays messages from main-powered devices, since a relay needs to keep the radio on all the time. That simply won't work with coin cell batteries. See https://www.bluetooth.com/learn-about-bluetooth/bluetooth-technology/topology-options/le-mesh/mesh-faq/ for more info.