Errors when connecting to nxt brick

497 views Asked by At

I'm using nxt-python to connect to my nxt brick from my raspberry pi.

After some struggle with the python 3.2 versions of the bluetooth and usb libraries it requires i've managed to get it to connect via bluetooth and ask for a passkey. After some more struggle i found that i could type bluetooth-agent PASSKEY & (and replace PASSKEY with the passkey) in the terminal before running the python script that connects with the nxt brick and as far as i know that works fine. But now it throws an error. Connecting with USB throws a different error.

Here's the error i get with both methods (USB & BT) and debug enabled:

USB: True BT: True Fantom: False FUSB: False FBT: False
Traceback (most recent call last):
  File "/usr/local/lib/python3.2/dist-packages/nxt/locator.py", line 138, in find_one_brick
    if name and info[0].strip('\0') != name:
TypeError: Type str doesn't support the buffer API
Failed to connect to possible brick
Traceback (most recent call last):
  File "/usr/local/lib/python3.2/dist-packages/nxt/locator.py", line 131, in find_one_brick
    info = b.get_device_info()
  File "/usr/local/lib/python3.2/dist-packages/nxt/brick.py", line 27, in poll
    self.sock.send(ogram.bytes())
  File "/usr/local/lib/python3.2/dist-packages/nxt/bluesock.py", line 57, in send
    l0 = len(data.encode('utf-8')) & 0xFF
AttributeError: 'bytes' object has no attribute 'encode'
Failed to connect to possible brick
No brick was found.
    Is the brick turned on?
    For more diagnosing use the debug=True argument or
    try the 'nxt_test' script located in /bin or ~/.local/bin
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.2/dist-packages/nxt/locator.py", line 154, in find_one_brick
    raise BrickNotFoundError
nxt.locator.BrickNotFoundError

Because i know python i could probably fix the errors by just editing the source code, but i'm affraid i'll break something. I've tried editing it (keeping backups of every file i edit) and then it gets past a couple of lines before throwing another different error.

EDIT

When i try to import using python 2 it gives me this error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/nxt/__init__.py", line 15, in <module>
    from nxt.locator import find_one_brick, Method
  File "/usr/local/lib/python2.7/dist-packages/nxt/locator.py", line 49
    if not silent: print("USB module unavailable, not searching there", file=sys.stderr)
                                                                            ^
SyntaxError: invalid syntax
1

There are 1 answers

0
DutChen18 On

I've downloaded the v2.2.2 stable instead of cloning the master commit and it runs fine under python2. Too bad it isn't python3 though.