hbldh / bleak

A cross platform Bluetooth Low Energy Client for Python using asyncio
MIT License
1.71k stars 285 forks source link

cannot connect again unless reboot #1617

Open hopethis opened 1 month ago

hopethis commented 1 month ago

Description

Bleak works fine the first time after Booting windows. Buf after one successfull operation I cant get the same programm to run. Either the connection cannot be established or it wasnt properly closed the first time.

import logging
from bleak import BleakClient

logging.basicConfig(level=logging.DEBUG)

address = "0D:8C:DC:22:11:11"
async def connect():
    async with BleakClient(address, timeout=30.0) as client:
        services = await client.get_services()
        print(services)

import asyncio
asyncio.run(connect())

After first execution the status toggles between active and closed

Error: <BluetoothError.SUCCESS: 0>, status: <GattSessionStatus.ACTIVE: 1>
error: <BluetoothError.SUCCESS: 0>, status: <GattSessionStatus.CLOSED: 0>

and failes at the end

ile "C:\Users\ladmin\AppData\Local\Programs\Python\Python311\Lib\site-packages\bleak\backends\winrt\client.py", line 168, 
in _ensure_success
    raise BleakError(f"{fail_msg}: Unreachable")
bleak.exc.BleakError: Could not get GATT services: Unreachable

A reboot fixes the problem and gives another try. .... but this is really annoying...

Does anybody has an idea?

dlech commented 1 month ago

Sounds like a bad Windows Bluetooth driver. You could try logging Bluetooth packets to see what is going on. See troubleshooting page in the docs for instructions.

hopethis commented 1 month ago

Hi,

yes it can be the driver. I checked for updates but there is non available...

i did already but couldnt upload pcap files here.

1   0.000000    host    controller  HCI_CMD 10  Sent LE Set Extended Scan Enable
2   0.002114    controller  host    HCI_EVT 7   Rcvd Command Complete (LE Set Extended Scan Enable)
3   0.002345    host    controller  HCI_CMD 6   Sent Vendor Command 0x001E (opcode 0xFC1E)
4   0.003991    controller  host    HCI_EVT 8   Rcvd Command Complete (Vendor Command 0x001E [opcode 0xFC1E])
5   0.004106    host    controller  HCI_CMD 12  Sent LE Set Extended Scan Parameters
6   0.006003    controller  host    HCI_EVT 7   Rcvd Command Complete (LE Set Extended Scan Parameters)
7   0.006112    host    controller  HCI_CMD 10  Sent LE Set Extended Scan Enable
8   0.007996    controller  host    HCI_EVT 7   Rcvd Command Complete (LE Set Extended Scan Enable)
9   0.008123    host    controller  HCI_CMD 16  Sent Vendor Command 0x002B (opcode 0xFC2B)
10  0.011000    controller  host    HCI_EVT 7   Rcvd Command Complete (LE Set Extended Scan Enable)
11  0.011133    host    controller  HCI_CMD 16  Sent Vendor Command 0x002B (opcode 0xFC2B)
12  0.013001    controller  host    HCI_EVT 7   Rcvd Command Complete (LE Set Extended Scan Enable)
13  0.013052    host    controller  HCI_CMD 16  Sent Vendor Command 0x002B (opcode 0xFC2B)
14  0.015033    controller  host    HCI_EVT 7   Rcvd Command Complete (LE Set Extended Scan Enable)
15  0.015096    host    controller  HCI_CMD 18  Sent Vendor Command 0x002B (opcode 0xFC2B)
16  0.017011    controller  host    HCI_EVT 7   Rcvd Command Complete (LE Set Extended Scan Parameters)
17  0.017249    host    controller  HCI_CMD 18  Sent Vendor Command 0x002B (opcode 0xFC2B)
18  0.019014    controller  host    HCI_EVT 7   Rcvd Command Complete (LE Set Extended Scan Parameters)
19  0.019166    host    controller  HCI_CMD 18  Sent Vendor Command 0x002B (opcode 0xFC2B)
20  0.021016    controller  host    HCI_EVT 7   Rcvd Command Complete (LE Set Extended Scan Parameters)
21  0.021175    host    controller  HCI_CMD 16  Sent Vendor Command 0x002B (opcode 0xFC2B)
22  0.023030    controller  host    HCI_EVT 7   Rcvd Command Complete (LE Set Extended Scan Enable)
23  0.023179    host    controller  HCI_CMD 16  Sent Vendor Command 0x002B (opcode 0xFC2B)
24  0.026020    controller  host    HCI_EVT 7   Rcvd Command Complete (LE Set Extended Scan Enable)
25  0.026172    host    controller  HCI_CMD 16  Sent Vendor Command 0x002B (opcode 0xFC2B)
26  0.029025    controller  host    HCI_EVT 7   Rcvd Command Complete (LE Set Extended Scan Enable)
27  0.030019    controller  host    HCI_EVT 47  Rcvd LE Meta (LE Extended Advertising Report)
28  0.031037    controller  host    HCI_EVT 29  Rcvd LE Meta (LE Extended Advertising Report)
29  0.033003    controller  host    HCI_EVT 47  Rcvd LE Meta (LE Extended Advertising Report)
30  0.034015    controller  host    HCI_EVT 29  Rcvd LE Meta (LE Extended Advertising Report)
31  0.147086    controller  host    HCI_EVT 46  Rcvd LE Meta (LE Extended Advertising Report)
32  0.160019    controller  host    HCI_EVT 48  Rcvd LE Meta (LE Extended Advertising Report)
33  0.161018    controller  host    HCI_EVT 29  Rcvd LE Meta (LE Extended Advertising Report)
34  0.396133    controller  host    HCI_EVT 37  Rcvd LE Meta (LE Extended Advertising Report)
35  0.500047    controller  host    HCI_EVT 59  Rcvd LE Meta (LE Extended Advertising Report)
36  0.503016    controller  host    HCI_EVT 56  Rcvd LE Meta (LE Extended Advertising Report)
37  0.504009    controller  host    HCI_EVT 52  Rcvd LE Meta (LE Extended Advertising Report)
38  0.505005    controller  host    HCI_EVT 47  Rcvd LE Meta (LE Extended Advertising Report)
39  0.505998    controller  host    HCI_EVT 29  Rcvd LE Meta (LE Extended Advertising Report)
40  0.522022    controller  host    HCI_EVT 46  Rcvd LE Meta (LE Extended Advertising Report)
41  0.738947    controller  host    HCI_EVT 46  Rcvd LE Meta (LE Extended Advertising Report)
42  0.739959    controller  host    HCI_EVT 29  Rcvd LE Meta (LE Extended Advertising Report)
43  0.751017    controller  host    HCI_EVT 56  Rcvd LE Meta (LE Extended Advertising Report)
44  0.752002    controller  host    HCI_EVT 52  Rcvd LE Meta (LE Extended Advertising Report)
45  0.852097    controller  host    HCI_EVT 57  Rcvd LE Meta (LE Extended Advertising Report)
46  0.860015    controller  host    HCI_EVT 47  Rcvd LE Meta (LE Extended Advertising Report)
47  0.860993    controller  host    HCI_EVT 29  Rcvd LE Meta (LE Extended Advertising Report)
48  0.864995    controller  host    HCI_EVT 47  Rcvd LE Meta (LE Extended Advertising Report)
49  0.865992    controller  host    HCI_EVT 29  Rcvd LE Meta (LE Extended Advertising Report)
50  0.974128    controller  host    HCI_EVT 53  Rcvd LE Meta (LE Extended Advertising Report)
51  0.984015    controller  host    HCI_EVT 48  Rcvd LE Meta (LE Extended Advertising Report)
52  0.984994    controller  host    HCI_EVT 29  Rcvd LE Meta (LE Extended Advertising Report)
53  1.223313    controller  host    HCI_EVT 48  Rcvd LE Meta (LE Extended Advertising Report)
54  1.224019    controller  host    HCI_EVT 50  Rcvd LE Meta (LE Extended Advertising Report)
55  1.331092    controller  host    HCI_EVT 47  Rcvd LE Meta (LE Extended Advertising Report)
56  1.332007    controller  host    HCI_EVT 29  Rcvd LE Meta (LE Extended Advertising Report)
57  1.333030    controller  host    HCI_EVT 46  Rcvd LE Meta (LE Extended Advertising Report)
58  1.336000    controller  host    HCI_EVT 56  Rcvd LE Meta (LE Extended Advertising Report)
59  1.336997    controller  host    HCI_EVT 52  Rcvd LE Meta (LE Extended Advertising Report)
60  1.343010    controller  host    HCI_EVT 46  Rcvd LE Meta (LE Extended Advertising Report)
61  1.483119    controller  host    HCI_EVT 44  Rcvd LE Meta (LE Extended Advertising Report)
62  1.484014    controller  host    HCI_EVT 29  Rcvd LE Meta (LE Extended Advertising Report)
63  1.570011    controller  host    HCI_EVT 46  Rcvd LE Meta (LE Extended Advertising Report)
64  1.571003    controller  host    HCI_EVT 29  Rcvd LE Meta (LE Extended Advertising Report)
65  1.799106    controller  host    HCI_EVT 48  Rcvd LE Meta (LE Extended Advertising Report)
66  1.800000    controller  host    HCI_EVT 29  Rcvd LE Meta (LE Extended Advertising Report)
67  1.933101    controller  host    HCI_EVT 47  Rcvd LE Meta (LE Extended Advertising Report)
68  1.934029    controller  host    HCI_EVT 29  Rcvd LE Meta (LE Extended Advertising Report)
69  2.031962    controller  host    HCI_EVT 44  Rcvd LE Meta (LE Extended Advertising Report)
70  2.032916    controller  host    HCI_EVT 29  Rcvd LE Meta (LE Extended Advertising Report)
71  2.049930    controller  host    HCI_EVT 48  Rcvd LE Meta (LE Extended Advertising Report)
72  2.050891    controller  host    HCI_EVT 50  Rcvd LE Meta (LE Extended Advertising Report)
73  2.051891    controller  host    HCI_EVT 38  Rcvd LE Meta (LE Extended Advertising Report)
74  2.052893    controller  host    HCI_EVT 53  Rcvd LE Meta (LE Extended Advertising Report)
75  2.054857    host    controller  HCI_CMD 10  Sent LE Set Extended Scan Enable
76  2.057894    controller  host    HCI_EVT 7   Rcvd Command Complete (LE Set Extended Scan Enable)
77  2.058067    host    controller  HCI_CMD 6   Sent Vendor Command 0x001E (opcode 0xFC1E)
78  2.059892    controller  host    HCI_EVT 8   Rcvd Command Complete (Vendor Command 0x001E [opcode 0xFC1E])
79  2.060104    host    controller  HCI_CMD 12  Sent LE Set Extended Scan Parameters
80  2.061896    controller  host    HCI_EVT 7   Rcvd Command Complete (LE Set Extended Scan Parameters)
81  2.061936    host    controller  HCI_CMD 10  Sent LE Set Extended Scan Enable
82  2.063914    controller  host    HCI_EVT 7   Rcvd Command Complete (LE Set Extended Scan Enable)
83  2.063935    host    controller  HCI_CMD 16  Sent Vendor Command 0x002B (opcode 0xFC2B)
84  2.066953    controller  host    HCI_EVT 7   Rcvd Command Complete (LE Set Extended Scan Enable)
85  2.067015    host    controller  HCI_CMD 16  Sent Vendor Command 0x002B (opcode 0xFC2B)
86  2.068893    controller  host    HCI_EVT 7   Rcvd Command Complete (LE Set Extended Scan Enable)
87  2.068901    host    controller  HCI_CMD 16  Sent Vendor Command 0x002B (opcode 0xFC2B)
88  2.070937    controller  host    HCI_EVT 7   Rcvd Command Complete (LE Set Extended Scan Enable)
89  2.070945    host    controller  HCI_CMD 18  Sent Vendor Command 0x002B (opcode 0xFC2B)
90  2.072907    controller  host    HCI_EVT 7   Rcvd Command Complete (LE Set Extended Scan Parameters)
91  2.072919    host    controller  HCI_CMD 18  Sent Vendor Command 0x002B (opcode 0xFC2B)
92  2.074903    controller  host    HCI_EVT 7   Rcvd Command Complete (LE Set Extended Scan Parameters)
93  2.074911    host    controller  HCI_CMD 18  Sent Vendor Command 0x002B (opcode 0xFC2B)
94  2.076893    controller  host    HCI_EVT 7   Rcvd Command Complete (LE Set Extended Scan Parameters)
95  2.076900    host    controller  HCI_CMD 16  Sent Vendor Command 0x002B (opcode 0xFC2B)
96  2.078904    controller  host    HCI_EVT 7   Rcvd Command Complete (LE Set Extended Scan Enable)
97  2.078928    host    controller  HCI_CMD 16  Sent Vendor Command 0x002B (opcode 0xFC2B)
98  2.081930    controller  host    HCI_EVT 7   Rcvd Command Complete (LE Set Extended Scan Enable)
99  2.081982    host    controller  HCI_CMD 16  Sent Vendor Command 0x002B (opcode 0xFC2B)
100 2.083896    controller  host    HCI_EVT 7   Rcvd Command Complete (LE Set Extended Scan Enable)
101 2.083913    host    controller  HCI_CMD 10  Sent LE Set Extended Scan Enable
102 2.086943    controller  host    HCI_EVT 7   Rcvd Command Complete (LE Set Extended Scan Enable)
103 2.086976    host    controller  HCI_CMD 11  Sent LE Add Device To Filter Accept List
104 2.088930    controller  host    HCI_EVT 7   Rcvd Command Complete (LE Add Device To Filter Accept List)
105 2.088964    host    controller  HCI_CMD 10  Sent LE Set Extended Scan Enable
106 2.090942    controller  host    HCI_EVT 7   Rcvd Command Complete (LE Set Extended Scan Enable)
107 2.091050    host    controller  HCI_CMD 30  Sent LE Extended Create Connection [v1]
108 2.093888    controller  host    HCI_EVT 7   Rcvd Command Status (LE Extended Create Connection [v1])
109 2.093921    host    controller  HCI_CMD 16  Sent Vendor Command 0x002B (opcode 0xFC2B)
110 2.095952    controller  host    HCI_EVT 7   Rcvd Command Complete (LE Set Extended Scan Enable)
111 2.096001    host    controller  HCI_CMD 16  Sent Vendor Command 0x002B (opcode 0xFC2B)
112 2.098946    controller  host    HCI_EVT 7   Rcvd Command Complete (LE Set Extended Scan Enable)
113 2.098996    host    controller  HCI_CMD 18  Sent Vendor Command 0x002B (opcode 0xFC2B)
114 2.100905    controller  host    HCI_EVT 7   Rcvd Command Complete (LE Set Extended Scan Parameters)
115 2.100937    host    controller  HCI_CMD 18  Sent Vendor Command 0x002B (opcode 0xFC2B)
116 2.102922    controller  host    HCI_EVT 7   Rcvd Command Complete (LE Set Extended Scan Parameters)
117 2.102957    host    controller  HCI_CMD 16  Sent Vendor Command 0x002B (opcode 0xFC2B)
118 2.105916    controller  host    HCI_EVT 7   Rcvd Command Complete (LE Set Extended Scan Enable)
119 2.105954    host    controller  HCI_CMD 16  Sent Vendor Command 0x002B (opcode 0xFC2B)
120 2.108927    controller  host    HCI_EVT 7   Rcvd Command Complete (LE Set Extended Scan Enable)
121 2.556102    controller  host    HCI_EVT 34  Rcvd LE Meta (LE Enhanced Connection Complete [v1])
122 2.556678    host    controller  HCI_CMD 6   Sent LE Read Channel Map
123 2.557076    controller  host    HCI_EVT 36  Rcvd Vendor-Specific
124 2.559112    controller  host    HCI_EVT 14  Rcvd Command Complete (LE Read Channel Map)
125 2.559320    host    controller  HCI_CMD 14  Sent Remote Name Request
126 2.561055    controller  host    HCI_EVT 7   Rcvd Command Status (Remote Name Request)
127 2.561775    localhost ()    Suunto_3e:57:61 (Movesense 214230001254)    ATT 12  Sent Exchange MTU Request, Client Rx MTU: 527
128 2.563320    Suunto_3e:57:61 (Movesense 214230001254)    localhost ()    L2CAP   21  Rcvd Connection Parameter Update Request
129 2.563371    localhost ()    Suunto_3e:57:61 (Movesense 214230001254)    L2CAP   15  Sent Connection Parameter Update Response (Accepted)
130 2.580003    controller  host    HCI_EVT 8   Rcvd Number of Completed Packets
131 2.593123    Suunto_3e:57:61 (Movesense 214230001254)    localhost ()    ATT 12  Rcvd Exchange MTU Request, Client Rx MTU: 161
132 2.593750    localhost ()    Suunto_3e:57:61 (Movesense 214230001254)    ATT 12  Sent Exchange MTU Response, Server Rx MTU: 527
133 2.595087    controller  host    HCI_EVT 8   Rcvd Number of Completed Packets
134 2.608161    Suunto_3e:57:61 (Movesense 214230001254)    localhost ()    ATT 12  Rcvd Exchange MTU Response, Server Rx MTU: 161
135 2.608665    localhost ()    Suunto_3e:57:61 (Movesense 214230001254)    ATT 18  Sent Find By Type Value Request, Primary Service, Handles: 0x0001..0xffff
136 2.625010    controller  host    HCI_EVT 8   Rcvd Number of Completed Packets
137 2.640025    controller  host    HCI_EVT 8   Rcvd Number of Completed Packets
138 2.641013    controller  host    HCI_EVT 14  Rcvd LE Meta (LE Data Length Change)
139 2.653206    Suunto_3e:57:61 (Movesense 214230001254)    localhost ()    ATT 14  Rcvd Find By Type Value Response
140 2.653843    localhost ()    Suunto_3e:57:61 (Movesense 214230001254)    ATT 18  Sent Find By Type Value Request, Primary Service, Handles: 0x000e..0xffff
141 2.670010    controller  host    HCI_EVT 8   Rcvd Number of Completed Packets
142 2.683733    Suunto_3e:57:61 (Movesense 214230001254)    localhost ()    ATT 14  Rcvd Error Response - Attribute Not Found, Handle: 0x000e (Unknown)
143 2.684541    localhost ()    Suunto_3e:57:61 (Movesense 214230001254)    ATT 16  Sent Read By Type Request, Characteristic, Handles: 0x000a..0x000d
144 2.700102    controller  host    HCI_EVT 8   Rcvd Number of Completed Packets
145 2.728146    Suunto_3e:57:61 (Movesense 214230001254)    localhost ()    ATT 18  Rcvd Read By Type Response, Attribute List Length: 1, Service Changed
146 2.729149    localhost ()    Suunto_3e:57:61 (Movesense 214230001254)    ATT 16  Sent Read By Type Request, Characteristic, Handles: 0x000c..0x000d
147 2.760087    controller  host    HCI_EVT 8   Rcvd Number of Completed Packets
148 2.773169    Suunto_3e:57:61 (Movesense 214230001254)    localhost ()    ATT 14  Rcvd Error Response - Attribute Not Found, Handle: 0x000c (Unknown: Service Changed)
149 2.773798    localhost ()    Suunto_3e:57:61 (Movesense 214230001254)    ATT 14  Sent Find Information Request, Handles: 0x000d..0x000d
150 2.790064    controller  host    HCI_EVT 8   Rcvd Number of Completed Packets
151 2.803216    Suunto_3e:57:61 (Movesense 214230001254)    localhost ()    ATT 15  Rcvd Find Information Response, Handle: 0x000d (Unknown: Service Changed: Client Characteristic Configuration)
152 2.804256    localhost ()    Suunto_3e:57:61 (Movesense 214230001254)    ATT 14  Sent Write Request, Handle: 0x000d (Unknown: Service Changed: Client Characteristic Configuration)
153 2.820084    controller  host    HCI_EVT 8   Rcvd Number of Completed Packets
154 2.909112    controller  host    HCI_EVT 9   Rcvd LE Meta (LE PHY Update Complete)
155 4.711307    controller  host    HCI_EVT 38  Rcvd LE Meta (LE Extended Advertising Report)
156 6.810312    controller  host    HCI_EVT 7   Rcvd Disconnect Complete
157 6.811045    controller  host    HCI_EVT 37  Rcvd Vendor-Specific
158 7.685043    controller  host    HCI_EVT 258 Rcvd Remote Name Request Complete
159 7.685388    host    controller  HCI_CMD 30  Sent LE Extended Create Connection [v1]
160 7.692025    controller  host    HCI_EVT 7   Rcvd Command Status (LE Extended Create Connection [v1])
161 7.753007    controller  host    HCI_EVT 34  Rcvd LE Meta (LE Enhanced Connection Complete [v1])
162 7.753198    host    controller  HCI_CMD 6   Sent LE Read Channel Map
163 7.754013    controller  host    HCI_EVT 36  Rcvd Vendor-Specific
164 7.754990    controller  host    HCI_EVT 14  Rcvd Command Complete (LE Read Channel Map)
165 7.755146    host    controller  HCI_CMD 14  Sent Remote Name Request
166 7.755923    localhost ()    Suunto_3e:57:61 (Movesense 214230001254)    ATT 12  Sent Exchange MTU Request, Client Rx MTU: 527
167 7.756993    controller  host    HCI_EVT 7   Rcvd Command Status (Remote Name Request)
168 7.768240    Suunto_3e:57:61 (Movesense 214230001254)    localhost ()    L2CAP   21  Rcvd Connection Parameter Update Request
169 7.768259    localhost ()    Suunto_3e:57:61 (Movesense 214230001254)    L2CAP   15  Sent Connection Parameter Update Response (Accepted)
170 7.785031    controller  host    HCI_EVT 8   Rcvd Number of Completed Packets
171 7.798157    Suunto_3e:57:61 (Movesense 214230001254)    localhost ()    ATT 12  Rcvd Exchange MTU Request, Client Rx MTU: 161
172 7.798662    localhost ()    Suunto_3e:57:61 (Movesense 214230001254)    ATT 12  Sent Exchange MTU Response, Server Rx MTU: 527
173 7.800003    controller  host    HCI_EVT 8   Rcvd Number of Completed Packets
174 7.813102    Suunto_3e:57:61 (Movesense 214230001254)    localhost ()    ATT 12  Rcvd Exchange MTU Response, Server Rx MTU: 161
175 7.813461    localhost ()    Suunto_3e:57:61 (Movesense 214230001254)    ATT 18  Sent Find By Type Value Request, Primary Service, Handles: 0x0001..0xffff
176 7.829091    controller  host    HCI_EVT 8   Rcvd Number of Completed Packets
177 7.845010    controller  host    HCI_EVT 8   Rcvd Number of Completed Packets
178 7.845944    controller  host    HCI_EVT 14  Rcvd LE Meta (LE Data Length Change)
179 7.858215    Suunto_3e:57:61 (Movesense 214230001254)    localhost ()    ATT 14  Rcvd Find By Type Value Response
180 7.858544    localhost ()    Suunto_3e:57:61 (Movesense 214230001254)    ATT 18  Sent Find By Type Value Request, Primary Service, Handles: 0x000e..0xffff
181 7.875076    controller  host    HCI_EVT 8   Rcvd Number of Completed Packets
182 7.888279    Suunto_3e:57:61 (Movesense 214230001254)    localhost ()    ATT 14  Rcvd Error Response - Attribute Not Found, Handle: 0x000e (Unknown)
183 7.889203    localhost ()    Suunto_3e:57:61 (Movesense 214230001254)    ATT 16  Sent Read By Type Request, Characteristic, Handles: 0x000a..0x000d
184 7.905082    controller  host    HCI_EVT 8   Rcvd Number of Completed Packets
185 7.933245    Suunto_3e:57:61 (Movesense 214230001254)    localhost ()    ATT 18  Rcvd Read By Type Response, Attribute List Length: 1, Service Changed
186 7.933967    localhost ()    Suunto_3e:57:61 (Movesense 214230001254)    ATT 16  Sent Read By Type Request, Characteristic, Handles: 0x000c..0x000d
187 7.965084    controller  host    HCI_EVT 8   Rcvd Number of Completed Packets
188 7.978085    Suunto_3e:57:61 (Movesense 214230001254)    localhost ()    ATT 14  Rcvd Error Response - Attribute Not Found, Handle: 0x000c (Unknown: Service Changed)
189 7.979102    localhost ()    Suunto_3e:57:61 (Movesense 214230001254)    ATT 14  Sent Find Information Request, Handles: 0x000d..0x000d
190 7.995107    controller  host    HCI_EVT 8   Rcvd Number of Completed Packets
191 8.008147    Suunto_3e:57:61 (Movesense 214230001254)    localhost ()    ATT 15  Rcvd Find Information Response, Handle: 0x000d (Unknown: Service Changed: Client Characteristic Configuration)
192 8.012128    localhost ()    Suunto_3e:57:61 (Movesense 214230001254)    ATT 14  Sent Write Request, Handle: 0x000d (Unknown: Service Changed: Client Characteristic Configuration)
193 8.025000    controller  host    HCI_EVT 8   Rcvd Number of Completed Packets
194 8.114103    controller  host    HCI_EVT 9   Rcvd LE Meta (LE PHY Update Complete)
195 10.013065   controller  host    HCI_EVT 38  Rcvd LE Meta (LE Extended Advertising Report)
196 12.015134   controller  host    HCI_EVT 7   Rcvd Disconnect Complete
197 12.016037   controller  host    HCI_EVT 37  Rcvd Vendor-Specific
198 12.627107   controller  host    HCI_EVT 38  Rcvd LE Meta (LE Extended Advertising Report)
199 12.892081   controller  host    HCI_EVT 258 Rcvd Remote Name Request Complete
200 12.892434   host    controller  HCI_CMD 30  Sent LE Extended Create Connection [v1]
201 12.894989   controller  host    HCI_EVT 7   Rcvd Command Status (LE Extended Create Connection [v1])
202 13.149137   controller  host    HCI_EVT 34  Rcvd LE Meta (LE Enhanced Connection Complete [v1])
203 13.149493   host    controller  HCI_CMD 6   Sent LE Read Channel Map
204 13.149984   controller  host    HCI_EVT 36  Rcvd Vendor-Specific
205 13.150917   controller  host    HCI_EVT 14  Rcvd Command Complete (LE Read Channel Map)
206 13.152028   localhost ()    Suunto_3e:57:61 (Movesense 214230001254)    ATT 12  Sent Exchange MTU Request, Client Rx MTU: 527
207 13.153213   Suunto_3e:57:61 (Movesense 214230001254)    localhost ()    L2CAP   21  Rcvd Connection Parameter Update Request
208 13.153238   localhost ()    Suunto_3e:57:61 (Movesense 214230001254)    L2CAP   15  Sent Connection Parameter Update Response (Accepted)
209 13.170030   controller  host    HCI_EVT 8   Rcvd Number of Completed Packets
210 13.183110   Suunto_3e:57:61 (Movesense 214230001254)    localhost ()    ATT 12  Rcvd Exchange MTU Request, Client Rx MTU: 161
211 13.183494   localhost ()    Suunto_3e:57:61 (Movesense 214230001254)    ATT 12  Sent Exchange MTU Response, Server Rx MTU: 527
212 13.184970   controller  host    HCI_EVT 8   Rcvd Number of Completed Packets
213 13.198116   Suunto_3e:57:61 (Movesense 214230001254)    localhost ()    ATT 12  Rcvd Exchange MTU Response, Server Rx MTU: 161
214 13.198424   localhost ()    Suunto_3e:57:61 (Movesense 214230001254)    ATT 18  Sent Find By Type Value Request, Primary Service, Handles: 0x0001..0xffff
215 13.213995   controller  host    HCI_EVT 8   Rcvd Number of Completed Packets
216 13.230093   controller  host    HCI_EVT 8   Rcvd Number of Completed Packets
217 13.231027   controller  host    HCI_EVT 14  Rcvd LE Meta (LE Data Length Change)
218 13.243316   Suunto_3e:57:61 (Movesense 214230001254)    localhost ()    ATT 14  Rcvd Find By Type Value Response
219 13.243966   localhost ()    Suunto_3e:57:61 (Movesense 214230001254)    ATT 18  Sent Find By Type Value Request, Primary Service, Handles: 0x000e..0xffff
220 13.260087   controller  host    HCI_EVT 8   Rcvd Number of Completed Packets
221 13.273257   Suunto_3e:57:61 (Movesense 214230001254)    localhost ()    ATT 14  Rcvd Error Response - Attribute Not Found, Handle: 0x000e (Unknown)
222 13.273977   localhost ()    Suunto_3e:57:61 (Movesense 214230001254)    ATT 16  Sent Read By Type Request, Characteristic, Handles: 0x000a..0x000d
223 13.290023   controller  host    HCI_EVT 8   Rcvd Number of Completed Packets
224 13.318201   Suunto_3e:57:61 (Movesense 214230001254)    localhost ()    ATT 18  Rcvd Read By Type Response, Attribute List Length: 1, Service Changed
225 13.319065   localhost ()    Suunto_3e:57:61 (Movesense 214230001254)    ATT 16  Sent Read By Type Request, Characteristic, Handles: 0x000c..0x000d
226 13.350104   controller  host    HCI_EVT 8   Rcvd Number of Completed Packets
227 13.363325   Suunto_3e:57:61 (Movesense 214230001254)    localhost ()    ATT 14  Rcvd Error Response - Attribute Not Found, Handle: 0x000c (Unknown: Service Changed)
228 13.364312   localhost ()    Suunto_3e:57:61 (Movesense 214230001254)    ATT 14  Sent Find Information Request, Handles: 0x000d..0x000d
229 13.380102   controller  host    HCI_EVT 8   Rcvd Number of Completed Packets
230 13.393330   Suunto_3e:57:61 (Movesense 214230001254)    localhost ()    ATT 15  Rcvd Find Information Response, Handle: 0x000d (Unknown: Service Changed: Client Characteristic Configuration)
231 13.394256   localhost ()    Suunto_3e:57:61 (Movesense 214230001254)    ATT 14  Sent Write Request, Handle: 0x000d (Unknown: Service Changed: Client Characteristic Configuration)
232 13.410098   controller  host    HCI_EVT 8   Rcvd Number of Completed Packets
233 13.499097   controller  host    HCI_EVT 9   Rcvd LE Meta (LE PHY Update Complete)
234 14.672110   controller  host    HCI_EVT 38  Rcvd LE Meta (LE Extended Advertising Report)
235 16.931612   controller  host    HCI_EVT 38  Rcvd LE Meta (LE Extended Advertising Report)
236 17.399488   controller  host    HCI_EVT 7   Rcvd Disconnect Complete
237 17.400488   controller  host    HCI_EVT 37  Rcvd Vendor-Specific
238 17.402206   host    controller  HCI_CMD 30  Sent LE Extended Create Connection [v1]
239 17.404437   controller  host    HCI_EVT 7   Rcvd Command Status (LE Extended Create Connection [v1])
240 17.587590   controller  host    HCI_EVT 34  Rcvd LE Meta (LE Enhanced Connection Complete [v1])
241 17.587934   host    controller  HCI_CMD 6   Sent LE Read Channel Map
242 17.588489   controller  host    HCI_EVT 36  Rcvd Vendor-Specific
243 17.590548   controller  host    HCI_EVT 14  Rcvd Command Complete (LE Read Channel Map)
244 17.592483   localhost ()    Suunto_3e:57:61 (Movesense 214230001254)    ATT 12  Sent Exchange MTU Request, Client Rx MTU: 527
245 17.593233   Suunto_3e:57:61 (Movesense 214230001254)    localhost ()    L2CAP   21  Rcvd Connection Parameter Update Request
246 17.593287   localhost ()    Suunto_3e:57:61 (Movesense 214230001254)    L2CAP   15  Sent Connection Parameter Update Response (Accepted)
247 17.609432   controller  host    HCI_EVT 8   Rcvd Number of Completed Packets
248 17.623100   Suunto_3e:57:61 (Movesense 214230001254)    localhost ()    ATT 12  Rcvd Exchange MTU Request, Client Rx MTU: 161
249 17.623403   localhost ()    Suunto_3e:57:61 (Movesense 214230001254)    ATT 12  Sent Exchange MTU Response, Server Rx MTU: 527
250 17.624424   controller  host    HCI_EVT 8   Rcvd Number of Completed Packets
251 17.638141   Suunto_3e:57:61 (Movesense 214230001254)    localhost ()    ATT 12  Rcvd Exchange MTU Response, Server Rx MTU: 161
252 17.638609   localhost ()    Suunto_3e:57:61 (Movesense 214230001254)    ATT 18  Sent Find By Type Value Request, Primary Service, Handles: 0x0001..0xffff
253 17.654469   controller  host    HCI_EVT 8   Rcvd Number of Completed Packets
254 17.670488   controller  host    HCI_EVT 8   Rcvd Number of Completed Packets
255 17.671455   controller  host    HCI_EVT 14  Rcvd LE Meta (LE Data Length Change)
256 17.683212   Suunto_3e:57:61 (Movesense 214230001254)    localhost ()    ATT 14  Rcvd Find By Type Value Response
257 17.683757   localhost ()    Suunto_3e:57:61 (Movesense 214230001254)    ATT 18  Sent Find By Type Value Request, Primary Service, Handles: 0x000e..0xffff
258 17.700462   controller  host    HCI_EVT 8   Rcvd Number of Completed Packets
259 17.713420   Suunto_3e:57:61 (Movesense 214230001254)    localhost ()    ATT 14  Rcvd Error Response - Attribute Not Found, Handle: 0x000e (Unknown)
260 17.714110   localhost ()    Suunto_3e:57:61 (Movesense 214230001254)    ATT 16  Sent Read By Type Request, Characteristic, Handles: 0x000a..0x000d
261 17.729520   controller  host    HCI_EVT 8   Rcvd Number of Completed Packets
262 17.758174   Suunto_3e:57:61 (Movesense 214230001254)    localhost ()    ATT 18  Rcvd Read By Type Response, Attribute List Length: 1, Service Changed
263 17.759054   localhost ()    Suunto_3e:57:61 (Movesense 214230001254)    ATT 16  Sent Read By Type Request, Characteristic, Handles: 0x000c..0x000d
264 17.789524   controller  host    HCI_EVT 8   Rcvd Number of Completed Packets
265 17.803110   Suunto_3e:57:61 (Movesense 214230001254)    localhost ()    ATT 14  Rcvd Error Response - Attribute Not Found, Handle: 0x000c (Unknown: Service Changed)
266 17.804005   localhost ()    Suunto_3e:57:61 (Movesense 214230001254)    ATT 14  Sent Find Information Request, Handles: 0x000d..0x000d
267 17.819520   controller  host    HCI_EVT 8   Rcvd Number of Completed Packets
268 17.833485   Suunto_3e:57:61 (Movesense 214230001254)    localhost ()    ATT 15  Rcvd Find Information Response, Handle: 0x000d (Unknown: Service Changed: Client Characteristic Configuration)
269 17.834600   localhost ()    Suunto_3e:57:61 (Movesense 214230001254)    ATT 14  Sent Write Request, Handle: 0x000d (Unknown: Service Changed: Client Characteristic Configuration)
270 17.849480   controller  host    HCI_EVT 8   Rcvd Number of Completed Packets
271 17.939530   controller  host    HCI_EVT 9   Rcvd LE Meta (LE PHY Update Complete)
272 19.418544   controller  host    HCI_EVT 38  Rcvd LE Meta (LE Extended Advertising Report)
273 20.155544   controller  host    HCI_EVT 38  Rcvd LE Meta (LE Extended Advertising Report)
274 20.582506   controller  host    HCI_EVT 38  Rcvd LE Meta (LE Extended Advertising Report)
275 21.628512   controller  host    HCI_EVT 38  Rcvd LE Meta (LE Extended Advertising Report)
276 21.839511   controller  host    HCI_EVT 7   Rcvd Disconnect Complete
277 21.840467   controller  host    HCI_EVT 37  Rcvd Vendor-Specific
278 21.846968   host    controller  HCI_CMD 10  Sent LE Set Extended Scan Enable
279 21.849440   controller  host    HCI_EVT 7   Rcvd Command Complete (LE Set Extended Scan Enable)
280 21.849457   host    controller  HCI_CMD 11  Sent LE Remove Device From Filter Accept List
281 21.851439   controller  host    HCI_EVT 7   Rcvd Command Complete (LE Remove Device From Filter Accept List)
282 21.851456   host    controller  HCI_CMD 10  Sent LE Set Extended Scan Enable
283 21.853433   controller  host    HCI_EVT 7   Rcvd Command Complete (LE Set Extended Scan Enable)
284 21.853450   host    controller  HCI_CMD 16  Sent Vendor Command 0x002B (opcode 0xFC2B)
285 21.872442   controller  host    HCI_EVT 7   Rcvd Command Complete (LE Set Extended Scan Enable)
286 21.872586   host    controller  HCI_CMD 16  Sent Vendor Command 0x002B (opcode 0xFC2B)
287 21.874484   controller  host    HCI_EVT 7   Rcvd Command Complete (LE Set Extended Scan Enable)
288 21.874554   host    controller  HCI_CMD 18  Sent Vendor Command 0x002B (opcode 0xFC2B)
289 21.876485   controller  host    HCI_EVT 7   Rcvd Command Complete (LE Set Extended Scan Parameters)
290 21.876759   host    controller  HCI_CMD 18  Sent Vendor Command 0x002B (opcode 0xFC2B)
291 21.878454   controller  host    HCI_EVT 7   Rcvd Command Complete (LE Set Extended Scan Parameters)
292 21.878497   host    controller  HCI_CMD 16  Sent Vendor Command 0x002B (opcode 0xFC2B)
293 21.880433   controller  host    HCI_EVT 7   Rcvd Command Complete (LE Set Extended Scan Enable)
294 21.880580   host    controller  HCI_CMD 16  Sent Vendor Command 0x002B (opcode 0xFC2B)
295 21.894473   controller  host    HCI_EVT 7   Rcvd Command Complete (LE Set Extended Scan Enable)
dlech commented 1 month ago

FYI, you can put them in a .zip file and upload them. But I think we can see enough info from the pasted log.

269 17.834600   localhost ()    Suunto_3e:57:61 (Movesense 214230001254)    ATT 14  Sent Write Request, Handle: 0x000d (Unknown: Service Changed: Client Characteristic Configuration)

There is no reply from this request, so it looks like you have a defective Bluetooth peripheral.

You might be able to avoid this by trying the use_cached_services=False argument. See https://bleak.readthedocs.io/en/latest/backends/windows.html#bleak.backends.winrt.client.WinRTClientArgs.use_cached_services.

hopethis commented 1 month ago

Thanks, whats odd is that it seems to work with other computer pretty well and everytime I reboot the machine its working as well. Passing the option used cached services to False unfortunally didnt solve the issue.

dlech commented 1 month ago

You could do a packet capture of the working cases and compare them to the not working cases to see what the difference is.

Aeva commented 1 month ago

This started happening for me recently on Linux.

Bleak: 0.22.2 Python: 3.12.4 OS: Fedora 40 bluetoothctl: 5.77

The version of bleak I have installed was through pip. This may have been due to me switching from NixOS to Fedora. The version of bleak I had on NixOS was installed via some nix magic, whereas the version of bleak I have installed now was just the one available on pip. I don't recall if this ever worked correctly on Fedora / with pip version.

This is the error that prints the second time I try to run my program after a successful first run:

Traceback (most recent call last):
  File "/home/aeva/.local/lib/python3.12/site-packages/bleak/backends/bluezdbus/client.py", line 273, in connect
    await self.get_services(
  File "/home/aeva/.local/lib/python3.12/site-packages/bleak/backends/bluezdbus/client.py", line 661, in get_services
    self.services = await manager.get_services(
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/aeva/.local/lib/python3.12/site-packages/bleak/backends/bluezdbus/manager.py", line 666, in get_services
    await self._wait_for_services_discovery(device_path)
  File "/home/aeva/.local/lib/python3.12/site-packages/bleak/backends/bluezdbus/manager.py", line 783, in _wait_for_services_discovery
    done, _ = await asyncio.wait(
              ^^^^^^^^^^^^^^^^^^^
  File "/usr/lib64/python3.12/asyncio/tasks.py", line 464, in wait
    return await _wait(fs, timeout, return_when, loop)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib64/python3.12/asyncio/tasks.py", line 550, in _wait
    await waiter
asyncio.exceptions.CancelledError

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/lib64/python3.12/multiprocessing/process.py", line 314, in _bootstrap
    self.run()
  File "/usr/lib64/python3.12/multiprocessing/process.py", line 108, in run
    self._target(*self._args, **self._kwargs)
  File "/home/aeva/science/autonomia/autonomia/bluetooth.py", line 110, in heart_monitor_proc
    asyncio.run(heart_monitor_runner(command_queue, event_queue, device_address))
  File "/usr/lib64/python3.12/asyncio/runners.py", line 194, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "/usr/lib64/python3.12/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib64/python3.12/asyncio/base_events.py", line 687, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "/home/aeva/science/autonomia/autonomia/bluetooth.py", line 69, in heart_monitor_runner
    async with BleakClient(device_address) as client:
  File "/home/aeva/.local/lib/python3.12/site-packages/bleak/__init__.py", line 570, in __aenter__
    await self.connect()
  File "/home/aeva/.local/lib/python3.12/site-packages/bleak/__init__.py", line 615, in connect
    return await self._backend.connect(**kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/aeva/.local/lib/python3.12/site-packages/bleak/backends/bluezdbus/client.py", line 151, in connect
    async with async_timeout(timeout):
  File "/usr/lib64/python3.12/asyncio/timeouts.py", line 115, in __aexit__
    raise TimeoutError from exc_val
TimeoutError

Rebooting my computer is the only thing that has worked so far to let me run my program again :/

dlech commented 3 weeks ago

This started happening for me recently on Linux.

This issue is about Windows, not Linux. So please start a new issue for the Linux issue and include a full reproducible test case.