Bluetooth-PAN piconet (Personal Area Network)
We raise the network via bluetooth on a Raspberry Pi with support systemd.
My friendship with the Raspberry Pi is many years old, and over the years I experimented endlessly. Does the Raspberry Pi encourage adventurism? Among other things, I am a passionate photographer, with might and main I use the “raspberry” as a wireless remote control for the camera using the program gphoto2.
In my configuration, the minicomputer includes its own web server for remote viewing of photos via wi-fi and works in mode access points.
But I need another wireless network interface, and this is where the acquaintance with the PAN piconet begins (HOWTO-PAN).
By the way, Nikon Corporation also uses a similar solution: photos are transmitted via a wi-fi interface, but control is carried out via bluetooth. The program is called SnapBridge for iOS and Android.
And with the help of PAN and ssh, you can remotely control “raspberries”, or even make a bridge to the Internet, for example, to watch news or read mail through a browser.
A few years ago, the piconet was configured using the program pandtoday the obsolete pand utility is no longer supported, the era has come systemd with “units” of loading. I found a working configuration of units on a well-known resource stackoverflowbut the rapid development of bluetooth again required adjustments.
So, let’s start configuring PAN on a systemd-enabled system.
After installing basic bluetooth packages Raspberry Pi OSdownload bluez-utils:
$ sudo apt-get install bluez-utils
See if the bluetooth is blocked by software:
$rfkill (bluetooth must be turned on)
To set up a network, you need to find out the bluetooth hardware addresses on the client and server:
$ hcitool dev (write MAC addresses)
You will also have to define “trusted devices”. There is a utility for this in Linux. bluetoothctl.
There is a lot of exhaustive documentation on bluetoothctl, so I will give the main steps. On the server and client, turn on the bluetooth so that the radio interfaces “shine”, then run the interactive bluetoothctl command, help is called by the help command. Scanning available networks. Find the MAC address of the desired device, do “pair MAC” (automatic completion tab) and “trust MAC”, “connect MAC”.
It seems that all the worst is behind us. But I’ll have to
create four files for systemd to run on the server side.
They are created in directories /etc/systemd/network And /etc/systemd/system.
These are the following files: /etc/systemd/network/pan0.netdev, /etc/systemd/network/pan0.network, /etc/systemd/system/bt-agent.service, /etc/systemd/system/bt-network.service.
Below are the contents of all four files.
“External” address, it will be possible to connect via ssh.
Description=Bluetooth Auth Agent
ExecStart=/usr/bin/bt-agent -c NoInputNoOutput
Description=Bluetooth NEP PAN
ExecStart=/usr/bin/bt-network -s nap pan0
You may need to make changes to the file etc/bluetouch/main.conf
I added just two lines so that the network automatically goes up.
We start systemd services.
$ sudo systemctl enable systemd-networkd
$ sudo systemctl enable bt-agent
$ sudo systemctl enable bt-network
$ sudo systemctl start systemd-networkd
$ sudo systemctl start bt-agent
$ sudo systemctl start bt-network
Everything is done on the server side.
Now on the client side you just need to enter a simple command on the command line (or create a script), where instead of asterisks the MAC address of the server.
$ sudo bt-network -c ******** nap
Note. Command bt network tends to unload with the error “segmentation fault” if the server is unavailable. If the connection is established, you will see the long-awaited inscription “network service is connected“. Check the connection and find the bnep0 interface:
$ ip a | grep bnep
Then, if the connection is established, enter the standard ssh command. (It is assumed that the server name pi)
$ ssh firstname.lastname@example.org
The server will ask for a password and… the setup is complete!
And with the help ifconfig or more modern command ip on the server side, you can see the network devices pan0 and bnep0
PS I’ve been connecting via PAN to my computer for about a year now, the network is surprisingly stable and fast.