Bluetooth

From BCCD 3.0

Jump to: navigation, search

Using Bluetooth devices on the BCCD is now possible!! Here's how.

Contents

Connecting your Bluetooth device(s) at runtime

  1. Make sure you have a Bluetooth adapter plugged into your BCCD host.
  2. Log in as root (or su to root); we'll need this to properly associate to the device. The default root password is "letmein" if you haven't changed it.
  3. Scan the airwaves for your devices
    hcitool scan
  4. Locate the Bluetooth ID for your specific device (the name of the device is in the last column, just to the left of that is something that looks like a MAC address; that's the BT ID)
  5. Then run:
    hidd --connect <your BT device ID>
  6. Now your device is all set!

Connecting your Bluetooth device(s) at startup

Unless you want it to connect on boot, in which case you can use either of the following two solutions:

Solution 1

  1. Edit /etc/default/bluetooth
  2. Change the "HCID_OPTIONS" variable to contain "--master --connect <your BT device ID> --server"
  3. Change the "HCID_ENABLE" variable to 1

Solution 2

Setting Up Script to Run at Startup

  1. Log in as root (or su to root); we'll need this to properly commit our new startup script. The default root password is "letmein" if you haven't changed it.
    (As a note, the bccd-bluetooth startup script should always run with root privileges so there is no need to use super user commands within the script itself.)
  2. Create /etc/init.d/bccd-bluetooth: vi /etc/init.d/bccd-bluetooth
  3. Insert the contents of the file, as provided below:
#! /bin/sh
# /etc/init.d/bccd-bluetooth

### BEGIN INIT INFO
# Provides:          bccd-bluetooth
# Required-Start:    bluetooth
# Required-Stop:     bluetooth
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Connect Bluetooth Devices on Boot
### END INIT INFO

if ! [ $(hostname -s) = "node000" ] ; then
  if [ "$1" = "start" ] ; then
    echo "Bluetooth devices can only be connected to the HEAD node."
  fi
  exit 0
fi

# Carry out specific startup/shutdown commands when asked to by the system
case "$1" in
  start)
    echo "Connecting Bluetooth Devices:"

    # Connect to Device 1
    echo "Device 1..."
    hidd --connect <your BT device 1 ID>

    # Connect to Device 2
    echo "Device 2..."
    hidd --connect <your BT device 2 ID>

    # Add more BT Devices here by copying the above 3 lines for each additional device...

    ;;

  stop)
    echo "Disconnecting Bluetooth Devices..."
    hidd --killall
    ;;

  *)
    echo "Usage: /etc/init.d/bccd-bluetooth {start|stop}
    exit 1
    ;;
esac

#Report status of bluetooth (to make sure everything worked)
hidd --show

exit 0
  1. Modify the file so that every instance of <your BT device # ID> is the ID of the Bluetooth device you wish to have connected automatically at BCCD startup. You can add/remove the number of BT devices that are auto-connected from directly within this file by simply changing the script to run the following command for each individual device: hidd --connect <your BT device # ID> For easier debugging (if it every becomes necessary), I would recommend that you include the other associated three lines surrounding the "hidd" command in the example above as well.
  2. Run the following command so the script will have the proper permissions:
    chmod 755 /etc/init.d/bccd-bluetooth
  3. Run the following command so the script will run at startup/shutdown:
    /usr/sbin/update-rc.d bccd-bluetooth defaults
  4. As we no longer need to use the super user environment, you can leave it by typing exit.
  5. Restart the BCCD and look for text that reads something like "(Dis)Connecting Bluetooth Devices... DONE!" in the startup/(shutdown) logs: /sbin/shutdown -r now
  6. Assuming there are no errors reported by the HID interface, the devices should be ready for use when the BCCD starts. There should be no need to put the BT devices in pairing mode when you startup the BCCD, the connection should be made regardless of the device's state (so long as the batteries in the device are good).

Add/Remove Devices in the Future

  1. Assuming that everything is already setup for Solution 2 to run at startup (see this section for more info), then adding/removing devices from the startup script is as simple as editing the script: sudo vi /etc/init.d/bccd-bluetooth
  2. You can add/remove the number of BT devices that are auto-connected from directly within this file by simply changing the script to run the following command for each individual device: hidd --connect <your BT device # ID>
    For easier debugging (if it every becomes necessary), I would recommend that you include the other associated three lines surrounding the "hidd" command as well (a comment, and two echos).
  3. To commit the changes, simply save the file: Shift+zz
  4. To test out the modified script, try rebooting your BCCD and see if the new devices are auto-connected: /sbin/shutdown -r now

Uninstalling Solution 2

  1. If you wish to remove this script from the startup sequence in the future, run the following command: sudo /usr/sbin/update-rc.d -f bccd-bluetooth remove
  2. Now that /etc/init.d/bccd-bluetooth has no references in the startup sequence, you can do whatever you want with it (if you're not going to use it, just delete it): rm /etc/init.d/bccd-bluetooth

Common Error Messages

Error: "Can't get device information: No route to host"

This probably means that the bluetooth service is not started in the BCCD. If this occurs at startup only, try to rearrange the order in which the startup scripts are executed. Otherwise, try running /etc/init.d/bluetooth start to start the BT service and try connecting again. You can use /etc/init.d/bluetooth status to check the status of the bluetooth service at any time. Also, verify that the Bluetooth adapter is properly connected to the BCCD.

Error: "Can't get device information: Host is down"

This could either mean that you do not have the correct <BT device ID> for the device you are trying to connect to or that the bluetooth device is out of range or in need of new batteries. Try running hcitool scan to verify that you are using the correct ID. The bluetooth service is likely up and running as it should be, but you can always use /etc/init.d/bluetooth status to check the status of the bluetooth service just to be sure.

Error: "HID create error 13 (Permission denied)"

Make sure that you are running the hidd command with root privileges. If this is happening from within the startup script, consider adding a prompt for super user privileges at startup. While this is NOT recommended, it is a viable work around if you do ever encounter this error from within the startup script itself and not just while running the command manually at the command line. Change each instance of the "hidd" command to:
su
hidd --connect <your BT device ID>          OR          sudo hidd --connect <your BT device ID>

Error: "Can't create HID control channel: Connection refused"

This error usually means that the device you are attempting to connect to is already connected (possibly to another system, or to this system). Check the Bluetooth device you were attempting to connect when you received the error... Odds are that it is connected just fine. If it is not connected or functional, make sure the device is available for pairing and run the command again.

Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox