Skip to content
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

bluetooth.btcommon.BluetoothError: [Errno 14] Bad address #200

Open
Zackariyya opened this issue Dec 20, 2024 · 3 comments
Open

bluetooth.btcommon.BluetoothError: [Errno 14] Bad address #200

Zackariyya opened this issue Dec 20, 2024 · 3 comments

Comments

@Zackariyya
Copy link

  • OS: Fedora 41
  • Python version: Python 3.13.0
  • NXT-Python version:3.3.0
  • Connection method: Bluetooth
Traceback (most recent call last):
  File "<string>", line 3, in send
_bluetooth.error: (14, 'Bad address')

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/mnt/DATA/CODING_FILES/MicroControllers/NXT/nxt-car-tkinter__V2.py", line 30, in <module>
    print("Found brick:", b.get_device_info()[0])
                          ~~~~~~~~~~~~~~~~~^^
  File "/home/$USERNAME/.local/lib/python3.13/site-packages/nxt/brick.py", line 1056, in get_device_info
    tgram = self._cmd(tgram)
  File "/home/$USERNAME/.local/lib/python3.13/site-packages/nxt/brick.py", line 326, in _cmd
    self._sock.send(tgram.bytes())
    ~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^
  File "/home/$USERNAME/.local/lib/python3.13/site-packages/nxt/backend/bluetooth.py", line 70, in send
    self._sock.send(data)
    ~~~~~~~~~~~~~~~^^^^^^
  File "<string>", line 5, in send
bluetooth.btcommon.BluetoothError: [Errno 14] Bad address

@schodet
Copy link
Owner

schodet commented Dec 20, 2024

Do you have more details?

What’s your program? What parameters did you use? Does bluetoothctl manage to see the brick?

Can you run nxt_test --log-level=debug?

@Zackariyya
Copy link
Author

This is my program

#!/usr/bin/python3
import nxt.locator
import tkinter as tk


def onKeyPress(event):
    e = event.char
    if e == 'w':
        print("Forward")
        wheel1.run(-100)
        wheel2.run(-100)

    if e == 'd':
        print("Left")
        steering.turn(25,60)
    if e == 's':
        print("Back")
        wheel1.run(100)
        wheel2.run(100)
    if e == 'a':
        print("Right")
        steering.turn(-25,60)
    if e == 'q':
        print("Stop Motor")
        wheel1.brake()
        wheel2.brake()

def onKeyRelease(event):
    print("Released "+event)
    e = event.char
    if e == 'w':
        print("STOP Forward")
        wheel1.brake()
        wheel1.brake()

    if e == 'd':
        print("UNDO Left")
        steering.turn(-25,60)
    if e == 's':
        print("STOP Back")
        wheel1.brake()
        wheel1.brake()
    if e == 'a':
        print("UNDO Right")
        steering.turn(25,60)
    if e == 'q':
        print("Release Motor")
        wheel1.coast()
        wheel2.coast()
# Find a brick.
with nxt.locator.find() as b:
    # Once found, print its name.
    print("Found brick:", b.get_device_info()[0])
    # And play a recognizable note.
    b.play_tone(440, 250)
    
    # Get the motor connected to the port A.
    steering = b.get_motor(nxt.motor.Port.A)
    wheel1 = b.get_motor(nxt.motor.Port.B)
    wheel2 = b.get_motor(nxt.motor.Port.C)
    # Full circle in one direction.
    steering.turn(25, 60)
    steering.turn(-25, 60)  
    
    root = tk.Tk()
    root.geometry('300x200')
    text = tk.Label(root, text="Focus this window and use WASD to control NXT")
    text.pack()
    root.bind('<KeyPress>', onKeyPress)
    root.bind('<KeyRelease>', onKeyRelease)
    root.mainloop()
    steering.idle()
    wheel.idle()

bluetoothctl connects to brick, then after a few seconds it disconnects :

USERNAME:~/ $ bluetoothctl                                                                                                                                                                                   [11:38:31]
[bluetooth]# Agent registered
[NXTI]# [CHG] Device 00:12:34:56:78:AB Connected: yes
[NXT]# [CHG] Device 00:12:34:56:78:AB ServicesResolved: yes
[NXT]# [CHG] Device 00:12:34:56:78:AB ServicesResolved: no
[bluetooth]# [CHG] Device 00:12:34:56:78:AB Connected: no
[bluetooth]# 

output of nxt_test --log-level=debug :

Find brick...
DEBUG:nxt.locator:configuration files=['.nxt-python.conf', '/home/USERNAME/.nxt-python.conf']
DEBUG:nxt.locator:configuration read from []
DEBUG:nxt.locator:no section default, using DEFAULT
INFO:nxt.locator:using backend from nxt.backend.usb
INFO:nxt.locator:using backend from nxt.backend.bluetooth
INFO:nxt.backend.bluetooth:connecting via Bluetooth (00:12:34:56:78:AB)
DEBUG:nxt.locator:found brick <nxt.brick.Brick object at 0x7ff067aef8c0>
DEBUG:nxt.backend.bluetooth:send: 0200019b
INFO:nxt.backend.bluetooth:closing Bluetooth (00:12:34:56:78:AB) connection
Traceback (most recent call last):
  File "<string>", line 3, in send
_bluetooth.error: (14, 'Bad address')

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/USERNAME/.local/bin/nxt_test", line 26, in <module>
    name, host, signal_strengths, user_flash = b.get_device_info()
                                               ~~~~~~~~~~~~~~~~~^^
  File "/home/USERNAME/.local/lib/python3.13/site-packages/nxt/brick.py", line 1056, in get_device_info
    tgram = self._cmd(tgram)
  File "/home/zackariyyasattaur/.local/lib/python3.13/site-packages/nxt/brick.py", line 326, in _cmd
    self._sock.send(tgram.bytes())
    ~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^
  File "/home/USERNAME/.local/lib/python3.13/site-packages/nxt/backend/bluetooth.py", line 70, in send
    self._sock.send(data)
    ~~~~~~~~~~~~~~~^^^^^^
  File "<string>", line 5, in send
bluetooth.btcommon.BluetoothError: [Errno 14] Bad address

While that is running, bluetoothctl reports that it connects, then immediatly disconnects:

[NXT]# [CHG] Device 00:12:34:56:78:AB Connected: yes
[bluetooth]# [CHG] Device 00:12:34:56:78:AB Connected: no

NOTE: Those are not the real MAC addresses, I replaced them with that random one.

@schodet
Copy link
Owner

schodet commented Dec 20, 2024

Does your address starts with 00:16:53?

Make sure there is no NXT-Python program still running in the background (reboot if not sure).

Here is what I do to make it work:

% bluetoothctl
Agent registered
[bluetooth]# devices
[bluetooth]# scan on
Discovery started
[NEW] Device 00:16:53:AA:BB:CC 00-16-53-AA-BB-CC
[CHG] Device 00:16:53:AA:BB:CC LegacyPairing: no
[CHG] Device 00:16:53:AA:BB:CC Name: NXT1
[CHG] Device 00:16:53:AA:BB:CC Alias: NXT1
[CHG] Device 00:16:53:AA:BB:CC LegacyPairing: yes
[bluetooth]# pair 00:16:53:AA:BB:CC
Attempting to pair with 00:16:53:AA:BB:CC
Request PIN code
(here, enter code 1234 on NXT screen)
[agent] Enter PIN code: 1234
[CHG] Device 00:16:53:AA:BB:CC Connected: yes
[CHG] Device 00:16:53:AA:BB:CC UUIDs: 00001101-0000-1000-8000-00805f9b34fb
[CHG] Device 00:16:53:AA:BB:CC ServicesResolved: yes
[CHG] Device 00:16:53:AA:BB:CC Paired: yes
Pairing successful
[CHG] Device 00:16:53:AA:BB:CC ServicesResolved: no
[CHG] Device 00:16:53:AA:BB:CC Connected: no
[bluetooth]# scan off
Discovery stopped
[bluetooth]# devices
Device 00:16:53:AA:BB:CC NXT1
[bluetooth]#

Now I can run a nxt-python script using the 00:16:53:AA:BB:CC address.

If I keep bluetoothctl open, during the script run, I can see:

[CHG] Device 00:16:53:AA:BB:CC Connected: yes
[CHG] Device 00:16:53:AA:BB:CC Connected: no

So this part is normal.

If it does not work, try to remove the NXT from known devices and start again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants