Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IP over Bluetooth with Raspbian systems

I have got 2 Raspberry Pis, running Raspbian, up-to-date. Each Pi has exactly one Bluetooth USB dongle. I can make them communicate via RFCOMM using this.

Now, I would like to establish a proper IP layer over the Bluetooth physical link. As far as I understand, I have to use PAN (Personal Area Network), that should create a network interface I could manage with ifconfig. I am trying to adapt this tutorial, but I am stuck at an invalid exchange error.

On RPi0, I run

$ sudo pand --nodetach --listen --master --role=NAP
pand[2313]: Bluetooth PAN daemon version 4.99

On RPi1, I run

$ pand --nodetach --connect 00:1A:7D:DA:71:16
pand[2323]: Bluetooth PAN daemon version 4.99
pand[2323]: Connecting to 00:1A:7D:DA:71:16
pand[2323]: Connect to 00:1A:7D:DA:71:16 failed. Invalid exchange(52)

I cannot find any relevant information about this error code. Any idea how I could solve this ? Or am I mistaken and should I use something else instead of PAN ?

Thanks in advance !

EDIT: When specifying the Bluetooth device I want to listen on, I get another error message. It doesn't really make sense either, since I do not run any other Bluetooth server.

$ sudo pand -i 00:1A:7D:DA:71:16 --nodetach --listen --role=NAP
pand[2582]: Bluetooth PAN daemon version 4.99
pand[2582]: Bind failed. Address already in use(98)
like image 661
tvuillemin Avatar asked Feb 03 '15 16:02

tvuillemin


People also ask

Can Raspberry Pi receive Bluetooth data?

Raspberry Pi has on-board Bluetooth which can be used for communication or sending/receiving files. Before establishing communication between Raspberry Pi and a Bluetooth enabled device, we need to pair them. Pairing a Bluetooth device on Raspberry Pi is same as that on a mobile or Laptop. Then make it discoverable.

Does a Raspberry Pi have its own IP address?

Turn on your Raspberry Pi, and make sure it's connected to a network. Open a terminal on your Pi. Enter the command hostname -I in the terminal. Your Pi's IP address is the first part of the output: it will contain four numbers separated by periods, like so: 192.


3 Answers

So things seem to have changed quite a lot recently and the Pi comes with Bluez 5.23 in 2016.

Having just spent two days, these steps have solved it for my pi but might help for any Debian Jessie install. I hope so. Tested on a new pi, running jessie with fresh install just now. This will give a bluetooth pan bridged to your eth0 network (and thus use your existing dhcp/dns server etc). This is my first post, so please forgive stupidity around the various conventions here. I hope this helps someone and saves you a little time.

This is prbably not an optimal solution (I'm no guru), and I'd love to hear about some improvements.

Install some things (python stuff will help with scritps): sudo apt-get install bridge-utils bluez python-dbus python-gobject

Download two very cool python scripts, put them in /usr/local/bin and chmod both perhaps to 755 depending on who needs access to execute... blueagent5 and bt-pan. Many thanks and homage to their respective authors. Gosh this kind of thing saves so much time and misery.

Now, we need a bridge. Add the following to the end of /etc/network/interfaces

auto pan0
iface pan0 inet dhcp
  bridge_stp off
  bridge_ports eth0

I rebooted at about this time to make sure all was as it would be normally.

sudo reboot

Log back in and we issue

modprobe bnep
hciconfig hci0 lm master,accept
ip link set pan0 up

If you don't want pin prompt, don't do this next step. To ensure we get a PIN prompt, issue this...

hciconfig hci0 sspmode 0

Start PAN using the special magic in the bt-pan script. It doesn't return, so add an ampersand at the end.

bt-pan  server pan0 &

Start the bluetooth security agent with wonderful ease and confidence. Optionally set a pin (it defaults to 0000).

blueagent5 --pin 4321 &

Okay, one last thing. Forward the network. This will only work if there is no fancy authentication at the router/dhcp, if there is, you may need to look further to solve this issue.

sysctl -w net.ipv4.ip_forward=1

iptables -A INPUT -i pan0 -j ACCEPT
iptables -A FORWARD -i pan0 -j ACCEPT

Once done, you may need to save these iptables settings and reinstate them each time the system boots.

Tiptoe over to your tablet or whatever you are trying to connect to the internet. Open Bluetooth in your settings. Pair with 4321 as your pin, and connect to the local network.

But you didn't need to tiptoe after all, it all seems quite robust to me. Enjoy!

like image 119
CowsWithGuns Avatar answered Sep 18 '22 15:09

CowsWithGuns


After a lot of struggle, this is how I got it working. Let's hope it can help someone else. Long story short, edit /etc/bluetooth/main.conf to include this line:

DisablePlugins = network

Restart the bluetooth service.

sudo service bluetooth restart

FYI, here is my command for the "server" :

sudo pand -i 00:1A:7D:DA:71:14 --listen --master --role=NAP

And for the "client":

sudo pand --nodetach --connect 00:1A:7D:DA:71:14

Then you can just use ifconfig, ping, ssh... usual stuff. You might want to take a look here, it was useful to me.

like image 35
tvuillemin Avatar answered Sep 22 '22 15:09

tvuillemin


@cowswithguns

Your solution works almost flawlessly except for

bt-pan  server pan &

it should be

bt-pan  server pan0 &

Works great with rpi3 and bluez5.X

Only caveat it still uses somehow the wifi. I am trying to ssh to rpi3 via bluetooth while rpi3 is associated with a device that provide its own AP for a one-to-one connection and this cuts off the bluetooth communication. Works only if the rpi3 is associated to a wifi AP.

like image 30
Marcello Avatar answered Sep 21 '22 15:09

Marcello