pylgbst: Cannot run a Lego tram
I’m trying to create a working solution for the new Lego Christmas tram. We want to make it run periodically in a shop window.
My plan is to use a Raspberry Pi connecting using Bluetooth, and then write some software to run the tram every now and then. As a start: My family wants me to setup an SMS gateway, so visitors outside the window can start the tram on demand by sending a text message. 😃
But first things first: I need a Python library to control the tram - and I would like to use pylgbst. But unfortunately, I cannot make it work.
Before diving into the details, I want to add that it actually works with another Python library known as BrickNil. However, this library has its own set of challenges, and it seems to be completely unsupported - there hasn’t been an update in three years, and PR and issues are unanswered. So I would prefer helping out to make pylgbst work.
Hardware for the tram is determined by Lego: An 88009 SmartHub, an 88011 Train Motor, and an 88005 Light Set.
BrickNil uses Bleak, and I can write a program and connect to the hub, change the colour of the builtin LED, and turn on the light in the external light set.
However, when I try pylgbst on the same RPi and tram, nothing works. If I try using pylgbst with bluepy, it can find the hub, but reports that nothing is connected. If I try using Bleak, it cannot find anything at all.
In issue #124 I found a small debug program. If I modify this to use a specific BT backend, I get these results for bluepy:
lars@lego-sporvogn:~ $ sudo ./test.py
DEBUG:comms-bluepy:Trying to connect client to MoveHub with MAC: 90:84:2b:c6:9a:f8
INFO:comms-bluepy:Discovering devices...
DEBUG:comms:Checking device: None, MAC: xx:xx:xx:xx:xx:xx
DEBUG:comms:Checking device: Smart Hub, MAC: 90:84:2b:c6:9a:f8
INFO:comms:Found Smart Hub at 90:84:2b:c6:9a:f8
DEBUG:comms-bluepy:Writing to handle 15: b'0100'
lars@lego-sporvogn:~ $
and for Bleak:
lars@lego-sporvogn:~ $ ./test.py
DEBUG:asyncio:Using selector: EpollSelector
DEBUG:asyncio:Using selector: EpollSelector
INFO:comms-bleak:Discovering devices... Press green button on Hub
lars@lego-sporvogn:~ $
Nothing more before the test program times out.
The RPi runs the latest Raspbian as of writing and updated to the latest and greatest everything. This means Python version 3.9.2.
I would love to see this work - but we’re in a bit of a hurry, our traditional Christmas exhibition in the shop window opens Dec. 1st. 😃
About this issue
- Original URL
- State: open
- Created 2 years ago
- Comments: 25 (11 by maintainers)
Bleak is not installed.by default because pylgbst works with several variants of BLE backends. you need to decide which you use and install it
In your case things are more complex: bricknil has installed its own patched bleak, and pylgbst uses it and fails. You should uninstall bricknil and bricknil-bleak, then install official bleak and then try again.