Bluetoothctl set passkey

后端 未结 5 746
北荒
北荒 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: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.

提交回复
热议问题