kariudo / onewheel-bluetooth

A python bluetooth data reader for the Onewheel (supporting Gemini firmware, and later).
30 stars 5 forks source link

Windows Support #6

Open kariudo opened 2 years ago

kariudo commented 2 years ago

Currently with the bleak rewrite, windows should be supported.

There is however an error at the unlock response (notify likely failing to get response):

2021-12-31 14:39:33 INFO     Likely found a onewheel, using ***
2021-12-31 14:39:56 INFO     Services resolved for BleakClientWinRT (***)
2021-12-31 14:40:28 ERROR    Error: timeout reached waiting for encryption key response.
2021-12-31 14:40:28 ERROR    Connection error: Timeout reached waiting for encryption key response
2021-12-31 14:40:28 INFO     Connected to board: None
2021-12-31 14:40:28 WARNING  Unable to read valid data, retrying in 3 sec...
2021-12-31 14:40:31 WARNING  Unable to read valid data, retrying in 3 sec...
2021-12-31 14:40:34 WARNING  Unable to read valid data, retrying in 3 sec...
2021-12-31 14:40:37 WARNING  Unable to read valid data, retrying in 3 sec...
2021-12-31 14:40:41 WARNING  Unable to read valid data, retrying in 3 sec...
2021-12-31 14:40:44 ERROR    Unable able to read valid data, after 5 failed attempts. Exiting.
kariudo commented 2 years ago

Additional errors include:

2021-12-31 14:45:12 INFO     Likely found a onewheel, using ***
2021-12-31 14:45:15 ERROR    Connection error: [WinError -2147483629] The object has been closed
2021-12-31 14:45:15 WARNING  Cannot read data, not connected
kariudo commented 2 years ago

Full debug output after detecting the board with scan:

2021-12-31 14:50:41 DEBUG    Connecting to BLE device @ ***
2021-12-31 14:50:42 DEBUG    _ConnectionStatusChanged_Handler: 1
2021-12-31 14:50:42 DEBUG    Get Services...
2021-12-31 14:50:43 DEBUG    _ConnectionStatusChanged_Handler: 0
2021-12-31 14:50:43 ERROR    Connection error: Could not get GATT services: Unreachable
2021-12-31 14:50:43 DEBUG    _ConnectionStatusChanged_Handler: 1
2021-12-31 14:50:43 INFO     Connected to board: None
2021-12-31 14:50:43 DEBUG    _ConnectionStatusChanged_Handler: 0
2021-12-31 14:50:43 WARNING  Not connected, exiting loop
2021-12-31 14:50:43 DEBUG    _ConnectionStatusChanged_Handler: 1
2021-12-31 14:50:43 DEBUG    Disconnecting from ***
2021-12-31 14:50:43 DEBUG    _ConnectionStatusChanged_Handler: 0
2021-12-31 14:50:43 DEBUG    Disconnecting from BLE device...
2021-12-31 14:50:43 DEBUG    Disconnected
kariudo commented 2 years ago

I think the problem is coming from this bit in bleak

https://github.com/hbldh/bleak/blob/156e8af24a4ec13540586fc32a13f99e75b2abb9/bleak/backends/winrt/client.py#L262

            # Windows does not support explicitly connecting to a device.
            # Instead it has the concept of a GATT session that is owned
            # by the calling program.
            self._session.maintain_connection = True
            # This keeps the device connected until we set maintain_connection = False.

            # wait for the session to become active
            await asyncio.wait_for(event.wait(), timeout=timeout)
        except BaseException:
            handle_disconnect()
            raise
        finally:
            self._session_active_events.remove(event)

        # Obtain services, which also leads to connection being established.
        await self.get_services()
kariudo commented 2 years ago

Since this looks like a bleak issue and I am more interested in linux support for my usage currently, this is not a priority unless someone else has a fix or input short of me making changes to bleak to work around it.