2

I want to enable bluetooth device when system is up.

Which is the recommended way to do it?

The command is sudo hciconfig hci0 up.

Should I put it in /etc/rc.local? or should I use update-rc.d?

If there is no "proper" way to do it, I'll choose the way with /etc/rc.local.

Thanks.

Edit

Following @krt's answer I added @reboot cronjob, but hci0 are still down when rebooting. According to /var/log/syslog the job is running correctly.

1136 May 24 11:17:20 klein /usr/sbin/cron[2107]: (CRON) INFO (pidfile fd = 3)
1137 May 24 11:17:20 klein /usr/sbin/cron[2108]: (CRON) STARTUP (fork ok)
1138 May 24 11:17:20 klein /usr/sbin/cron[2108]: (CRON) INFO (Running @reboot jobs)
  • What (Linux?) distribution are you running? If it's Debian/Raspbian, what's the output of dpkg -S /sbin/init? – Gilles May 24 '15 at 17:31
1

Is your system starting bluetoothd at boot? If yes, then you should check its configuration: it might be overriding the settings you make with hciconfig as it starts up.

For example, the [Policy] section of my /etc/bluetooth/main.conf has an AutoEnable setting, which defaults to false. If you set it to true, then all Bluetooth interfaces get activated automatically by bluetoothd.

If you want more fine-grained control than that, you may have to use bluetoothctl or some other command (depends on your BlueZ version).

0

with systemd unit, create for example /usr/lib/systemd/system/bluetooth-audio.service and add After=bluetooth.target, in order to make the unit start right after bluetooth.target had been reached and BindsTo=bluetooth.target to make it fail when bluetooth.target had failed:

#!/bin/sh
[Unit]
Description=Bluetooth Audio Connect
ConditionPathIsDirectory=/sys/class/bluetooth
After=bluetooth.target
BindsTo=bluetooth.target

[Service]
ExecStart=/home/scripts/bluetooth_connect.sh
Type=simple

systemctl daemon-reload and systemctl start bluetooth-audio.service bring the unit up. the problem is, that running scripts from udev is pretty useless, while there is no bluetooth yet. here are the corresponding (my) bluetooth_connect and bluetooth_disconnect shell scripts.

-1

Instead of using /etc/rc.local or update-rc-d you colud simply create a new @reboot cronjob. To do this, open up root's crontab with:

sudo crontab -u root -e

And add the following to it:

@reboot hciconfig hci0 up 

Crontabs @reboot runs the job once on each boot and reboot.

  • Thanks for your answer and sorry for late reply. I couldn't take time for raspberry pi. I did what you recommended but @reboot job didn't work. – ironsand Jun 26 '15 at 11:51
-1

Put the following in /etc/cron.d/<yourfilename>

#enable BT
@reboot root hciconfig hci0 up

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.