clonmac
Posts: 9
Joined: Thu Aug 07, 2014 12:45 pm

Connect Bluetooth Keyboard at boot

Tue Sep 06, 2016 11:19 pm

I am trying to configure the bluetooth on the RPi3 to automatically connect to my BT keyboard when it boots up, but am unable to get it to work. Currently I am using Raspbian and it boots to the login screen via GUI. Would anyone be able to help me out on how to configure it so it connects at bootup? The device is trusted via bluetoothctl and I can connect to it fine once I am logged in and I connect it manually.

User avatar
Douglas6
Posts: 4923
Joined: Sat Mar 16, 2013 5:34 am
Location: Chicago, IL

Re: Connect Bluetooth Keyboard at boot

Wed Sep 07, 2016 12:35 am

The keyboard should reestablish the connection, after tapping a key or two. Make sure your pairing is trusted.

clonmac
Posts: 9
Joined: Thu Aug 07, 2014 12:45 pm

Re: Connect Bluetooth Keyboard at boot

Wed Sep 07, 2016 1:11 am

It is trusted and I've tried tapping a key or two, but it doesn't reestablish the connection. The device is trusted as well. Here is the output from bluetoothctl info:

Code: Select all

Device 20:16:07:05:92:9E
	Name: NexDock Keyboard
	Alias: NexDock Keyboard
	Class: 0x000540
	Icon: input-keyboard
	Paired: yes
	Trusted: yes
	Blocked: no
	Connected: yes
	LegacyPairing: no
	UUID: Human Interface Device... (00001124-0000-1000-8000-00805f9b34fb)
	UUID: PnP Information           (00001200-0000-1000-8000-00805f9b34fb)
	Modalias: usb:v04E8p7021d0001
Apparently according to Nexdock's site, "the latest version of Raspbian does not support autoreconnect after reboot". I'm wondering if there is a way I can script it out at bootup or use a cronjob every minute to attempt a reconnect.

User avatar
Douglas6
Posts: 4923
Joined: Sat Mar 16, 2013 5:34 am
Location: Chicago, IL

Re: Connect Bluetooth Keyboard at boot

Wed Sep 07, 2016 1:23 am

Well, a coupla things you could try. You can write a bash script to call bluetoothctl and pipe in the connect command. Put that in cron as a @reboot script. Or, get the test-device Python script from the BlueZ source tree and set that up to connect in cron.

clonmac
Posts: 9
Joined: Thu Aug 07, 2014 12:45 pm

Re: Connect Bluetooth Keyboard at boot

Wed Sep 07, 2016 1:42 am

Thanks so much for the suggestion. I put this in crontab and that got it to connect after a reboot successfully:

Code: Select all

@reboot sleep 20 && /bin/echo -e 'connect XX:XX:XX:XX:XX:XX \n' | bluetoothctl

User avatar
Douglas6
Posts: 4923
Joined: Sat Mar 16, 2013 5:34 am
Location: Chicago, IL

Re: Connect Bluetooth Keyboard at boot

Wed Sep 07, 2016 1:47 am

Excellent. Don't know if you want to add 'quit\n' to that.

User avatar
sdse78
Posts: 25
Joined: Thu Apr 11, 2013 1:31 am
Location: San Diego, CA

Re: Connect Bluetooth Keyboard at boot

Thu Sep 08, 2016 9:51 pm

clonmac wrote:Thanks so much for the suggestion. I put this in crontab and that got it to connect after a reboot successfully:

Code: Select all

@reboot sleep 20 && /bin/echo -e 'connect XX:XX:XX:XX:XX:XX \n' | bluetoothctl
Can you share how you did this? I have a similar issue with my NexDock.

I know what a cron job is, but where is crontab found?

I tried putting a command in etc/rc.local and that failed...

User avatar
sdse78
Posts: 25
Joined: Thu Apr 11, 2013 1:31 am
Location: San Diego, CA

Re: Connect Bluetooth Keyboard at boot

Thu Sep 08, 2016 9:56 pm

Douglas6 wrote:Well, a coupla things you could try. You can write a bash script to call bluetoothctl and pipe in the connect command. Put that in cron as a @reboot script. Or, get the test-device Python script from the BlueZ source tree and set that up to connect in cron.
Maybe you can show me how to do this? :roll:

clonmac
Posts: 9
Joined: Thu Aug 07, 2014 12:45 pm

Re: Connect Bluetooth Keyboard at boot

Fri Sep 09, 2016 2:19 pm

First you need to know the address of the bluetooth device you want to connect. You can find that by typing in bluetoothctl and it will list any devices you've paired already. Once you have the address, type in the following command to edit root's crontab:

Code: Select all

sudo crontab -e
That will allow you to add new tasks to be run.

At the bottom of that file, add the following line:

Code: Select all

@reboot sleep 5 && /bin/echo -e 'connect XX:XX:XX:XX:XX:XX \n quit \n' | bluetoothctl
I actually decreased the sleep amount on the command to cut down on the wait time before the keyboard connects. That should do it. Hope this helps.

User avatar
sdse78
Posts: 25
Joined: Thu Apr 11, 2013 1:31 am
Location: San Diego, CA

Re: Connect Bluetooth Keyboard at boot

Fri Sep 09, 2016 3:12 pm

clonmac wrote:First you need to know the address of the bluetooth device you want to connect. You can find that by typing in bluetoothctl and it will list any devices you've paired already. Once you have the address, type in the following command to edit root's crontab:

Code: Select all

sudo crontab -e
That will allow you to add new tasks to be run.

At the bottom of that file, add the following line:

Code: Select all

@reboot sleep 5 && /bin/echo -e 'connect XX:XX:XX:XX:XX:XX \n quit \n' | bluetoothctl
I actually decreased the sleep amount on the command to cut down on the wait time before the keyboard connects. That should do it. Hope this helps.
Awesome! Thank you!

However, I actually figured it out since I last posted. I used a little Linux common sense and it occurred to me what you were talking about. :)

This is definitely the best workaround thus far.

DAveShillito
Posts: 10
Joined: Sun Jun 17, 2012 9:43 pm

Re: Connect Bluetooth Keyboard at boot

Mon Sep 26, 2016 12:00 pm

clonmac wrote:Apparently according to Nexdock's site, "the latest version of Raspbian does not support autoreconnect after reboot". I'm wondering if there is a way I can script it out at bootup or use a cronjob every minute to attempt a reconnect.
Cheers for that clonmac.
Do you happen to have a link to that quote? I too have a Nexdock and would just like to read around the problem.

Does anyone know if this is an "issue" with Raspbian that is likely to be fixed in a later update, or if is by design and the cron workaround is the permanent fix?

DAve

User avatar
Douglas6
Posts: 4923
Joined: Sat Mar 16, 2013 5:34 am
Location: Chicago, IL

Re: Connect Bluetooth Keyboard at boot

Mon Sep 26, 2016 12:51 pm

From what I've read here, there are folks with Bluetooth keyboards that DO reconnect, so I'm not certain it's a Raspbian problem.

The quote is from this page: http://nexdock.com/support-raspberry-pi/

Aydan
Posts: 731
Joined: Fri Apr 13, 2012 11:48 am
Location: Germany, near Lake Constance

Re: Connect Bluetooth Keyboard at boot

Tue Sep 27, 2016 2:01 pm

I think the NexDock keyboard doesn't "remember" what it was paired with. It will just accept any pairing request. This means the host has to initiate the connection.

Regards
Aydan

Fii
Posts: 1
Joined: Wed Oct 04, 2017 3:49 am
Location: Surabaya Indonesia

Re: Connect Bluetooth Keyboard at boot

Mon Oct 30, 2017 5:18 pm

clonmac wrote:
Fri Sep 09, 2016 2:19 pm
First you need to know the address of the bluetooth device you want to connect. You can find that by typing in bluetoothctl and it will list any devices you've paired already. Once you have the address, type in the following command to edit root's crontab:

Code: Select all

sudo crontab -e
That will allow you to add new tasks to be run.

At the bottom of that file, add the following line:

Code: Select all

@reboot sleep 5 && /bin/echo -e 'connect XX:XX:XX:XX:XX:XX \n quit \n' | bluetoothctl
I actually decreased the sleep amount on the command to cut down on the wait time before the keyboard connects. That should do it. Hope this helps.
hello i try this way to auto connect my bluetooth keybord to my Raspi but nothing happend. can someone help me?

User avatar
Douglas6
Posts: 4923
Joined: Sat Mar 16, 2013 5:34 am
Location: Chicago, IL

Re: Connect Bluetooth Keyboard at boot

Mon Oct 30, 2017 6:40 pm

Run bluetoothctl. What is the response to 'info <bdaddr>'? What happens if you try 'connect <bdaddr>'? In both cases, replace <bdaddr> with the Bluetooth device address of your keyboard. There were also significant upgrades to Bluetooth made just today, so it wouldn't hurt to make sure your system is upgraded.

Return to “Advanced users”