Steps (11) to be done to automatically enable RPi Bluetooth connection with my phone using a static IP address.
On my Raspberry is installed the Raspbian release that can be known running from its terminal:
pi@raspberrypi ~ $cat /etc/os-release
and in this case is the last one ( Dec 2018)
VERSION = '9 (stretch )'
Precondition - Bluetooth pairing:
0- pair your raspberry pi with your mobile device
Steps from 1 to 5 are described ( and reported here) in README.md file in github repository at point 1-
https://github.com/WayneKeenan/Raspberr ... utoConnect
download this files:
After cloning this repository copy the 2 scripts bt-pan and check-and-connect-bt-pan.sh into ~pi/bin
(create the folder if necessary)
and from the pi terminal change theirs attribute :
pi@raspberrypi ~ $chmod +x /bin/bt-pan
pi@raspberrypi ~ $chmod +x /bin/check-and-connect-bt-pan.sh
Find your Mac/PC /Mobile Device MAC Address
We need the Bluetooth MAC address of your Mac/PC or Mobile Device that is providing the Bluetooth network.
On the Pi run hcitool scan:
pi@raspberrypi ~ $hcitool scan
Edit check-and-connect-bt-pan.sh and replace the exisitng MAC address assigned to BT_MAC_ADDR with the one found by hcitool scan for your computer.
BT_MAC_ADDR=<Your MAC address>
ref https://www.raspberrypi.org/documentati ... ge/cron.md
In order for the Pi to automatically (re)connect create a cron job to run a script every minute.
pi@raspberrypi ~ $crontab -e
Add this line:
* * * * * /home/pi/bin/check-and-connect-bt-pan.sh
Then save the file.
6- Activate on your mobile device the Bluetooth tethering entering in Setting/Tethering and Mobile hotspot
7- from the Raspbian terminal run :
pi@raspberrypi ~ $/home/pi/bin/check-and-connect-bt-pan.sh
to enable the bluetooth connection.
8- With a static(****) IP, you’ll be able to use the same IP address every time you connect to your Pi. Run from the terminal :
pi@raspberrypi ~ $ifconfig bnep0
and take note of Raspberry IP address that is like 192.168.44.49 (*)that will be used for static ip_address in dhcpcd.conf file
9- Run from the terminal :
pi@raspberrypi ~ $route -en
and take note of gateway IP address that is like 192.168.44.1 It will be used for the static routers and enter
pi@raspberrypi ~ cat /etc/resolv.conf
at the command prompt to find the domain name servers that will be used for the static domain_name_servers
in dhcpcd.conf file
10- from the Raspbian terminal run :
pi@raspberrypi ~ $sudo leafpad /etc/dhcpcd.conf
and add (at the end) the following 4 lines and then save the file
11- Reboot your Pi and verify the automatic Bluetooth connection with your mobile device
(*) 192.168.44.<x> where x can be your choice :
2<= x <= 254
(**) the same procedure can be used for USB tethering substituting bnep0 connection with usb0 connection .
(***) As simple solution ( 5-) , to test the process, you can place the following script command in /etc/rc.local file before the exit(0) row
By default the Pi is configured with a dynamic IP address. To assign it a static IP address, you need to add your static IP, default gateway IP, and domain name servers to the dhcpcd.conf file.