Enable Bluetooth and connect to devices on boot

Enable Bluetooth and connect to devices on boot

Enable Bluetooth and connect to devices on boot

No Comments on Enable Bluetooth and connect to devices on boot

Now that the networking part is actually working, we need to fix the small errors that appeared along the way. My Raspberry can’t find the USB Bluetooth device on boot, and I also need to connect to the phone and enable the DHCP server. All of this can be easily accomplished by the use of Bash and crontab.
In order to start making an android app connect to this, I need the Raspberry to do all the dirty work first. Such as connecting to the phone’s Bluetooth and setting up the IP addresses. Let’s dive into it and see how to enable Bluetooth and connect to devices on boot.

To enable Bluetooth I simple restart the service using

/etc/init.d/bluetooth restart

Now the Bluetooth service works fine, heres a DMESG:
Dmesg bluetooth
We need to connect to the phone using BNEP, and to enable the DHCP service on our new bnep0 networking device. Since there are just a few basic commands each time, it seems easier just to use the Crontab functionality.

crontab -e

Heres mine:
crontab bluetooth

@reboot sudo bash /root/restartBluetooth.sh

Opens the file whenever the raspberry pi is booting up. Here is the script:

#!/bin/bash
/etc/init.d/bluetooth restart
sleep 10
pand –connect CC:F9:E8:E2:20:36 -n
sleep 5
dhclient bnep0

Save it and reboot. Now the device should connect to the phone at boot time, and start the DHCP server as well.

Martin Jørgensen

Martin Jørgensen

Got my degree from EAL in 2012 as an IT-Technologist with specialty in network. I enjoy living in a century where I can earn a living doing my hobby. Material I publish here are often part of my small projects.
Martin Jørgensen

Latest posts by Martin Jørgensen (see all)

Related Posts

Back to Top