Reputation: 41
For a BLE project I have been working on, I have created a smartphone application which serves as central, and a program in Linux, that serves as peripheral. After manually disconnecting via the phone, the program works as intended. But after disconnecting via the peripheral, the connection gets stuck in connect/disconnect loop.
I'm using "JustWorks" in bluetooth, which doesn't require any bonding/pairing.
The smartphone application is made in Flutter, and uses the flutter_reactive_ble library from Hue. The Linux program is written in Python, and uses the Bluezero package, but for disconnecting, I'm using:
subprocess.run("bluetoothctl -- disconnect", shell=True)
The terminal that is running the peripheral looks like this:
Attempting to disconnect from 58:93:C0:B5:9B:D7
Successful disconnected
[CHG] Device 58:93:C0:B5:9B:D7 Connected: no
Attempting to disconnect from 58:93:C0:B5:9B:D7
Successful disconnected
Attempting to disconnect from 58:93:C0:B5:9B:D7
Successful disconnected
The bluetoothctl terminal looks like this:
[CHG] Device 6E:4C:38:CB:4D:A9 Connected: no
[CHG] Device 6E:4C:38:CB:4D:A9 Connected: yes
[CHG] Device 6E:4C:38:CB:4D:A9 Connected: no
[CHG] Device 6E:4C:38:CB:4D:A9 Connected: yes
[CHG] Device 6E:4C:38:CB:4D:A9 Connected: no
[CHG] Device 6E:4C:38:CB:4D:A9 Connected: yes
This is the btmon output: From start to end: Received data -> disconnected from peripheral -> stuck in connect/disconnect loop.
> HCI Event: LE Meta Event (0x3e) plen 10 #72 [hci0] 4.765604
LE Connection Update Complete (0x03)
Status: Success (0x00)
Handle: 24
Connection interval: 45.00 msec (0x0024)
Connection latency: 0 (0x0000)
Supervision timeout: 5000 msec (0x01f4)
> ACL Data RX: Handle 24 flags 0x02 dlen 27 #73 [hci0] 4.855361
> ACL Data RX: Handle 24 flags 0x01 dlen 27 #74 [hci0] 4.856590
> ACL Data RX: Handle 24 flags 0x01 dlen 81 #75 [hci0] 4.857340
ATT: Write Command (0x52) len 130
Handle: 0x0026
Data: 6c69664638704647574134704656625275514a6d727053547062486a754d4c527758674f545733496d4e566630506d385542776c7a446155482b774f506f6a6330335345796c69695438494477554e477664617431424a3373496b352f58476d507a5937676a42707462436e4574392f5858702b79426b4e77796e43694c7242
> HCI Event: LE Meta Event (0x3e) plen 11 #76 [hci0] 4.857646
LE Data Length Change (0x07)
Handle: 24
Max TX octets: 251
Max TX time: 2120
Max RX octets: 250
Max RX time: 2120
@ MGMT Command: Disconnect (0x0014) plen 7 {0x0001} [hci0] 6.819215
LE Address: 48:AD:99:8B:C5:3D (Resolvable)
< HCI Command: Disconnect (0x01|0x0006) plen 3 #77 [hci0] 6.819411
Handle: 24
Reason: Remote User Terminated Connection (0x13)
> HCI Event: Command Status (0x0f) plen 4 #78 [hci0] 6.823217
Disconnect (0x01|0x0006) ncmd 2
Status: Success (0x00)
> HCI Event: Disconnect Complete (0x05) plen 4 #79 [hci0] 6.881799
Status: Success (0x00)
Handle: 24
Reason: Connection Terminated By Local Host (0x16)
@ MGMT Event: Command Complete (0x0001) plen 10 {0x0001} [hci0] 6.882315
Disconnect (0x0014) plen 7
Status: Success (0x00)
LE Address: 48:AD:99:8B:C5:3D (Resolvable)
< HCI Command: LE Set Extended Adve.. (0x08|0x0039) plen 6 #80 [hci0] 6.907442
Extended advertising: Disabled (0x00)
Number of sets: 1 (0x01)
Entry 0
Handle: 0x01
Duration: 0 ms (0x00)
Max ext adv events: 0
> HCI Event: Command Complete (0x0e) plen 4 #81 [hci0] 6.911608
LE Set Extended Advertising Enable (0x08|0x0039) ncmd 2
Status: Success (0x00)
< HCI Command: LE Set Extended Adv.. (0x08|0x0036) plen 25 #82 [hci0] 6.911986
Handle: 0x01
Properties: 0x0013
Connectable
Scannable
Use legacy advertising PDUs: ADV_IND
Min advertising interval: 37.500 msec (0x003c)
Max advertising interval: 37.500 msec (0x003c)
Channel map: 37, 38, 39 (0x07)
Own address type: Public (0x00)
Peer address type: Public (0x00)
Peer address: 00:00:00:00:00:00 (OUI 00-00-00)
Filter policy: Allow Scan Request from Any, Allow Connect Request from Any (0x00)
TX power: 0 dbm (0x00)
Primary PHY: LE 1M (0x01)
Secondary max skip: 0x00
Secondary PHY: LE 1M (0x01)
SID: 0x00
Scan request notifications: Disabled (0x00)
> HCI Event: Command Complete (0x0e) plen 5 #83 [hci0] 6.913620
LE Set Extended Advertising Parameters (0x08|0x0036) ncmd 2
Status: Success (0x00)
TX power (selected): 0 dbm (0x00)
< HCI Command: LE Set Extended Adve.. (0x08|0x0039) plen 6 #84 [hci0] 6.913983
Extended advertising: Enabled (0x01)
Number of sets: 1 (0x01)
Entry 0
Handle: 0x01
Duration: 0 ms (0x00)
Max ext adv events: 0
> HCI Event: Command Complete (0x0e) plen 4 #85 [hci0] 6.918517
LE Set Extended Advertising Enable (0x08|0x0039) ncmd 2
Status: Success (0x00)
> HCI Event: LE Meta Event (0x3e) plen 19 #86 [hci0] 7.793289
LE Connection Complete (0x01)
Status: Success (0x00)
Handle: 24
Role: Peripheral (0x01)
Peer address type: Random (0x01)
Peer address: 48:AD:99:8B:C5:3D (Resolvable)
Connection interval: 45.00 msec (0x0024)
Connection latency: 0 (0x0000)
Supervision timeout: 5000 msec (0x01f4)
Central clock accuracy: 0x01
@ MGMT Event: Device Connected (0x000b) plen 13 {0x0001} [hci0] 7.793976
LE Address: 48:AD:99:8B:C5:3D (Resolvable)
Flags: 0x00000000
Data length: 0
< HCI Command: LE Read Remote Used... (0x08|0x0016) plen 2 #87 [hci0] 7.794074
Handle: 24
> HCI Event: LE Meta Event (0x3e) plen 6 #88 [hci0] 7.795376
LE Advertising Set Terminated (0x12)
Status: Success (0x00)
Handle: 1
Connection handle: 24
Number of completed extended advertising events: 20
> HCI Event: Command Status (0x0f) plen 4 #89 [hci0] 7.797118
LE Read Remote Used Features (0x08|0x0016) ncmd 2
Status: Success (0x00)
> HCI Event: LE Meta Event (0x3e) plen 4 #90 [hci0] 7.827428
LE Channel Selection Algorithm (0x14)
Handle: 24
Algorithm: #2 (0x01)
> HCI Event: LE Meta Event (0x3e) plen 12 #91 [hci0] 7.873271
LE Read Remote Used Features (0x04)
Status: Success (0x00)
Handle: 24
Features: 0xbd 0x7f 0x00 0x37 0x01 0x00 0x00 0x00
LE Encryption
Extended Reject Indication
Peripheral-initiated Features Exchange
LE Ping
LE Data Packet Length Extension
Extended Scanner Filter Policies
LE 2M PHY
Stable Modulation Index - Transmitter
Stable Modulation Index - Receiver
LE Coded PHY
LE Extended Advertising
LE Periodic Advertising
Channel Selection Algorithm #2
Periodic Advertising Sync Transfer - Sender
Periodic Advertising Sync Transfer - Recipient
Sleep Clock Accuracy Updates
Connected Isochronous Stream - Central
Connected Isochronous Stream - Peripheral
Isochronous Channels (Host Support)
> ACL Data RX: Handle 24 flags 0x02 dlen 26 #92 [hci0] 8.006833
LE L2CAP: Enhanced Credit Connection Request (0x17) ident 3 len 18
PSM: 39 (0x0027)
MTU: 256
MPS: 251
Credits: 65535
Source CID: 67
Source CID: 80
Source CID: 72
Source CID: 73
Source CID: 74
< ACL Data TX: Handle 24 flags 0x00 dlen 10 #93 [hci0] 8.011070
LE L2CAP: Command Reject (0x01) ident 3 len 2
Reason: Command not understood (0x0000)
> ACL Data RX: Handle 24 flags 0x02 dlen 26 #94 [hci0] 8.011537
LE L2CAP: Enhanced Credit Connection Request (0x17) ident 4 len 18
PSM: 39 (0x0027)
MTU: 256
MPS: 251
Credits: 65535
Source CID: 67
Source CID: 80
Source CID: 72
Source CID: 73
Source CID: 74
< ACL Data TX: Handle 24 flags 0x00 dlen 10 #95 [hci0] 8.011863
LE L2CAP: Command Reject (0x01) ident 4 len 2
Reason: Command not understood (0x0000)
> ACL Data RX: Handle 24 flags 0x02 dlen 26 #96 [hci0] 8.013806
LE L2CAP: Enhanced Credit Connection Request (0x17) ident 5 len 18
PSM: 39 (0x0027)
MTU: 256
MPS: 251
Credits: 65535
Source CID: 67
Source CID: 80
Source CID: 72
Source CID: 73
Source CID: 74
< ACL Data TX: Handle 24 flags 0x00 dlen 10 #97 [hci0] 8.014120
LE L2CAP: Command Reject (0x01) ident 5 len 2
Reason: Command not understood (0x0000)
> ACL Data RX: Handle 24 flags 0x02 dlen 26 #98 [hci0] 8.015700
LE L2CAP: Enhanced Credit Connection Request (0x17) ident 6 len 18
PSM: 39 (0x0027)
MTU: 256
MPS: 251
Credits: 65535
Source CID: 67
Source CID: 80
Source CID: 72
Source CID: 73
Source CID: 74
< ACL Data TX: Handle 24 flags 0x00 dlen 10 #99 [hci0] 8.016011
LE L2CAP: Command Reject (0x01) ident 6 len 2
Reason: Command not understood (0x0000)
> ACL Data RX: Handle 24 flags 0x02 dlen 26 #100 [hci0] 8.017572
LE L2CAP: Enhanced Credit Connection Request (0x17) ident 7 len 18
PSM: 39 (0x0027)
MTU: 256
MPS: 251
Credits: 65535
Source CID: 67
Source CID: 80
Source CID: 72
Source CID: 73
Source CID: 74
< ACL Data TX: Handle 24 flags 0x00 dlen 10 #101 [hci0] 8.017884
LE L2CAP: Command Reject (0x01) ident 7 len 2
Reason: Command not understood (0x0000)
> ACL Data RX: Handle 24 flags 0x02 dlen 26 #102 [hci0] 8.019854
LE L2CAP: Enhanced Credit Connection Request (0x17) ident 8 len 18
PSM: 39 (0x0027)
MTU: 256
MPS: 251
Credits: 65535
Source CID: 67
Source CID: 80
Source CID: 72
Source CID: 73
Source CID: 74
< ACL Data TX: Handle 24 flags 0x00 dlen 10 #103 [hci0] 8.020183
LE L2CAP: Command Reject (0x01) ident 8 len 2
Reason: Command not understood (0x0000)
> HCI Event: Number of Completed Packets (0x13) plen 5 #104 [hci0] 8.055702
Num handles: 1
Handle: 24
Count: 1
> HCI Event: LE Meta Event (0x3e) plen 11 #105 [hci0] 8.059275
LE Data Length Change (0x07)
Handle: 24
Max TX octets: 251
Max TX time: 2120
Max RX octets: 27
Max RX time: 328
> HCI Event: Number of Completed Packets (0x13) plen 5 #106 [hci0] 8.063411
Num handles: 1
Handle: 24
Count: 1
> HCI Event: Number of Completed Packets (0x13) plen 5 #107 [hci0] 8.067380
Num handles: 1
Handle: 24
Count: 1
> HCI Event: Number of Completed Packets (0x13) plen 5 #108 [hci0] 8.070316
Num handles: 1
Handle: 24
Count: 1
> HCI Event: Number of Completed Packets (0x13) plen 5 #109 [hci0] 8.072300
Num handles: 1
Handle: 24
Count: 1
> HCI Event: Number of Completed Packets (0x13) plen 5 #110 [hci0] 8.099836
Num handles: 1
Handle: 24
Count: 1
@ MGMT Command: Disconnect (0x0014) plen 7 {0x0001} [hci0] 10.834677
LE Address: 48:AD:99:8B:C5:3D (Resolvable)
< HCI Command: Disconnect (0x01|0x0006) plen 3 #111 [hci0] 10.836267
Handle: 24
Reason: Remote User Terminated Connection (0x13)
> HCI Event: Command Status (0x0f) plen 4 #112 [hci0] 10.840869
Disconnect (0x01|0x0006) ncmd 2
Status: Success (0x00)
> HCI Event: Disconnect Complete (0x05) plen 4 #113 [hci0] 10.889096
Status: Success (0x00)
Handle: 24
Reason: Connection Terminated By Local Host (0x16)
@ MGMT Event: Command Complete (0x0001) plen 10 {0x0001} [hci0] 10.889891
Disconnect (0x0014) plen 7
Status: Success (0x00)
LE Address: 48:AD:99:8B:C5:3D (Resolvable)
< HCI Command: LE Set Extended Ad.. (0x08|0x0039) plen 6 #114 [hci0] 10.919524
Extended advertising: Disabled (0x00)
Number of sets: 1 (0x01)
Entry 0
Handle: 0x01
Duration: 0 ms (0x00)
Max ext adv events: 0
> HCI Event: Command Complete (0x0e) plen 4 #115 [hci0] 10.923760
LE Set Extended Advertising Enable (0x08|0x0039) ncmd 2
Status: Success (0x00)
< HCI Command: LE Set Extended A.. (0x08|0x0036) plen 25 #116 [hci0] 10.924022
Handle: 0x01
Properties: 0x0013
Connectable
Scannable
Use legacy advertising PDUs: ADV_IND
Min advertising interval: 37.500 msec (0x003c)
Max advertising interval: 37.500 msec (0x003c)
Channel map: 37, 38, 39 (0x07)
Own address type: Public (0x00)
Peer address type: Public (0x00)
Peer address: 00:00:00:00:00:00 (OUI 00-00-00)
Filter policy: Allow Scan Request from Any, Allow Connect Request from Any (0x00)
TX power: 0 dbm (0x00)
Primary PHY: LE 1M (0x01)
Secondary max skip: 0x00
Secondary PHY: LE 1M (0x01)
SID: 0x00
Scan request notifications: Disabled (0x00)
> HCI Event: Command Complete (0x0e) plen 5 #117 [hci0] 10.927608
LE Set Extended Advertising Parameters (0x08|0x0036) ncmd 2
Status: Success (0x00)
TX power (selected): 0 dbm (0x00)
< HCI Command: LE Set Extended Ad.. (0x08|0x0039) plen 6 #118 [hci0] 10.928040
Extended advertising: Enabled (0x01)
Number of sets: 1 (0x01)
Entry 0
Handle: 0x01
Duration: 0 ms (0x00)
Max ext adv events: 0
> HCI Event: Command Complete (0x0e) plen 4 #119 [hci0] 10.933897
LE Set Extended Advertising Enable (0x08|0x0039) ncmd 2
Status: Success (0x00)
> HCI Event: LE Meta Event (0x3e) plen 19 #120 [hci0] 10.942881
LE Connection Complete (0x01)
Status: Success (0x00)
Handle: 24
Role: Peripheral (0x01)
Peer address type: Random (0x01)
Peer address: 48:AD:99:8B:C5:3D (Resolvable)
Connection interval: 45.00 msec (0x0024)
Connection latency: 0 (0x0000)
Supervision timeout: 5000 msec (0x01f4)
Central clock accuracy: 0x01
@ MGMT Event: Device Connected (0x000b) plen 13 {0x0001} [hci0] 10.943295
LE Address: 48:AD:99:8B:C5:3D (Resolvable)
Flags: 0x00000000
Data length: 0
< HCI Command: LE Read Remote Use.. (0x08|0x0016) plen 2 #121 [hci0] 10.943372
Handle: 24
> HCI Event: LE Meta Event (0x3e) plen 6 #122 [hci0] 10.944681
LE Advertising Set Terminated (0x12)
Status: Success (0x00)
Handle: 1
Connection handle: 24
Number of completed extended advertising events: 0
> HCI Event: Command Status (0x0f) plen 4 #123 [hci0] 10.946984
LE Read Remote Used Features (0x08|0x0016) ncmd 2
Status: Success (0x00)
> HCI Event: LE Meta Event (0x3e) plen 4 #124 [hci0] 10.979349
LE Channel Selection Algorithm (0x14)
Handle: 24
Algorithm: #2 (0x01)
> HCI Event: LE Meta Event (0x3e) plen 12 #125 [hci0] 11.024865
LE Read Remote Used Features (0x04)
Status: Success (0x00)
Handle: 24
Features: 0xbd 0x7f 0x00 0x37 0x01 0x00 0x00 0x00
LE Encryption
Extended Reject Indication
Peripheral-initiated Features Exchange
LE Ping
LE Data Packet Length Extension
Extended Scanner Filter Policies
LE 2M PHY
Stable Modulation Index - Transmitter
Stable Modulation Index - Receiver
LE Coded PHY
LE Extended Advertising
LE Periodic Advertising
Channel Selection Algorithm #2
Periodic Advertising Sync Transfer - Sender
Periodic Advertising Sync Transfer - Recipient
Sleep Clock Accuracy Updates
Connected Isochronous Stream - Central
Connected Isochronous Stream - Peripheral
Isochronous Channels (Host Support)
> ACL Data RX: Handle 24 flags 0x02 dlen 26 #126 [hci0] 11.158694
LE L2CAP: Enhanced Credit Connection Request (0x17) ident 9 len 18
PSM: 39 (0x0027)
MTU: 256
MPS: 251
Credits: 65535
Source CID: 75
Source CID: 82
Source CID: 64
Source CID: 65
Source CID: 66
< ACL Data TX: Handle 24 flags 0x00 dlen 10 #127 [hci0] 11.159017
LE L2CAP: Command Reject (0x01) ident 9 len 2
Reason: Command not understood (0x0000)
> ACL Data RX: Handle 24 flags 0x02 dlen 26 #128 [hci0] 11.160874
LE L2CAP: Enhanced Credit Connection Request (0x17) ident 10 len 18
PSM: 39 (0x0027)
MTU: 256
MPS: 251
Credits: 65535
Source CID: 75
Source CID: 82
Source CID: 64
Source CID: 65
Source CID: 66
< ACL Data TX: Handle 24 flags 0x00 dlen 10 #129 [hci0] 11.161137
LE L2CAP: Command Reject (0x01) ident 10 len 2
Reason: Command not understood (0x0000)
> ACL Data RX: Handle 24 flags 0x02 dlen 26 #130 [hci0] 11.162536
LE L2CAP: Enhanced Credit Connection Request (0x17) ident 11 len 18
PSM: 39 (0x0027)
MTU: 256
MPS: 251
Credits: 65535
Source CID: 75
Source CID: 82
Source CID: 64
Source CID: 65
Source CID: 66
< ACL Data TX: Handle 24 flags 0x00 dlen 10 #131 [hci0] 11.162874
LE L2CAP: Command Reject (0x01) ident 11 len 2
Reason: Command not understood (0x0000)
> ACL Data RX: Handle 24 flags 0x02 dlen 26 #132 [hci0] 11.164513
LE L2CAP: Enhanced Credit Connection Request (0x17) ident 12 len 18
PSM: 39 (0x0027)
MTU: 256
MPS: 251
Credits: 65535
Source CID: 75
Source CID: 82
Source CID: 64
Source CID: 65
Source CID: 66
< ACL Data TX: Handle 24 flags 0x00 dlen 10 #133 [hci0] 11.164839
LE L2CAP: Command Reject (0x01) ident 12 len 2
Reason: Command not understood (0x0000)
> ACL Data RX: Handle 24 flags 0x02 dlen 26 #134 [hci0] 11.166441
LE L2CAP: Enhanced Credit Connection Request (0x17) ident 13 len 18
PSM: 39 (0x0027)
MTU: 256
MPS: 251
Credits: 65535
Source CID: 75
Source CID: 82
Source CID: 64
Source CID: 65
Source CID: 66
< ACL Data TX: Handle 24 flags 0x00 dlen 10 #135 [hci0] 11.166739
LE L2CAP: Command Reject (0x01) ident 13 len 2
Reason: Command not understood (0x0000)
> ACL Data RX: Handle 24 flags 0x02 dlen 26 #136 [hci0] 11.168433
LE L2CAP: Enhanced Credit Connection Request (0x17) ident 14 len 18
PSM: 39 (0x0027)
MTU: 256
MPS: 251
Credits: 65535
Source CID: 75
Source CID: 82
Source CID: 64
Source CID: 65
Source CID: 66
< ACL Data TX: Handle 24 flags 0x00 dlen 10 #137 [hci0] 11.168788
LE L2CAP: Command Reject (0x01) ident 14 len 2
Reason: Command not understood (0x0000)
> HCI Event: Number of Completed Packets (0x13) plen 5 #138 [hci0] 11.207392
Num handles: 1
Handle: 24
Count: 1
> HCI Event: LE Meta Event (0x3e) plen 11 #139 [hci0] 11.211700
LE Data Length Change (0x07)
Handle: 24
Max TX octets: 251
Max TX time: 2120
Max RX octets: 27
Max RX time: 328
> HCI Event: Number of Completed Packets (0x13) plen 5 #140 [hci0] 11.213812
Num handles: 1
Handle: 24
Count: 1
> HCI Event: Number of Completed Packets (0x13) plen 5 #141 [hci0] 11.217827
Num handles: 1
Handle: 24
Count: 1
> HCI Event: Number of Completed Packets (0x13) plen 5 #142 [hci0] 11.221915
Num handles: 1
Handle: 24
Count: 1
> HCI Event: Number of Completed Packets (0x13) plen 5 #143 [hci0] 11.225994
Num handles: 1
Handle: 24
Count: 1
> HCI Event: Number of Completed Packets (0x13) plen 5 #144 [hci0] 11.251600
Num handles: 1
Handle: 24
Count: 1
@ MGMT Command: Disconnect (0x0014) plen 7 {0x0001} [hci0] 14.821568
LE Address: 48:AD:99:8B:C5:3D (Resolvable)
< HCI Command: Disconnect (0x01|0x0006) plen 3 #145 [hci0] 14.821608
Handle: 24
Reason: Remote User Terminated Connection (0x13)
> HCI Event: Command Status (0x0f) plen 4 #146 [hci0] 14.830653
Disconnect (0x01|0x0006) ncmd 2
Status: Success (0x00)
> HCI Event: Disconnect Complete (0x05) plen 4 #147 [hci0] 14.896228
Status: Success (0x00)
Handle: 24
Reason: Connection Terminated By Local Host (0x16)
@ MGMT Event: Command Complete (0x0001) plen 10 {0x0001} [hci0] 14.896709
Disconnect (0x0014) plen 7
Status: Success (0x00)
LE Address: 48:AD:99:8B:C5:3D (Resolvable)
For this project, I would like the peripheral to be able to disconnect, without getting stuck in the connect/disconnect loop.
Attempting to manually disconnect via the console in the bluetoothctl menu returns the same results.
It doesn't seem that the error is in my application. Debug statements proof that the connect method doesn't get called.
Does anyone have any suggestions/solutions for this problem?
Edit: It seems like this was an issue with Android, which got fixed in a newer version.
Upvotes: 3
Views: 550