0

Was able to successfully connect my bluetooth keyboard and mouse using:

hcitool scan
sudo hidd --connect AA:BB:CC:DD:EE:FF

But if I reboot or even turn the device on/off I have to reconnect via command line. Any way to do this automatically?

Note: I have tried to connect via bluez-simple-agent but was never successful. The HIDD connect was the only method I was able to make work. I am running Ubuntu 14.04

3 Answers 3

0

I would recommend either making an init startup script or adding it via the "Startup Applications" program which is built in. Since you are using a sudo command I believe you will need to edit the sudoers to allow that command without asking for a password. This link has some additional info.

We could make a program to do it easily so that it can be run as an application?

    //resetbt.c
    #include <stdio.h>
    #include <stdlib.h>
    int main(void)
    {
      int x;
      int attempts = 0;
      while(attempts < 20)
      {
        x = system("hcitool scan");
        usleep("500000"); //added a little wait state
        printf("%d", x);    
        if(x != -1 && x == THE_CORRECT_VALUE_OF_X_FOR_SUCCESS_OF_FIRST_COMMAND) //the printf echos a number, check for when its working and when its not. Change the value to be the one it returns when its working
        {
          system("sudo hidd --connect AA:BB:CC:DD:EE:FF");
          exit(EXIT_SUCCESS);
        }
        attempts++;
      }
    }

Compiled with gcc:

    gcc resetbt.c -o reset.bin
2
  • I looked into that option, but that doesn't help when I manually turn the device off using the on/off switch. Only on reboot. The reason that is important to me is because my bluetooth gets all jenky sometimes and does some weird things. The only solution is to turn the device off and back on again...
    – ryandlf
    Sep 18, 2015 at 3:56
  • Ive added a little bit of code for you to try out. I dont have a bluetooth mouse so I cannot test it myself :(
    – Aedazan
    Sep 18, 2015 at 4:21
0

I solved the problem by trying bluez again. Turns out the reason it hadn't worked initially was because I was running the commands in the wrong order. On Ubuntu 14.04 I run in terminal:

hcitool dev //Get HCI number
//Press Connect on Device
hcitool scan //Get MAC Address
bluez-simple-agent hci0 MAC_ADDRESS
bluez-test-input connect MAC_ADDRESS
bluez-test-device trusted MAC_ADDRESS yes

I guess I was running trusted before I connected and for whatever reason i'm my machine I had to connect first before trusting.

0

Old post but i searched the whole web for a acceptable solution. Here it is.. quick and simple

Create the device configuration file (/etc/bluetooth/hcid.conf or /etc/bluetooth/input.conf)

# nano /etc/bluetooth/hcid.conf
device XX:XX:XX:XX:XX:XX {
  name "Wireless Keyboard";
  auth enable;
  encrypt enable;
}

run and add this line to your /etc/rc.local

# hidd --server

Now hidd accepts connections from the slave device.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .