Sunday, June 15, 2014

BeagleBone Bluetooth Networking

You're looking a VNC and internet connection to my BeagleBone, all over Bluetooth of course!
So I've been spending a large amount of time messing around with a BeagleBone Black (BBB) lately.  I've experimented with wifi dongles, VNC, Ethernet over USB, and Bluetooth.  I started out programming the BBB from my Mac, and then ended up switching over to a Windows computer.  However, when it came time to set up a Bluetooth connection, I gave up and installed Ubuntu on my Windows computer.  After all, why would you want to program a linux development platform using anything other than linux?

Anyhow, it took me a long time to set up a proper Bluetooth connection.  I ended up creating an IP network connection over Bluetooth, allowing me to SSH and VNC into the bone wirelessly.  Cool stuff!  After a bit of thought, I realized that if I already established an IP connection to the BeagleBone, why not forward it internet through the same address! After a bit more experimentation with programming, I ended up with a BeagleBone that was both remotely accessible and connected to the internet using nothing but Bluetooth.  Below I detail the commands I used to do so, I couldn't find a specific guide for doing all of this on the web so I figured I'd make a tutorial.

First, connect your BeagleBone to the internet and run the following commands.  **These only need to be ran the first time you set up your Bluetooth connection** 

opkg install bridge-utils
opkg install bluez
nano ./test_nap

Next, paste this code into ./test_nap.  Press ^x followed by y to exit and save the file.  In order to make it executable, enter the command chmod +x ./test_nap

The following commands must then be run every time the BBB is rebooted in order to establish remote accessibility and internet over Bluetooth.

On the BeagleBone:

brctl addbr pan0
ifconfig pan0 192.168.99.1 up
./test_nap pan0 &
(press the enter key)

route add default gw 192.168.99.2

Now log out of your connection to the BeagleBone and type this command into your computer's command line:

hcitool scan

Choose the MAC address that corresponds to your BeagleBone based on the results of the hcitool scan command. In my case this is 00:02:72:AB:84:5B

sudo pand -n -c 00:02:72:AB:84:5B

sudo ifconfig bnep0 192.168.99.2

sudo su

iptables --table nat --append POSTROUTING --out-interface wlan0 -j MASQUERADE

iptables --append FORWARD --in-interface bnep0 -j ACCEPT

echo 1 > /proc/sys/net/ipv4/ip_forward

That's it! Pull out your USB cable connection to the BeagleBone and try to connect to it remotely using ssh root@192.168.99.1, then use something along the lines of ping 8.8.8.8 to verify that you're connected to the internet.


The entire process, along with verification that it worked




No comments:

Post a Comment