iRobotEducation / irobot-edu-python-sdk

Python SDK for iRobot Edu robots (Root or Create 3)
BSD 3-Clause "New" or "Revised" License
16 stars 6 forks source link

BleakDBusError('org.bluez.Error.InProgress', 'In Progress') #5

Closed carlitoselmago closed 1 year ago

carlitoselmago commented 1 year ago

I get this error when running multple functions for the event "when_play":

It does not occur when my code is runned thru the python web playground

Task exception was never retrieved
future: <Task finished name='Task-7' coro=<play() done, defined at /home/ubuntu/roomba-lofibeats/python-sdk/explore.py:245> exception=BleakDBusError('org.bluez.Error.InProgress', 'In Progress')>
Traceback (most recent call last):
  File "/home/ubuntu/roomba-lofibeats/python-sdk/explore.py", line 254, in play
    sensors = (await robot.get_ir_proximity()).sensors
  File "/home/ubuntu/.local/lib/python3.9/site-packages/irobot_edu_sdk/create3.py", line 55, in get_ir_proximity
    await self._backend.write_packet(Packet(dev, cmd, inc))
  File "/home/ubuntu/.local/lib/python3.9/site-packages/irobot_edu_sdk/backend/bluetooth_desktop.py", line 75, in write_packet
    await self._client.write_gatt_char(self.TX_CHARACTERISTIC, packet.to_bytearray(), True)
  File "/home/ubuntu/.local/lib/python3.9/site-packages/bleak/__init__.py", line 593, in write_gatt_char
    await self._backend.write_gatt_char(char_specifier, data, response)
  File "/home/ubuntu/.local/lib/python3.9/site-packages/bleak/backends/bluezdbus/client.py", line 801, in write_gatt_char
    assert_reply(reply)
  File "/home/ubuntu/.local/lib/python3.9/site-packages/bleak/backends/bluezdbus/utils.py", line 20, in assert_reply
    raise BleakDBusError(reply.error_name, reply.body)
bleak.exc.BleakDBusError: [org.bluez.Error.InProgress] In Progress
shamlian commented 1 year ago

It would be helpful if you could please supply your test code, as well as giving us some details about your environment (I see you're in Python 3.9; what's your version of Ubuntu (and version of BlueZ if it's different than the core)?) so that we can try to reproduce. The major difference between this downloadable SDK and the Python Web Playground is the backend -- for the former, we are using Bleak, and for the latter, web-bluetooth -- so there may be some cases we've missed, and would like to solve. Thanks for your interest!

shamlian commented 1 year ago

I wrote a minimal example that can reproduce this bug with BlueZ 5.53 on x86_64, but it does not happen in Windows 10. (I don't have a Mac handy to test). I have some ideas about how to fix it, though. Below is my minimal example:

from irobot_edu_sdk.robots import event, hand_over, Color, Robot, Root

import random

backend = Bluetooth()
robot = Root(backend)

@event(robot.when_play)
async def play1(robot):
    while True:
        print('light')
        await robot.set_lights_rgb(random.randint(0,255), random.randint(0,255), random.randint(0,255))

@event(robot.when_play)
async def play2(robot):
    while True:
        print('beep')
        await robot.play_note(440, .25)

robot.play()
carlitoselmago commented 1 year ago

Thanks for your quick response.

I have a while True: running so I quick-fixed it by adding a sleep(0.1) at the end of it and some try: except:

It's running on Ubuntu 20 server on a raspberry pi 4 (arm64) BlueZ 5.53-0ubuntu3.6

shamlian commented 1 year ago

If you're comfortable, give this branch a try; if not, we'll do some more testing over the next few days before cutting a patch release.

shamlian commented 1 year ago

If you pip install --upgrade the SDK, you should get 0.1.2 which fixes this bug