-
Notifications
You must be signed in to change notification settings - Fork 39
Description
I have connected a Large motor to port A on a Technic Hub, to power a Lego Loop Coaster. I've been able to control it via Bricknil on my Macbook Pro, but I can't get it to work on a Raspberry Pi. Almost every time I run my program on the Raspberry Pi, I get the following error:
``
INFO:BLE Event Q.0:found device Technic Hub
DEBUG:bleak.backends.bluezdbus.client:Connecting to BLE device @ 90:84:2B:70:74:8C with hci0
DEBUG:bleak.backends.bluezdbus.discovery:Technic Hub, 90:84:2B:70:74:8C (-74 dBm), Object Path: /org/bluez/hci0/dev_90_84_2B_70_74_8C
Traceback (most recent call last):
File "/home/tyler/lego1/lib/python3.9/site-packages/bleak/backends/bluezdbus/client.py", line 69, in connect
await self._bus.callRemote(
txdbus.error.RemoteError: org.bluez.Error.Failed: Software caused connection abort
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/tyler/lego1/./bricknil_test.py", line 21, in
start(system)
File "/home/tyler/lego1/lib/python3.9/site-packages/bricknil/bricknil.py", line 214, in start
ble.run()
File "/home/tyler/lego1/lib/python3.9/site-packages/bricknil/bleak_interface.py", line 52, in run
self.loop.run_until_complete(self.asyncio_loop())
File "/usr/lib/python3.9/asyncio/base_events.py", line 642, in run_until_complete
return future.result()
File "/home/tyler/lego1/lib/python3.9/site-packages/bricknil/bleak_interface.py", line 71, in asyncio_loop
await device.connect()
File "/home/tyler/lego1/lib/python3.9/site-packages/bleak/backends/bluezdbus/client.py", line 78, in connect
raise BleakError(str(e))
bleak.exc.BleakError: org.bluez.Error.Failed: Software caused connection abort
``
It works every time on the Macbook Pro. It worked once out of maybe 50 attempts on the Raspberry Pi.
Does anyone have a combination of Raspberry Pi OS / Python / Bricknil / Bleak versions that is working well for them?
Steps to reproduce:
- Install "Raspberry Pi OS (32-bit) Bullseye 2023-05-03" on a Raspberry Pi 4 Model B, and login as a regular user via SSH. This comes with Python 3.9.2.
- pip install virtualenv
- export PATH=$PATH:~/.local/bin
- virtualenv lego1
- cd lego1
- source bin/activate
- pip install bricknil
Successfully installed attrs-23.1.0 automat-22.10.0 bluebrick-Adafruit-BluefruitLE-0.9.13 bricknil-0.9.3 bricknil-bleak-0.3.1 constantly-15.1.0 curio-1.6 future-0.18.3 hyperlink-21.0.0 idna-3.4 incremental-22.10.0 pyyaml-6.0.1 six-1.16.0 twisted-23.8.0 txdbus-1.1.2 typing-extensions-4.7.1 zope-interface-6.0
Then run the following Python program, based on the technic 4x4 example:
``
#! /usr/bin/env python3
import logging
from curio import sleep
from bricknil import attach, start
from bricknil.hub import CPlusHub
from bricknil.sensor.motor import CPlusLargeMotor
@Attach(CPlusLargeMotor, name='loop_motor', port=0)
class Coaster(CPlusHub):
async def run(self):
self.message_info("Running")
await self.loop_motor.set_speed(50)
await sleep(20)
async def system():
hub = Coaster('loop_hub', True)
if name == 'main':
logging.basicConfig(level=logging.DEBUG)
start(system)
``
If I press the button on the hub immediately before running the Python program, or soon after, I can see that it discovers the hub OK, but fails when it tries to connect.