Page 1 of 1

Connect Bluetooth Keyboard at boot

Posted: Tue Sep 06, 2016 11:19 pm
by clonmac
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.

Re: Connect Bluetooth Keyboard at boot

Posted: Wed Sep 07, 2016 12:35 am
by Douglas6
The keyboard should reestablish the connection, after tapping a key or two. Make sure your pairing is trusted.

Re: Connect Bluetooth Keyboard at boot

Posted: Wed Sep 07, 2016 1:11 am
by clonmac
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.

Re: Connect Bluetooth Keyboard at boot

Posted: Wed Sep 07, 2016 1:23 am
by Douglas6
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.

Re: Connect Bluetooth Keyboard at boot

Posted: Wed Sep 07, 2016 1:42 am
by clonmac
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

Re: Connect Bluetooth Keyboard at boot

Posted: Wed Sep 07, 2016 1:47 am
by Douglas6
Excellent. Don't know if you want to add 'quit\n' to that.

Re: Connect Bluetooth Keyboard at boot

Posted: Thu Sep 08, 2016 9:51 pm
by sdse78
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...

Re: Connect Bluetooth Keyboard at boot

Posted: Thu Sep 08, 2016 9:56 pm
by sdse78
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:

Re: Connect Bluetooth Keyboard at boot

Posted: Fri Sep 09, 2016 2:19 pm
by clonmac
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.

Re: Connect Bluetooth Keyboard at boot

Posted: Fri Sep 09, 2016 3:12 pm
by sdse78
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.

Re: Connect Bluetooth Keyboard at boot

Posted: Mon Sep 26, 2016 12:00 pm
by DAveShillito
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

Re: Connect Bluetooth Keyboard at boot

Posted: Mon Sep 26, 2016 12:51 pm
by Douglas6
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/

Re: Connect Bluetooth Keyboard at boot

Posted: Tue Sep 27, 2016 2:01 pm
by Aydan
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

Re: Connect Bluetooth Keyboard at boot

Posted: Mon Oct 30, 2017 5:18 pm
by Fii
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?

Re: Connect Bluetooth Keyboard at boot

Posted: Mon Oct 30, 2017 6:40 pm
by Douglas6
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.