-
Notifications
You must be signed in to change notification settings - Fork 121
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
Cannot run a Lego tram #125
Comments
Hello, What you should try is to experiment around version of bleak Python library. Which version do you use at the moment? It should be something recent from this list: https://pypi.org/project/bleak/#history Also, I can see that bricknil uses a patched version of Bleak: https://github.com/virantha/bleak that is installable as I understand the urgency, let's see if there can be some progress from bleak library variants. |
Hm - did some more troubleshooting, and lo and behold, now something works. I was foolish enough to assume that the But now I wonder: If |
Sorry - my last comment was posted just after you posted yours. I'll try some troubleshooting along the lines you suggest and report back. |
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. |
I've now done it properly and created a virtual environment. Installing
Then pressing
Interesting to learn that it complains about a motor that it cannot find - but only after i press I have modified |
|
"All devices are present" in log is a very good sign, seems your |
There are couple of important messages in the log:
Those mean that The interaction can happen on lower level, via message sending/receiving, or by optimistic peripheral enablement. We can even figure out the exact device capabilities and write nice peripheral handling for those. |
Here's a snippet of initializing your own objects bindings: hub = SmartHub()
# create objects
motor = pylgbst.peripherals.EncodedMotor(hub, 0x0)
led = pylgbst.peripherals.LEDLight(hub, 0x1)
# optionally, assign it into hub class
hub.peripherals[0x0] = motor
hub.peripherals[0x1] = led
# also the shorthand ports
hub.port_A = motor
hub.port_B = led
# use it!
led.brightness = 1.0
motor.timed(1.0, 1.0) After that, your can do commands to those peripherals. The code can be arranged slightly differently. If |
Back again after surgery - and on to the project! Thank you very much for your example: But whilst it most likely will work with the current code on Github, it doesn't work with the latest release and hence it won't work with the latest package on PyPi. Your latest release is 1.2.2, that's the latest package on PyPi as well - but it doesn't include the peripheral LEDLight. Perhaps time for a new release? |
Having removed the LED and concentrating on the motor for now, I do get a bit further, but your code snippet still fails:
|
Hey, welcome back. Hope nothing serious with your surgery. I would love to validate that the source code works before doing a release. It is easily possible by running Regarding "Not connected" error - it's something very specific to bluez, not something that we control on the From reading the log above, I don't see the motor is attached. It rather reports attaching the LED with Let's continue troubleshooting it. |
No, nothing too bad about surgery - just a toe with osteoarthritis. But bad enough when you suffer from it. Anyway, the motor is there - my snippet was just too short. The lines immediately before the ones above:
Will try to install from Github instead of PyPi. |
Unfortunately, same result after installing latest master. In general, everything should be up to date: The RPi was installed from scratch only three weeks ago, and I've uninstalled all Python packages related to this project for my If everything else fails, we can try wiping out the RPi and start over again with a fresh Raspbian. This RPi will only be used for Lego - at least for now. |
But the debug log isn't completely the same after the upgrade:
|
Upgraded |
What is the exact Bleak version you have? I have no other ideas than asking on Bleak issue tracker for possible help. The difficult part is the fact that the code works on other machines. It must be something with that specific combination of OS, hardware and software. |
I'm using Bleak version 0.19.5 - the latest and greatest just about two weeks old. I'll try opening a ticket with the Bleak project as well. |
@larsskj Can you try patching the library right on RPi, by searching for file like |
Sorry for being away for a long time: I've been ill, and then we've had all the usual celebrations. But here we go and I've found the time to test some of the suggestions: I first downloaded the latest BlueZ from |
@larsskj Did you try patching |
@undera Yes, that's what I meant by writing "I then patched the Python code according to the suggestion as well..." Did you see the comment from dlech in the Bleak issue about a bug in the Lego implementation? And that the simple patch of |
So, looks like we are unable to find the solution for this particular problem. Something is broken there in BLE communications. |
@larsskj we were able to include support for the train motor. It is available in the latest |
This sounds amazing: I'll give it a try in the weekend. |
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
usesBleak
, 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 usingpylgbst
withbluepy
, it can find the hub, but reports that nothing is connected. If I try usingBleak
, 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
:and for
Bleak
: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. :-)
The text was updated successfully, but these errors were encountered: