Comments (13)
Sorry, I don't have that set to experiment with it. But let me know if you'll try. I heard the protocol is more or less compatible.
from pylgbst.
FYI There's also https://github.com/nathankellenicki/node-poweredup working on this, using JS.
from pylgbst.
Hi, I tried to build a minimal class for the communication with the Powered Up Hub, but there are some issues:
import time
from struct import pack
from pylgbst.comms.cpygatt import GattoolConnection
from pylgbst import get_connection_auto
from pylgbst.constants import *
from pylgbst.utilities import str2hex
ENABLE_NOTIFICATIONS_HANDLE = 0x000f
ENABLE_NOTIFICATIONS_VALUE = b'\x01\x00'
class poweredup:
def __init__(self, connection=None):
if not connection:
connection = get_connection_auto()
self.connection = connection
self._wait_for_devices()
def _wait_for_devices(self):
self.connection.enable_notifications()
def send(self, msg_type, payload):
cmd = pack("<B", PACKET_VER) + pack("<B", msg_type) + payload
self.connection.write(MOVE_HUB_HARDWARE_HANDLE, pack("<B", len(cmd) + 1) + cmd)
def _notify(self, handle, data):
print ("notification received")
def shutdown(self):
self.send(MSG_DEVICE_SHUTDOWN, b'')
def write_to_hub(self, msg_type, port, params):
cmd = pack("<B", port) + params
self.send(msg_type, cmd)
conn = GattoolConnection("hci0")
print ("connect")
conn.connect("90:84:2B:03:xx:xx")
print ("connected")
hub = poweredup(conn)
i = 0x60
# Speed Time Swing Mode
cmd = pack("<B", 0x11) + pack("<B", 0x60) + pack("<B", 0x00) + pack("<B", i) + pack("<B", 0x20) + pack("<B", 0x00)
hub.write_to_hub(MSG_SET_PORT_VAL, 0x00, cmd)
time.sleep(0.1)
# does not work at all:
while (i > 0):
cmd = pack("<B", 0x11) + pack("<B", 0x60) + pack("<B", 0x00) + pack("<B", i) + pack("<B", 0x20) + pack("<B", 0x00)
hub.write_to_hub(MSG_SET_PORT_VAL, 0x00, cmd)
time.sleep(0.1)
i-=0x10
hub.shutdown()
The Issues are, that the connection is very unstable. Most of the time i get:
connect
ERROR:pygatt.backends.gatttool.gatttool:Timed out connecting to 90:84:2B:03:xx:xx after 5.0 seconds.
Traceback (most recent call last):
File "test.py", line 40, in <module>
conn.connect("90:84:2B:xx:xx")
File "/home/xx/.local/lib/python2.7/site-packages/pylgbst/comms/cpygatt.py", line 39, in connect
self._conn_hnd = adapter.connect(address)
File "/home/xx/.local/lib/python2.7/site-packages/pygatt/backends/gatttool/gatttool.py", line 388, in connect
raise NotConnectedError(message)
pygatt.exceptions.NotConnectedError: Timed out connecting to 90:84:2B:03:xx:xx after 5.0 seconds.
And if it works, it only works for the first commands. The connection closes immediately. But the motor moves for a fraction of a second - so fundamentally it works.
Device Detection and Notifications seems not to work at all.
from pylgbst.
Connection instability is a real thing, but from what I heard, it's specific to devices you use. For example, my setup only has connection stability issues when battery is drained.
from pylgbst.
Interesting. The thing is, that the following command works quite well, but disconnects also after some seconds:
gatttool -b 90:84:2B:03:xx:xx --char-write-req --handle 0x0e --value 0800810011510020
and connecting and playing with gattool works completely fine and permanently:
gatttool -b 90:84:2B:03:xx:xx -I
[90:84:2B:03:xx:xx][LE]> connect
Attempting to connect to 90:84:2B:03:xx:xx
[90:84:2B:03:xx:xx][LE]> primary
attr handle: 0x0001, end grp handle: 0x0004 uuid: 00001801-0000-1000-8000-00805f9b34fb
attr handle: 0x0005, end grp handle: 0x000b uuid: 00001800-0000-1000-8000-00805f9b34fb
attr handle: 0x000c, end grp handle: 0x000f uuid: 00001623-1212-efde-1623-785feabcd123
[90:84:2B:03:xx:xx][LE]> char-write-req 0x0e 0800810011510020
Characteristic value was written successfully
[90:84:2B:03:xx:xx][LE]> char-write-req 0x0e 0800810011510000
Characteristic value was written successfully
[90:84:2B:03:xx:xx][LE]>
from pylgbst.
So i tried to sniff the traffic between the BT remote and the Hub. It seems that those devices have a different protocol and also they are much more chatty. A message is send multiple times a second. Is it possible, that the connection has to be kept alive actively?
from pylgbst.
It's BLE, so connection is on all the time. You should join Slack channel of Lego Boost and read history there. One guy was experimenting around train a lot, he shared some findings.
from pylgbst.
here is a link to a js library for PoweredUp devices (includes Boost and the other ones as well):
https://github.com/nathankellenicki/node-poweredup
from pylgbst.
Thank you for your recommendation. I've already tested the library, but I would prefer a Python Library.
from pylgbst.
I'm all for adding PoweredUp support into pylgbst
library, I just don't have device to validate it.
I'm ready to work with whoever able to contribute PR to support it. I have expectation (coming from JS library owner sharings) that protocol is quite similar and there can be single library implementing all devices support.
from pylgbst.
I would also looking forward to use pylgbst together with PoweredUp/Train system. Node-poweredup working well, but I want to include this into a existing python project.
Do you have any time plans for it? If is only the missing HW issue, I could support you by the development.
from pylgbst.
I don't have plans to invest much time and I don't have hardware.
But I can accept some code contribution, assuming it's done with the same level of quality and architecture. For that, you'd need to first explain what and how you plan to change in the code and if everything fits the idea of pylgbst - implement it and bring for review.
from pylgbst.
Closing as stale
from pylgbst.
Related Issues (20)
- Lego Boost reconnection issue HOT 1
- LEDRGB: Current color can't be obtained/notified from the hub HOT 4
- Cannot connect to 88015 hub HOT 1
- Error on MacOS HOT 5
- 'MoveHub' object has no attribute 'connection' HOT 2
- Any plans for adding other hubs, maybe Mindstorms 515151? HOT 5
- [motors]Is there a way to ? HOT 1
- Technic Hub Port AB doesnt work HOT 16
- Connecting to WeDo SmartHub: no characteristic found HOT 7
- Blue Tooth Connection HOT 6
- Cannot run a Lego tram HOT 25
- How to get Sound Files with Lego Boost app? HOT 1
- Calling hub methods from callback functions blocks further operations HOT 6
- Crashes from time to time calling bluepy function HOT 14
- How to control a DC (train) motor ? HOT 40
- Support for Powered Up Remote Handset (Lego 88010) HOT 6
- Is pylgbst thread-safe? HOT 2
- To bleak or not to bleak...? HOT 3
- AttributeError: 'NoneType' object has no attribute 'timed' HOT 3
- Proper way to detect if motor is stuck during its move? HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pylgbst.