Python Bluetooth Passkey / Password Linux

I am working on a Python script to control Mindstorms NXT using Raspberry Pi. My problem is that the NXT has a Bluetooth passkey. You can change the passkey but not delete it.

I want to know how you can connect a PyBluez socket to a device with a passkey.

This is the current program:

import bluetooth
import socket

target_name = "Jerry"
target_address = None

print "performing inquiry..."
nearby_devices = bluetooth.discover_devices()
print "found %d devices" % len(nearby_devices)

for bdaddr in nearby_devices:
    if target_name == bluetooth.lookup_name( bdaddr ):
        target_address = bdaddr
        break

if target_address is not None:
    print "found target bluetooth device with address ", target_address
else:
    print "could not find target bluetooth device nearby"

bluesock= socket.socket(socket.AF_BLUETOOTH, socket.SOCK_STREAM, socket.BTPROTO_RFCOMM)
bluesock.connect((target_address, 1))
+4
source share
2 answers

I am not sure if there is an answer in Python. The py-nxt actions I saw seemed to point to the OS.

Does this background process (on your computer) help you to start using the passkey?

bluetooth-agent 1234 &

I found it useful to first establish a connection with NXT using:

hcitool cc 00:16:53:0A:17:16

, MAC- :

hcitool scan

rfcomm Linux, ref .

+3

Windows Bluetooth , Windows, NXT. , , , , , , nxt-python.

0

All Articles