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

BLE Reconnection Fails After GoPro Battery Removal or Extended Idle Time (Requires Manual Re-pairing) #645

Open
areiner222 opened this issue Dec 17, 2024 · 0 comments
Labels
bug Something isn't working triage Needs to be reviewed and assigned

Comments

@areiner222
Copy link

Component
What is the bug in?

  • Demos (python sdk, etc) - Using WirelessGoPro / python sdk

Describe the bug
I can successfully pair my gopro via ble and then connect with the WirelessGoPro (connecting and disconnecting successfully). However, if the battery is removed / changes or the camera sits idle for long enough after powering off then I cannot reconnect via ble without manually repairing.

Repro

gp0 = WirelessGoPro(
    target=target0,
    enable_wifi=False,
    maintain_state=False,
)
await gp0.open()

Error:
Connection failed during establishment..
[org.bluez.Error.Failed] Operation already in progress
Failed to connect: ConnectFailed('BLE connection failed to establish after 1 retries with timeout 1'). Retrying #1
Failed to connect: ConnectFailed('BLE connection failed to establish after 1 retries with timeout 1'). Retrying #2
Connection failed during establishment..
[org.bluez.Error.Failed] Operation already in progress
Error while opening: BLE connection failed to establish after 5 retries with timeout 15
Failed to connect: ConnectFailed('BLE connection failed to establish after 1 retries with timeout 1'). Retrying #3
Failed to connect: ConnectFailed('BLE connection failed to establish after 1 retries with timeout 1'). Retrying #4
---------------------------------------------------------------------------
BleakDBusError                            Traceback (most recent call last)
File [~/miniforge3/envs/zed_dev2/lib/python3.10/site-packages/bleak/__init__.py:615](http://localhost:9091/home/areiner/miniforge3/envs//lib/python3.10/site-packages/bleak/__init__.py#line=614), in BleakClient.connect(self, **kwargs)
    606 """Connect to the specified GATT server.
    607 
    608 Args:
   (...)
    613 
    614 """
--> 615 return await self._backend.connect(**kwargs)

File [~/miniforge3/envs/zed_dev2/lib/python3.10/site-packages/bleak/backends/bluezdbus/client.py:254](http://localhost:9091/home/areiner/miniforge3/envs/zed_dev2/lib/python3.10/site-packages/bleak/backends/bluezdbus/client.py#line=253), in BleakClientBlueZDBus.connect(self, dangerous_use_bleak_cache, **kwargs)
    249             raise BleakDeviceNotFoundError(
    250                 self.address,
    251                 f"Device with address {self.address} was not found. It may have been removed from BlueZ when scanning stopped.",
    252             )
--> 254     assert_reply(reply)
    256 self._is_connected = True

File [~/miniforge3/envs/zed_dev2/lib/python3.10/site-packages/bleak/backends/bluezdbus/utils.py:20](http://localhost:9091/home/areiner/miniforge3/envs/zed_dev2/lib/python3.10/site-packages/bleak/backends/bluezdbus/utils.py#line=19), in assert_reply(reply)
     19 if reply.message_type == MessageType.ERROR:
---> 20     raise BleakDBusError(reply.error_name, reply.body)
     21 assert reply.message_type == MessageType.METHOD_RETURN

BleakDBusError: [org.bluez.Error.Failed] Operation already in progress

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

ConnectFailed                             Traceback (most recent call last)
File [~/miniforge3/envs/zed_dev2/lib/python3.10/site-packages/open_gopro/ble/client.py:110](http://localhost:9091/home/areiner/miniforge3/envs/zed_dev2/lib/python3.10/site-packages/open_gopro/ble/client.py#line=109), in BleClient.open(self, timeout, retries)
    109 try:
--> 110     self._handle = await self._controller.connect(self._disconnected_cb, self._device, timeout=timeout)
    111     break

File [~/miniforge3/envs/zed_dev2/lib/python3.10/site-packages/open_gopro/ble/adapters/bleak_wrapper.py:249](http://localhost:9091/home/areiner/miniforge3/envs/zed_dev2/lib/python3.10/site-packages/open_gopro/ble/adapters/bleak_wrapper.py#line=248), in BleakWrapperController.connect(self, disconnect_cb, device, timeout)
    248     logger.warning(exception)
--> 249     raise ConnectFailed("BLE", 1, 1) from exception
    250 return client

ConnectFailed: BLE connection failed to establish after 1 retries with timeout 1

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

ConnectFailed                             Traceback (most recent call last)
File [~/miniforge3/envs/zed_dev2/lib/python3.10/site-packages/open_gopro/gopro_wireless.py:294](http://localhost:9091/home/areiner/miniforge3/envs/zed_dev2/lib/python3.10/site-packages/open_gopro/gopro_wireless.py#line=293), in WirelessGoPro.open(self, timeout, retries)
    293 try:
--> 294     await self._open_ble(timeout, retries)
    296     # Set current dst-aware time. Don't assert on success since some old cameras don't support this command.

File [~/miniforge3/envs/zed_dev2/lib/python3.10/site-packages/open_gopro/gopro_wireless.py:583](http://localhost:9091/home/areiner/miniforge3/envs/zed_dev2/lib/python3.10/site-packages/open_gopro/gopro_wireless.py#line=582), in WirelessGoPro._open_ble(self, timeout, retries)
    582 # Establish connection, pair, etc.
--> 583 await self._ble.open(timeout, retries)
    584 # Start state maintenance

File [~/miniforge3/envs/zed_dev2/lib/python3.10/site-packages/open_gopro/ble/client.py:115](http://localhost:9091/home/areiner/miniforge3/envs/zed_dev2/lib/python3.10/site-packages/open_gopro/ble/client.py#line=114), in BleClient.open(self, timeout, retries)
    114         if retry == retries - 1:
--> 115             raise ConnectFailed("BLE", timeout, retries) from e
    117 assert self._handle is not None

ConnectFailed: BLE connection failed to establish after 5 retries with timeout 15

During handling of the above exception, another exception occurred:

GoProNotOpened                            Traceback (most recent call last)
Cell In[13], line 1
----> 1 r = await gp0.open()

File [~/miniforge3/envs/zed_dev2/lib/python3.10/site-packages/open_gopro/gopro_wireless.py:318](http://localhost:9091/home/areiner/miniforge3/envs/zed_dev2/lib/python3.10/site-packages/open_gopro/gopro_wireless.py#line=317), in WirelessGoPro.open(self, timeout, retries)
    316 except Exception as e:
    317     logger.error(f"Error while opening: {e}")
--> 318     await self.close()
    319     raise e

File [~/miniforge3/envs/zed_dev2/lib/python3.10/site-packages/open_gopro/gopro_wireless.py:329](http://localhost:9091/home/areiner/miniforge3/envs/zed_dev2/lib/python3.10/site-packages/open_gopro/gopro_wireless.py#line=328), in WirelessGoPro.close(self)
    321 async def close(self) -> None:
    322     """Safely stop the GoPro instance.
    323 
    324     This will disconnect BLE and WiFI if applicable.
   (...)
    327     prevent reconnection issues because the OS has never disconnected from the previous session.
    328     """
--> 329     await self._close_wifi()
    330     await self._close_ble()
    331     self._open = False

File [~/miniforge3/envs/zed_dev2/lib/python3.10/site-packages/open_gopro/gopro_wireless.py:805](http://localhost:9091/home/areiner/miniforge3/envs/zed_dev2/lib/python3.10/site-packages/open_gopro/gopro_wireless.py#line=804), in WirelessGoPro._close_wifi(self)
    803 async def _close_wifi(self) -> None:
    804     """Terminate the Wifi connection."""
--> 805     assert (await self.ble_command.enable_wifi_ap(enable=False)).ok
    806     if hasattr(self, "_wifi"):  # Corner case where instantiation fails before superclass is initialized
    807         self._wifi.close()

File [~/miniforge3/envs/zed_dev2/lib/python3.10/site-packages/open_gopro/api/builders.py:275](http://localhost:9091/home/areiner/miniforge3/envs/zed_dev2/lib/python3.10/site-packages/open_gopro/api/builders.py#line=274), in ble_write_command.<locals>.wrapper(wrapped, instance, _, kwargs)
    273 @wrapt.decorator
    274 async def wrapper(wrapped: Callable, instance: BleMessages, _: Any, kwargs: Any) -> GoProResp:
--> 275     return await instance._communicator._send_ble_message(message, rules, **(await wrapped(**kwargs) or kwargs))

File [~/miniforge3/envs/zed_dev2/lib/python3.10/site-packages/open_gopro/gopro_base.py:89](http://localhost:9091/home/areiner/miniforge3/envs/zed_dev2/lib/python3.10/site-packages/open_gopro/gopro_base.py#line=88), in ensure_opened.<locals>.wrapper(wrapped, instance, args, kwargs)
     86 @wrapt.decorator
     87 def wrapper(wrapped: Callable, instance: GoProBase, args: Any, kwargs: Any) -> Callable:
     88     if GoProMessageInterface.BLE in interface and not instance.is_ble_connected:
---> 89         raise GpException.GoProNotOpened("BLE not connected")
     90     if GoProMessageInterface.HTTP in interface and not instance.is_http_connected:
     91         raise GpException.GoProNotOpened("HTTP interface not connected")

GoProNotOpened: GoPro is not correctly open: BLE not connected

Screenshots
If applicable, add screenshots to help explain your problem.

Hardware

  • Camera: Hero13 Black etc.
  • PC, Ubuntu 22.04

Additional Info

Here are some additional logs via btmon:

> HCI Event: Encryption Change (0x08) plen 4                                                                                                                                                                                   #453 [hci1] 39.779169
        Status: PIN or Key Missing (0x06)
        Handle: 16
        Encryption: Disabled (0x00)
< HCI Command: Disconnect (0x01|0x0006) plen 3                                                                                                                                                                                 #454 [hci1] 39.779438
        Handle: 16
        Reason: Authentication Failure (0x05)
> HCI Event: Command Status (0x0f) plen 4                                                                                                                                                                                      #455 [hci1] 39.781072
      Disconnect (0x01|0x0006) ncmd 2
        Status: Success (0x00)
> HCI Event: Disconnect Complete (0x05) plen 4                                                                                                                                                                                 #456 [hci1] 39.823092
        Status: Success (0x00)
        Handle: 16
        Reason: Connection Terminated By Local Host (0x16)
@ MGMT Event: Device Disconnected (0x000c) plen 8                                                                                                                                                                          {0x0001} [hci1] 39.823134
        LE Address: D6:DE:15:46:94:6E (Static)
        Reason: Connection terminated due to authentication failure (0x04)
@ MGMT Event: Connect Failed (0x000d) plen 8                                                                                                                                                                               {0x0001} [hci1] 39.843463
        LE Address: D6:DE:15:46:94:6E (Static)
        Status: Disconnected (0x0e)
@areiner222 areiner222 added the bug Something isn't working label Dec 17, 2024
@github-actions github-actions bot added the triage Needs to be reviewed and assigned label Dec 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working triage Needs to be reviewed and assigned
Projects
None yet
Development

No branches or pull requests

1 participant