Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix get_services() fails because no GattSession #973

Merged
merged 5 commits into from
Sep 5, 2022

Conversation

nv-h
Copy link
Contributor

@nv-h nv-h commented Sep 2, 2022

Since the following error occurred when connecting, set the MTU to the default 20 to avoid it.
AttributeError: 'NoneType' object has no attribute 'max_pdu_size'

  File "C:\Users\saido\scoop\apps\python39\current\lib\site-packages\bleak\backends\winrt\client.py", line 331, in connect
    await self.get_services()
  File "C:\Users\saido\scoop\apps\python39\current\lib\site-packages\bleak\backends\winrt\client.py", line 547, in get_services
    characteristic, self._session.max_pdu_size - 3
AttributeError: 'NoneType' object has no attribute 'max_pdu_size'

Tested by Python 3.9 on Windows 11.

Since the following error occurred when connecting, set the MTU to the default 20 to avoid it.
`AttributeError: 'NoneType' object has no attribute 'max_pdu_size'`
@dlech
Copy link
Collaborator

dlech commented Sep 2, 2022

If self._session is None, then we have disconnected already so I am a bit surprised that this workaround seems to work. Can you share the code that reproduces the problem and debug logs from when this problem occurs.

@dlech dlech added the Backend: WinRT Issues or PRs relating to the WinRT backend label Sep 2, 2022
@nv-h
Copy link
Contributor Author

nv-h commented Sep 2, 2022

@dlech Thank you for your reply!

Test code is here: https://github.com/nv-h/nRF52_sensors/blob/master/test/search_and_connect.py
I am attaching the debug log below. It doesn't seem to happen every time.

> python .\test\search_and_connect.py
2022-09-03 06:08:42,234 bleak.backends.winrt.scanner DEBUG: Received 3D:E6:F1:FB:EE:40: Unknown.
2022-09-03 06:08:42,292 bleak.backends.winrt.scanner DEBUG: Received 05:8F:CF:97:48:1E: Unknown.
2022-09-03 06:08:42,379 bleak.backends.winrt.scanner DEBUG: Received 66:02:66:1D:43:61: Unknown.
2022-09-03 06:08:42,390 bleak.backends.winrt.scanner DEBUG: Received 66:02:66:1D:43:61: Unknown.
2022-09-03 06:08:42,600 bleak.backends.winrt.scanner DEBUG: Received C7:9B:E9:C7:9B:EA: WM2.
2022-09-03 06:08:42,618 bleak.backends.winrt.scanner DEBUG: Received C7:9B:E9:C7:9B:EA: Unknown.
2022-09-03 06:08:42,634 bleak.backends.winrt.scanner DEBUG: Received 6B:D8:E1:9F:A8:12: Unknown.
2022-09-03 06:08:42,650 bleak.backends.winrt.scanner DEBUG: Received 78:86:3A:E5:88:7B: Unknown.
2022-09-03 06:08:42,664 bleak.backends.winrt.scanner DEBUG: Received 6B:D8:E1:9F:A8:12: Unknown.
2022-09-03 06:08:42,888 bleak.backends.winrt.scanner DEBUG: Received 30:8D:98:80:D7:03: Unknown.
2022-09-03 06:08:43,117 bleak.backends.winrt.scanner DEBUG: Received 46:80:98:B7:5D:3B: Unknown.
2022-09-03 06:08:43,198 bleak.backends.winrt.scanner DEBUG: Received 66:02:66:1D:43:61: Unknown.
2022-09-03 06:08:43,210 bleak.backends.winrt.scanner DEBUG: Received 66:02:66:1D:43:61: Unknown.
2022-09-03 06:08:43,355 bleak.backends.winrt.scanner DEBUG: Received 05:8F:CF:97:48:1E: Unknown.
2022-09-03 06:08:43,514 bleak.backends.winrt.scanner DEBUG: Received 5C:98:9A:62:CC:CB: Unknown.
2022-09-03 06:08:43,538 bleak.backends.winrt.scanner DEBUG: Received 63:23:23:54:F6:CB: Unknown.
2022-09-03 06:08:43,557 bleak.backends.winrt.scanner DEBUG: Received 63:23:23:54:F6:CB: Unknown.
2022-09-03 06:08:43,573 bleak.backends.winrt.scanner DEBUG: Received 05:29:25:26:88:15: Unknown.
2022-09-03 06:08:43,734 bleak.backends.winrt.scanner DEBUG: Received 70:5A:8E:51:BA:87: Unknown.
2022-09-03 06:08:43,953 bleak.backends.winrt.scanner DEBUG: Received 78:86:3A:E5:88:7B: Unknown.
2022-09-03 06:08:44,031 bleak.backends.winrt.scanner DEBUG: Received 66:02:66:1D:43:61: Unknown.
2022-09-03 06:08:44,049 bleak.backends.winrt.scanner DEBUG: Received 38:20:6B:C3:C9:73: Unknown.
2022-09-03 06:08:44,255 bleak.backends.winrt.scanner DEBUG: Received 57:CD:71:F1:32:9A: Unknown.
2022-09-03 06:08:44,273 bleak.backends.winrt.scanner DEBUG: Received 57:CD:71:F1:32:9A: Unknown.
2022-09-03 06:08:44,299 bleak.backends.winrt.scanner DEBUG: Received C7:9B:E9:C7:9B:EA: WM2.
2022-09-03 06:08:44,313 bleak.backends.winrt.scanner DEBUG: Received C7:9B:E9:C7:9B:EA: Unknown.
2022-09-03 06:08:44,336 bleak.backends.winrt.scanner DEBUG: Received 50:25:C5:69:98:63: Unknown.
2022-09-03 06:08:44,406 bleak.backends.winrt.scanner DEBUG: Received 3D:E6:F1:FB:EE:40: Unknown.
2022-09-03 06:08:44,484 bleak.backends.winrt.scanner DEBUG: Received 78:86:3A:E5:88:7B: Unknown.
2022-09-03 06:08:44,517 bleak.backends.winrt.scanner DEBUG: Received C7:9B:E9:C7:9B:EA: WM2.
2022-09-03 06:08:44,534 bleak.backends.winrt.scanner DEBUG: Received C7:9B:E9:C7:9B:EA: Unknown.
2022-09-03 06:08:44,770 bleak.backends.winrt.scanner DEBUG: Received 32:1F:4A:1D:D7:70: Unknown.
2022-09-03 06:08:44,805 bleak.backends.winrt.scanner DEBUG: Received 6B:92:42:AC:10:37: Unknown.
2022-09-03 06:08:44,824 bleak.backends.winrt.scanner DEBUG: Received 6B:92:42:AC:10:37: Unknown.
2022-09-03 06:08:44,848 bleak.backends.winrt.scanner DEBUG: Received 78:86:3A:E5:88:7B: Unknown.
2022-09-03 06:08:44,872 bleak.backends.winrt.scanner DEBUG: Received 4E:D9:AE:7B:F9:3B: Unknown.
2022-09-03 06:08:44,898 bleak.backends.winrt.scanner DEBUG: Received 66:02:66:1D:43:61: Unknown.
2022-09-03 06:08:44,936 bleak.backends.winrt.scanner DEBUG: Received 51:6A:84:8C:55:E6: Unknown.
2022-09-03 06:08:44,952 bleak.backends.winrt.scanner DEBUG: Received 51:6A:84:8C:55:E6: Unknown.
2022-09-03 06:08:44,973 bleak.backends.winrt.scanner DEBUG: Received 2E:51:70:41:A9:42: Unknown.
2022-09-03 06:08:45,007 bleak.backends.winrt.scanner DEBUG: Received C7:9B:E9:C7:9B:EA: WM2.
2022-09-03 06:08:45,020 bleak.backends.winrt.scanner DEBUG: Received C7:9B:E9:C7:9B:EA: Unknown.
2022-09-03 06:08:45,159 bleak.backends.winrt.scanner DEBUG: Received C7:9B:E9:C7:9B:EA: WM2.
2022-09-03 06:08:45,182 bleak.backends.winrt.scanner DEBUG: Received 50:25:C5:69:98:63: Unknown.
2022-09-03 06:08:45,303 bleak.backends.winrt.scanner DEBUG: Received 78:86:3A:E5:88:7B: Unknown.
2022-09-03 06:08:45,383 bleak.backends.winrt.scanner DEBUG: Received C7:9B:E9:C7:9B:EA: WM2.
2022-09-03 06:08:45,451 bleak.backends.winrt.scanner DEBUG: Received E6:B5:EC:E5:10:BB: Unknown.
2022-09-03 06:08:45,548 bleak.backends.winrt.scanner DEBUG: Received C7:9B:E9:C7:9B:EA: WM2.
2022-09-03 06:08:45,727 bleak.backends.winrt.scanner DEBUG: Received 6B:92:42:AC:10:37: Unknown.
2022-09-03 06:08:45,753 bleak.backends.winrt.scanner DEBUG: Received 66:02:66:1D:43:61: Unknown.
2022-09-03 06:08:45,769 bleak.backends.winrt.scanner DEBUG: Received 66:02:66:1D:43:61: Unknown.
2022-09-03 06:08:45,863 bleak.backends.winrt.scanner DEBUG: Received 63:23:23:54:F6:CB: Unknown.
2022-09-03 06:08:45,885 bleak.backends.winrt.scanner DEBUG: Received 63:23:23:54:F6:CB: Unknown.
2022-09-03 06:08:45,909 bleak.backends.winrt.scanner DEBUG: Received 78:86:3A:E5:88:7B: Unknown.
2022-09-03 06:08:46,014 bleak.backends.winrt.scanner DEBUG: Received 5C:98:9A:62:CC:CB: Unknown.
2022-09-03 06:08:46,033 bleak.backends.winrt.scanner DEBUG: Received 5C:98:9A:62:CC:CB: Unknown.
2022-09-03 06:08:46,074 bleak.backends.winrt.scanner DEBUG: Received C7:9B:E9:C7:9B:EA: WM2.
2022-09-03 06:08:46,094 bleak.backends.winrt.scanner DEBUG: Received 05:8F:CF:97:48:1E: Unknown.
2022-09-03 06:08:46,212 bleak.backends.winrt.scanner DEBUG: Received C7:9B:E9:C7:9B:EA: WM2.
2022-09-03 06:08:46,228 bleak.backends.winrt.scanner DEBUG: Received C7:9B:E9:C7:9B:EA: Unknown.
2022-09-03 06:08:46,355 bleak.backends.winrt.scanner DEBUG: Received 78:86:3A:E5:88:7B: Unknown.
2022-09-03 06:08:46,573 bleak.backends.winrt.scanner DEBUG: Received 05:8F:CF:97:48:1E: Unknown.
2022-09-03 06:08:46,604 bleak.backends.winrt.scanner DEBUG: Received C7:9B:E9:C7:9B:EA: WM2.
2022-09-03 06:08:46,619 bleak.backends.winrt.scanner DEBUG: Received C7:9B:E9:C7:9B:EA: Unknown.
2022-09-03 06:08:46,639 bleak.backends.winrt.scanner DEBUG: Received 4F:7B:43:3B:99:24: Unknown.
2022-09-03 06:08:46,952 bleak.backends.winrt.scanner DEBUG: Received 32:1F:4A:1D:D7:70: Unknown.
2022-09-03 06:08:47,046 bleak.backends.winrt.scanner DEBUG: Received C7:9B:E9:C7:9B:EA: WM2.
2022-09-03 06:08:47,060 bleak.backends.winrt.scanner DEBUG: 22 devices found. Watcher status: 3.
2022-09-03 06:08:47,063 bleak.backends.winrt.scanner DEBUG: Received C7:9B:E9:C7:9B:EA: Unknown.
No board found. [0]
2022-09-03 06:08:47,225 bleak.backends.winrt.scanner DEBUG: Received 32:1F:4A:1D:D7:70: Unknown.
2022-09-03 06:08:47,299 bleak.backends.winrt.scanner DEBUG: Received 05:8F:CF:97:48:1E: Unknown.
2022-09-03 06:08:47,369 bleak.backends.winrt.scanner DEBUG: Received 2E:51:70:41:A9:42: Unknown.
2022-09-03 06:08:47,392 bleak.backends.winrt.scanner DEBUG: Received C7:9B:E9:C7:9B:EA: WM2.
2022-09-03 06:08:47,589 bleak.backends.winrt.scanner DEBUG: Received 5F:48:AC:27:B6:44: Unknown.
2022-09-03 06:08:47,679 bleak.backends.winrt.scanner DEBUG: Received C7:9B:E9:C7:9B:EA: WM2.
2022-09-03 06:08:47,692 bleak.backends.winrt.scanner DEBUG: Received C7:9B:E9:C7:9B:EA: Unknown.
2022-09-03 06:08:47,709 bleak.backends.winrt.scanner DEBUG: Received EE:3A:A8:66:DC:F7: Unknown.
2022-09-03 06:08:47,767 bleak.backends.winrt.scanner DEBUG: Received 6B:D8:E1:9F:A8:12: Unknown.
2022-09-03 06:08:47,789 bleak.backends.winrt.scanner DEBUG: Received 6B:D8:E1:9F:A8:12: Unknown.
2022-09-03 06:08:47,834 bleak.backends.winrt.scanner DEBUG: Received 46:80:98:B7:5D:3B: Unknown.
2022-09-03 06:08:47,853 bleak.backends.winrt.scanner DEBUG: Received 46:80:98:B7:5D:3B: Unknown.
2022-09-03 06:08:47,894 bleak.backends.winrt.scanner DEBUG: Received C7:9B:E9:C7:9B:EA: WM2.
2022-09-03 06:08:47,926 bleak.backends.winrt.scanner DEBUG: Received 50:25:C5:69:98:63: Unknown.
2022-09-03 06:08:47,947 bleak.backends.winrt.scanner DEBUG: Received 38:20:6B:C3:C9:73: Unknown.
2022-09-03 06:08:48,127 bleak.backends.winrt.scanner DEBUG: Received FA:CE:80:AA:9B:0F: Unknown.
2022-09-03 06:08:48,150 bleak.backends.winrt.scanner DEBUG: Received FA:CE:80:AA:9B:0F: Unknown.
2022-09-03 06:08:48,272 bleak.backends.winrt.scanner DEBUG: Received 11:29:36:F9:88:06: Unknown.
2022-09-03 06:08:48,354 bleak.backends.winrt.scanner DEBUG: Received 70:5A:8E:51:BA:87: Unknown.
2022-09-03 06:08:48,367 bleak.backends.winrt.scanner DEBUG: Received 70:5A:8E:51:BA:87: Unknown.
2022-09-03 06:08:48,391 bleak.backends.winrt.scanner DEBUG: Received C7:9B:E9:C7:9B:EA: WM2.
2022-09-03 06:08:48,406 bleak.backends.winrt.scanner DEBUG: Received C7:9B:E9:C7:9B:EA: Unknown.
2022-09-03 06:08:48,430 bleak.backends.winrt.scanner DEBUG: Received 4E:D9:AE:7B:F9:3B: Unknown.
2022-09-03 06:08:48,446 bleak.backends.winrt.scanner DEBUG: Received 4E:D9:AE:7B:F9:3B: Unknown.
2022-09-03 06:08:48,658 bleak.backends.winrt.scanner DEBUG: Received 5C:98:9A:62:CC:CB: Unknown.
2022-09-03 06:08:48,731 bleak.backends.winrt.scanner DEBUG: Received 50:25:C5:69:98:63: Unknown.
2022-09-03 06:08:48,749 bleak.backends.winrt.scanner DEBUG: Received 50:25:C5:69:98:63: Unknown.
2022-09-03 06:08:48,816 bleak.backends.winrt.scanner DEBUG: Received 2E:51:70:41:A9:42: Unknown.
2022-09-03 06:08:48,854 bleak.backends.winrt.scanner DEBUG: Received C7:9B:E9:C7:9B:EA: WM2.
2022-09-03 06:08:48,870 bleak.backends.winrt.scanner DEBUG: Received C7:9B:E9:C7:9B:EA: Unknown.
2022-09-03 06:08:48,891 bleak.backends.winrt.scanner DEBUG: Received 05:8F:CF:97:48:1E: Unknown.
2022-09-03 06:08:49,041 bleak.backends.winrt.scanner DEBUG: Received C7:9B:E9:C7:9B:EA: WM2.
2022-09-03 06:08:49,387 bleak.backends.winrt.scanner DEBUG: Received 32:1F:4A:1D:D7:70: Unknown.
2022-09-03 06:08:49,407 bleak.backends.winrt.scanner DEBUG: Received 78:86:3A:E5:88:7B: Unknown.
2022-09-03 06:08:49,481 bleak.backends.winrt.scanner DEBUG: Received 46:80:98:B7:5D:3B: Unknown.
2022-09-03 06:08:49,494 bleak.backends.winrt.scanner DEBUG: Received 46:80:98:B7:5D:3B: Unknown.
2022-09-03 06:08:49,770 bleak.backends.winrt.scanner DEBUG: Received FA:CE:80:AA:9B:0F: Unknown.
2022-09-03 06:08:49,867 bleak.backends.winrt.scanner DEBUG: Received C7:9B:E9:C7:9B:EA: WM2.
2022-09-03 06:08:49,895 bleak.backends.winrt.scanner DEBUG: Received 3D:E6:F1:FB:EE:40: Unknown.
2022-09-03 06:08:49,928 bleak.backends.winrt.scanner DEBUG: Received 05:8F:CF:97:48:1E: Unknown.
2022-09-03 06:08:49,952 bleak.backends.winrt.scanner DEBUG: Received 5C:98:9A:62:CC:CB: Unknown.
2022-09-03 06:08:49,974 bleak.backends.winrt.scanner DEBUG: Received 5C:98:9A:62:CC:CB: Unknown.
2022-09-03 06:08:50,000 bleak.backends.winrt.scanner DEBUG: Received 11:29:36:F9:88:06: Unknown.
2022-09-03 06:08:50,032 bleak.backends.winrt.scanner DEBUG: Received C7:9B:E9:C7:9B:EA: WM2.
2022-09-03 06:08:50,047 bleak.backends.winrt.scanner DEBUG: Received C7:9B:E9:C7:9B:EA: Unknown.
2022-09-03 06:08:50,073 bleak.backends.winrt.scanner DEBUG: Received 6B:D8:E1:9F:A8:12: Unknown.
2022-09-03 06:08:50,303 bleak.backends.winrt.scanner DEBUG: Received 46:80:98:B7:5D:3B: Unknown.
2022-09-03 06:08:50,381 bleak.backends.winrt.scanner DEBUG: Received 50:25:C5:69:98:63: Unknown.
2022-09-03 06:08:50,472 bleak.backends.winrt.scanner DEBUG: Received C7:9B:E9:C7:9B:EA: WM2.
2022-09-03 06:08:50,484 bleak.backends.winrt.scanner DEBUG: Received C7:9B:E9:C7:9B:EA: Unknown.
2022-09-03 06:08:50,538 bleak.backends.winrt.scanner DEBUG: Received 05:29:25:26:88:15: Unknown.
2022-09-03 06:08:50,644 bleak.backends.winrt.scanner DEBUG: Received 57:BA:2D:06:56:C8: Unknown.
2022-09-03 06:08:50,682 bleak.backends.winrt.scanner DEBUG: Received C7:9B:E9:C7:9B:EA: WM2.
2022-09-03 06:08:50,746 bleak.backends.winrt.scanner DEBUG: Received 32:1F:4A:1D:D7:70: Unknown.
2022-09-03 06:08:50,834 bleak.backends.winrt.scanner DEBUG: Received C7:9B:E9:C7:9B:EA: WM2.
2022-09-03 06:08:50,847 bleak.backends.winrt.scanner DEBUG: Received C7:9B:E9:C7:9B:EA: Unknown.
2022-09-03 06:08:50,980 bleak.backends.winrt.scanner DEBUG: Received 63:23:23:54:F6:CB: Unknown.
2022-09-03 06:08:50,995 bleak.backends.winrt.scanner DEBUG: Received 05:8F:CF:97:48:1E: Unknown.
2022-09-03 06:08:51,033 bleak.backends.winrt.scanner DEBUG: Received C7:9B:E9:C7:9B:EA: WM2.
2022-09-03 06:08:51,055 bleak.backends.winrt.scanner DEBUG: Received C7:9B:E9:C7:9B:EA: Unknown.
2022-09-03 06:08:51,084 bleak.backends.winrt.scanner DEBUG: Received 70:5A:8E:51:BA:87: Unknown.
2022-09-03 06:08:51,099 bleak.backends.winrt.scanner DEBUG: Received 70:5A:8E:51:BA:87: Unknown.
2022-09-03 06:08:51,138 bleak.backends.winrt.scanner DEBUG: Received 46:80:98:B7:5D:3B: Unknown.
2022-09-03 06:08:51,154 bleak.backends.winrt.scanner DEBUG: Received 46:80:98:B7:5D:3B: Unknown.
2022-09-03 06:08:51,280 bleak.backends.winrt.scanner DEBUG: Received 78:86:3A:E5:88:7B: Unknown.
2022-09-03 06:08:51,358 bleak.backends.winrt.scanner DEBUG: Received C7:9B:E9:C7:9B:EA: WM2.
2022-09-03 06:08:51,373 bleak.backends.winrt.scanner DEBUG: Received C7:9B:E9:C7:9B:EA: Unknown.
2022-09-03 06:08:51,725 bleak.backends.winrt.scanner DEBUG: Received 5F:48:AC:27:B6:44: Unknown.
2022-09-03 06:08:51,738 bleak.backends.winrt.scanner DEBUG: Received 5F:48:AC:27:B6:44: Unknown.
2022-09-03 06:08:51,780 bleak.backends.winrt.scanner DEBUG: Received C7:9B:E9:C7:9B:EA: WM2.
2022-09-03 06:08:51,795 bleak.backends.winrt.scanner DEBUG: Received C7:9B:E9:C7:9B:EA: Unknown.
2022-09-03 06:08:51,823 bleak.backends.winrt.scanner DEBUG: Received 05:8F:CF:97:48:1E: Unknown.
2022-09-03 06:08:51,877 bleak.backends.winrt.scanner DEBUG: Received 6B:D8:E1:9F:A8:12: Unknown.
2022-09-03 06:08:51,947 bleak.backends.winrt.scanner DEBUG: Received 46:80:98:B7:5D:3B: Unknown.
2022-09-03 06:08:51,959 bleak.backends.winrt.scanner DEBUG: Received 46:80:98:B7:5D:3B: Unknown.
2022-09-03 06:08:52,028 bleak.backends.winrt.scanner DEBUG: Received C7:9B:E9:C7:9B:EA: WM2.
2022-09-03 06:08:52,101 bleak.backends.winrt.scanner DEBUG: Received 05:29:25:26:88:15: Unknown.
2022-09-03 06:08:52,115 bleak.backends.winrt.scanner DEBUG: 20 devices found. Watcher status: 3.
No board found. [1]
2022-09-03 06:08:52,273 bleak.backends.winrt.scanner DEBUG: Received 4E:D9:AE:7B:F9:3B: Unknown.
2022-09-03 06:08:52,291 bleak.backends.winrt.scanner DEBUG: Received 4E:D9:AE:7B:F9:3B: Unknown.
2022-09-03 06:08:52,315 bleak.backends.winrt.scanner DEBUG: Received 63:23:23:54:F6:CB: Unknown.
2022-09-03 06:08:52,337 bleak.backends.winrt.scanner DEBUG: Received 63:23:23:54:F6:CB: Unknown.
2022-09-03 06:08:52,359 bleak.backends.winrt.scanner DEBUG: Received 5C:98:9A:62:CC:CB: Unknown.
2022-09-03 06:08:52,379 bleak.backends.winrt.scanner DEBUG: Received 5C:98:9A:62:CC:CB: Unknown.
2022-09-03 06:08:52,420 bleak.backends.winrt.scanner DEBUG: Received FA:CE:80:AA:9B:0F: Unknown.
2022-09-03 06:08:52,443 bleak.backends.winrt.scanner DEBUG: Received 70:5A:8E:51:BA:87: Unknown.
2022-09-03 06:08:52,458 bleak.backends.winrt.scanner DEBUG: Received 70:5A:8E:51:BA:87: Unknown.
2022-09-03 06:08:52,480 bleak.backends.winrt.scanner DEBUG: Received 57:CD:71:F1:32:9A: Unknown.
2022-09-03 06:08:52,577 bleak.backends.winrt.scanner DEBUG: Received C7:9B:E9:C7:9B:EA: WM2.
2022-09-03 06:08:52,592 bleak.backends.winrt.scanner DEBUG: Received C7:9B:E9:C7:9B:EA: Unknown.
2022-09-03 06:08:52,635 bleak.backends.winrt.scanner DEBUG: Received 05:8F:CF:97:48:1E: Unknown.
2022-09-03 06:08:52,796 bleak.backends.winrt.scanner DEBUG: Received 66:02:66:1D:43:61: Unknown.
2022-09-03 06:08:52,871 bleak.backends.winrt.scanner DEBUG: Received 50:25:C5:69:98:63: Unknown.
2022-09-03 06:08:52,885 bleak.backends.winrt.scanner DEBUG: Received 50:25:C5:69:98:63: Unknown.
2022-09-03 06:08:52,903 bleak.backends.winrt.scanner DEBUG: Received 38:20:6B:C3:C9:73: Unknown.
2022-09-03 06:08:52,943 bleak.backends.winrt.scanner DEBUG: Received 05:29:25:26:88:15: Unknown.
2022-09-03 06:08:53,021 bleak.backends.winrt.scanner DEBUG: Received C7:9B:E9:C7:9B:EA: WM2.
2022-09-03 06:08:53,042 bleak.backends.winrt.scanner DEBUG: Received C7:9B:E9:C7:9B:EA: Unknown.
2022-09-03 06:08:53,245 bleak.backends.winrt.scanner DEBUG: Received 57:CD:71:F1:32:9A: Unknown.
2022-09-03 06:08:53,260 bleak.backends.winrt.scanner DEBUG: Received 57:CD:71:F1:32:9A: Unknown.
2022-09-03 06:08:53,398 bleak.backends.winrt.scanner DEBUG: Received C7:9B:E9:C7:9B:EA: WM2.
2022-09-03 06:08:53,470 bleak.backends.winrt.scanner DEBUG: Received E9:7B:3A:20:B5:75: Unknown.
2022-09-03 06:08:53,492 bleak.backends.winrt.scanner DEBUG: Received 32:1F:4A:1D:D7:70: Unknown.
2022-09-03 06:08:53,625 bleak.backends.winrt.scanner DEBUG: Received C7:9B:E9:C7:9B:EA: WM2.
2022-09-03 06:08:53,687 bleak.backends.winrt.scanner DEBUG: Received 78:86:3A:E5:88:7B: Unknown.
2022-09-03 06:08:53,707 bleak.backends.winrt.scanner DEBUG: Received 50:25:C5:69:98:63: Unknown.
2022-09-03 06:08:53,720 bleak.backends.winrt.scanner DEBUG: Received 50:25:C5:69:98:63: Unknown.
2022-09-03 06:08:53,856 bleak.backends.winrt.scanner DEBUG: Received C7:9B:E9:C7:9B:EA: WM2.
2022-09-03 06:08:53,872 bleak.backends.winrt.scanner DEBUG: Received C7:9B:E9:C7:9B:EA: Unknown.
2022-09-03 06:08:53,990 bleak.backends.winrt.scanner DEBUG: Received 05:8F:CF:97:48:1E: Unknown.
2022-09-03 06:08:54,076 bleak.backends.winrt.scanner DEBUG: Received 63:23:23:54:F6:CB: Unknown.
2022-09-03 06:08:54,098 bleak.backends.winrt.scanner DEBUG: Received 63:23:23:54:F6:CB: Unknown.
2022-09-03 06:08:54,149 bleak.backends.winrt.scanner DEBUG: Received 57:BA:2D:06:56:C8: Unknown.
2022-09-03 06:08:54,217 bleak.backends.winrt.scanner DEBUG: Received 78:86:3A:E5:88:7B: Unknown.
2022-09-03 06:08:54,250 bleak.backends.winrt.scanner DEBUG: Received C7:9B:E9:C7:9B:EA: WM2.
2022-09-03 06:08:54,300 bleak.backends.winrt.scanner DEBUG: Received C7:9B:E9:C7:9B:EA: WM2.
2022-09-03 06:08:54,316 bleak.backends.winrt.scanner DEBUG: Received C7:9B:E9:C7:9B:EA: Unknown.
2022-09-03 06:08:54,516 bleak.backends.winrt.scanner DEBUG: Received 05:8F:CF:97:48:1E: Unknown.
2022-09-03 06:08:54,598 bleak.backends.winrt.scanner DEBUG: Received C7:9B:E9:C7:9B:EA: WM2.
2022-09-03 06:08:54,611 bleak.backends.winrt.scanner DEBUG: Received C7:9B:E9:C7:9B:EA: Unknown.
2022-09-03 06:08:54,633 bleak.backends.winrt.scanner DEBUG: Received 57:CD:71:F1:32:9A: Unknown.
2022-09-03 06:08:54,734 bleak.backends.winrt.scanner DEBUG: Received 3D:E6:F1:FB:EE:40: Unknown.
2022-09-03 06:08:54,822 bleak.backends.winrt.scanner DEBUG: Received 4F:7B:43:3B:99:24: Unknown.
2022-09-03 06:08:54,898 bleak.backends.winrt.scanner DEBUG: Received C7:9B:E9:C7:9B:EA: WM2.
2022-09-03 06:08:54,918 bleak.backends.winrt.scanner DEBUG: Received C7:9B:E9:C7:9B:EA: Unknown.
2022-09-03 06:08:55,256 bleak.backends.winrt.scanner DEBUG: Received E3:54:B4:CE:3A:4D: isp1507_sensor.
2022-09-03 06:08:55,277 bleak.backends.winrt.scanner DEBUG: Received E3:54:B4:CE:3A:4D: Unknown.
2022-09-03 06:08:55,477 bleak.backends.winrt.scanner DEBUG: Received 6B:92:42:AC:10:37: Unknown.
2022-09-03 06:08:55,506 bleak.backends.winrt.scanner DEBUG: Received 6B:D8:E1:9F:A8:12: Unknown.
2022-09-03 06:08:55,516 bleak.backends.winrt.scanner DEBUG: Received 6B:D8:E1:9F:A8:12: Unknown.
2022-09-03 06:08:55,645 bleak.backends.winrt.scanner DEBUG: Received 32:1F:4A:1D:D7:70: Unknown.
2022-09-03 06:08:55,807 bleak.backends.winrt.scanner DEBUG: Received C7:9B:E9:C7:9B:EA: WM2.
2022-09-03 06:08:55,814 bleak.backends.winrt.scanner DEBUG: Received C7:9B:E9:C7:9B:EA: Unknown.
2022-09-03 06:08:55,866 bleak.backends.winrt.scanner DEBUG: Received 63:23:23:54:F6:CB: Unknown.
2022-09-03 06:08:55,882 bleak.backends.winrt.scanner DEBUG: Received 63:23:23:54:F6:CB: Unknown.
2022-09-03 06:08:56,101 bleak.backends.winrt.scanner DEBUG: Received 66:02:66:1D:43:61: Unknown.
2022-09-03 06:08:56,118 bleak.backends.winrt.scanner DEBUG: Received 66:02:66:1D:43:61: Unknown.
2022-09-03 06:08:56,141 bleak.backends.winrt.scanner DEBUG: Received 3D:E6:F1:FB:EE:40: Unknown.
2022-09-03 06:08:56,239 bleak.backends.winrt.scanner DEBUG: Received 5D:BB:28:BA:54:C4: Unknown.
2022-09-03 06:08:56,264 bleak.backends.winrt.scanner DEBUG: Received C7:9B:E9:C7:9B:EA: WM2.
2022-09-03 06:08:56,278 bleak.backends.winrt.scanner DEBUG: Received C7:9B:E9:C7:9B:EA: Unknown.
2022-09-03 06:08:56,317 bleak.backends.winrt.scanner DEBUG: Received 78:86:3A:E5:88:7B: Unknown.
2022-09-03 06:08:56,339 bleak.backends.winrt.scanner DEBUG: Received E3:54:B4:CE:3A:4D: isp1507_sensor.
2022-09-03 06:08:56,421 bleak.backends.winrt.scanner DEBUG: Received C7:9B:E9:C7:9B:EA: WM2.
2022-09-03 06:08:56,439 bleak.backends.winrt.scanner DEBUG: Received C7:9B:E9:C7:9B:EA: Unknown.
2022-09-03 06:08:56,459 bleak.backends.winrt.scanner DEBUG: Received 05:8F:CF:97:48:1E: Unknown.
2022-09-03 06:08:56,793 bleak.backends.winrt.scanner DEBUG: Received 5D:BB:28:BA:54:C4: Unknown.
2022-09-03 06:08:56,877 bleak.backends.winrt.scanner DEBUG: Received FA:CE:56:BD:80:64: Unknown.
2022-09-03 06:08:57,139 bleak.backends.winrt.scanner DEBUG: Received 78:86:3A:E5:88:7B: Unknown.
2022-09-03 06:08:57,153 bleak.backends.winrt.scanner DEBUG: 23 devices found. Watcher status: 3.
2022-09-03 06:08:57,157 bleak.backends.winrt.client DEBUG: Connecting to BLE device @ E3:54:B4:CE:3A:4D
2022-09-03 06:08:59,650 bleak.backends.winrt.client DEBUG: session_status_changed_event_handler: id: <_bleak_winrt_Windows_Devices_Bluetooth.BluetoothDeviceId object at 0x000001F6DC11DE30>, error: 0, status: 1
2022-09-03 06:08:59,650 bleak.backends.winrt.client DEBUG: Get Services...
2022-09-03 06:08:59,927 bleak.backends.winrt.client DEBUG: session_status_changed_event_handler: id: <_bleak_winrt_Windows_Devices_Bluetooth.BluetoothDeviceId object at 0x000001F6DC120A70>, error: 0, status: 0
Traceback (most recent call last):
  File "C:\Users\saido\OneDrive\work\ncs_vscode\nRF52_sensors\test\search_and_connect.py", line 54, in <module>
    asyncio.run(main(DEVICE_NAME))
  File "C:\Users\saido\scoop\apps\python39\current\lib\asyncio\runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "C:\Users\saido\scoop\apps\python39\current\lib\asyncio\base_events.py", line 647, in run_until_complete
    return future.result()
  File "C:\Users\saido\OneDrive\work\ncs_vscode\nRF52_sensors\test\search_and_connect.py", line 31, in main
    async with BleakClient(device, timeout=20.0) as client:
  File "c:\users\saido\onedrive\sources\bleak\bleak\backends\client.py", line 61, in __aenter__
    await self.connect()
  File "c:\users\saido\onedrive\sources\bleak\bleak\backends\winrt\client.py", line 331, in connect
    await self.get_services()
  File "c:\users\saido\onedrive\sources\bleak\bleak\backends\winrt\client.py", line 547, in get_services
    characteristic, self._session.max_pdu_size - 3
AttributeError: 'NoneType' object has no attribute 'max_pdu_size'

@dlech
Copy link
Collaborator

dlech commented Sep 2, 2022

Thanks for the logs.

2022-09-03 06:08:59,927 bleak.backends.winrt.client DEBUG: session_status_changed_event_handler: id: <_bleak_winrt_Windows_Devices_Bluetooth.BluetoothDeviceId object at 0x000001F6DC120A70>, error: 0, status: 0

This is what I was expecting to see. It looks as if the device is disconnecting even though we tell Windows to stay connected. Can you also get a Wireshark log of the Bluetooth packets when the problem happens (see troubleshooting page in bleak docs for howto)? I would like to see if Windows is disconnecting or if the device itself is disconnecting or if it is not disconnecting at all.

@nv-h
Copy link
Contributor Author

nv-h commented Sep 2, 2022

I see. So, does my workaround match?

I've attached the packet capture results when I try and reproduce it 3 times.
try_to_3_times_and_reproducing.pcapng.gz

@dlech
Copy link
Collaborator

dlech commented Sep 2, 2022

I've attached the packet capture results when I try and reproduce it 3 times.

Does this mean the first two attempts did not have a problem and the 3rd attempt did have the problem?

@nv-h
Copy link
Contributor Author

nv-h commented Sep 2, 2022

Does this mean the first two attempts did not have a problem and the 3rd attempt did have the problem?

Yes!

@dlech
Copy link
Collaborator

dlech commented Sep 2, 2022

image

This shows that the device disconnected itself about 1/4 of a second after connecting (before the MTU exchange was complete).

So, I don't think the workaround is the correct solution here. Instead, the connect method should fail because the device disconnected before the services could be retrieved. Then the connection can be retried later.

@nv-h
Copy link
Contributor Author

nv-h commented Sep 2, 2022

Thank you for the explanation. So, I think that try to write the retry process in the application code by catch AttributeError.
So I am closing this PR.

@nv-h nv-h closed this Sep 2, 2022
@dlech
Copy link
Collaborator

dlech commented Sep 2, 2022

I would accept a PR that adds

        if not self.is_connected:
            raise BleakError("Not connected")

to get_services() in the WinRT backend just like we already have in the BlueZ backend if it helps catch this problem.

That would be more informative than an AttributeError.

@nv-h nv-h reopened this Sep 2, 2022
@nv-h
Copy link
Contributor Author

nv-h commented Sep 2, 2022

Thank you. I added it like this commit.

Copy link
Collaborator

@dlech dlech left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Can you also add a changelog entry?

bleak/backends/winrt/client.py Outdated Show resolved Hide resolved
@nv-h
Copy link
Contributor Author

nv-h commented Sep 3, 2022

Thank you for review. I changed place and added changelog.

@nv-h nv-h requested a review from dlech September 3, 2022 00:22
@nv-h
Copy link
Contributor Author

nv-h commented Sep 3, 2022

Added a connection check referring to BlueZ's implementation. I didn't see the implementation, so I'm sorry for bothering you twice.

@nv-h nv-h requested a review from dlech September 5, 2022 09:32
CHANGELOG.rst Outdated Show resolved Hide resolved
@nv-h nv-h requested a review from dlech September 5, 2022 14:31
@dlech dlech merged commit 9c2b34d into hbldh:develop Sep 5, 2022
@dlech
Copy link
Collaborator

dlech commented Sep 5, 2022

Merged, thanks!

@nv-h nv-h deleted the fix_winrt_get_service branch September 5, 2022 20:43
@dlech dlech mentioned this pull request Sep 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Backend: WinRT Issues or PRs relating to the WinRT backend
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants