Bluetoothctl set passkey

后端 未结 5 684
北荒
北荒 2021-02-05 12:39

I have a Raspberry Pi 2 running Raspbian kernel 4.1.15 and Bluez version 5.23.

I want to be able to connect a device (like an Android phone) to the rapsberry which shoul

相关标签:
5条回答
  • 2021-02-05 13:16

    Here is what works thanks to kaylum :

    $bluetoothctl
    [bluetooth]# power on
    Changing power on succeeded
    [bluetooth]# discoverable on
    Changing discoverable on succeeded
    [bluetooth]# pairable on
    Changing pairable on succeeded
    [bluetooth]# agent NoInputNoOutput
    Agent registered
    [bluetooth]# default-agent 
    Default agent request successful
    

    Then I pair the raspberry with my phone from the phone.

    [NEW] Device XX:XX:XX:XX:XX:XX nameofthedevice
    [CHG] Device XX:XX:XX:XX:XX:XX UUIDS:
          --UUIDS--
    [CHG] Device XX:XX:XX:XX:XX:XX Paired: yes
    
    0 讨论(0)
  • 2021-02-05 13:18

    https://github.com/nokia/rcm-bluez/blob/master/client/bluez-5.43/test/simple-agent

    https://raw.githubusercontent.com/pauloborges/bluez/master/test/bluezutils.py

    @Ion Flare idea is perfect for setup auto-pairing Bluetooth for raspberry pi. just little tweak in my answer is I got an error for import bluezutils so in order to bypass that simply I would say download above file that is simple-agent and bluezutils.py. Put in is same location, for me it is /home/pi. And just run command @Ion Flare mentioned python simple-agent -c NoInputNoOutput

    In my use case I changed a simple-agent file to accept every connection and services to make things simple for me.

    0 讨论(0)
  • I just had the same issue. If you press tab twice after agent you should see a list of available agents; KeyboardOnly works fine without notifications:

    [bluetooth]# agent on          # accidentally used wrong agent
    Agent registered
    [bluetooth]# agent 
    DisplayOnly      DisplayYesNo     KeyboardDisplay  KeyboardOnly     NoInputNoOutput  off              on               
    [bluetooth]# agent KeyboardOnly 
    Agent is already registered    # can't use two agents at one
    [bluetooth]# agent off         # unregister agent
    Agent unregistered
    [bluetooth]# agent KeyboardOnly   # register proper agent
    Agent registered
    [bluetooth]# pair XX:XX:XX:04:F5:7C 
    Attempting to pair with XX:XX:XX:04:F5:7C 
    [CHG] Device XX:XX:XX:04:F5:7C Connected: yes
    Request passkey
    [agent] Enter passkey (number in 0-999999): 722504
    [MoarBacon]# pair XX:XX:XX:04:F5:7C 
    Attempting to pair with XX:XX:XX:04:F5:7C 
    [CHG] Device XX:XX:XX:04:F5:7C Paired: yes
    Pairing successful
    
    0 讨论(0)
  • 2021-02-05 13:32

    First you have to configurate sspmode 0, for pin request: hciconfig hci0 sspmode 0

    And using bt-agent aplicattion (you can run as deamon too):

    bt-agent -c NoInputNoOutput -p /root/bluethooth.cfg
    

    Edit the file configuration, you can put tha mac address and the pin: For example:

    XX:XX:XX:XX:XX:XX 1234
    

    Or if you want a pin to all the device the same pin code, for example 1234, edit the file like this: * 1234

    This work for me!

    0 讨论(0)
  • 2021-02-05 13:37

    I already had bluez-5.43 installed. This is how to automate the pairing process on a raspberry pi.

    (1) First test a line like this out to make sure bluetooth agent works:

     bluez-5.43/test/simple-agent -c NoInputNoOutput
    

    (2) To automate pairing, put this code into a shell file (I named mine pairbot.sh):

    if [ "$(id -un)" != "pi" ]; then
            exec sudo -u pi $0 "$@"
        fi
    
        export XAUTHORITY=/home/pi/.Xauthority
        export DISPLAY=:0
    
         lxterminal --command="/bin/bash -c '/home/pi/bluez-5.43/test/simple-agent -c NoInputNoOutput &; read'"
    

    (3) Go to crontab:

    sudo cronetab -e
    

    (4) At the bottom add:

    @reboot sleep 20 &&  /home/pi/pairbot.sh > /home/pi/blelog.txt 2>&1
    

    (5) Reboot and test if it works.

    My recommendation for others facing the same issue would be to look into your bluez folder (or if you don't have one install the latest version of bluez) and search for the folder that says "test" for "simple agent" to locate the file path. From here, you should be able to construct the command line shown above (1). Hopefully it will work for you too.

    0 讨论(0)
提交回复
热议问题