Raspberry Pi Pan

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.

/etc/systemd/network/pan0.netdev

[NetDev]
Name=pan0
Kind=bridge

/etc/systemd/network/pan0.network

[Match]
Name=pan0

[Network]

“External” address, it will be possible to connect via ssh.

Address=192.168.5.1/24
DHCPServer=yes

/etc/systemd/system/bt-agent.service

[Unit]
Description=Bluetooth Auth Agent

[Service]
ExecStart=/usr/bin/bt-agent -c NoInputNoOutput
Type=simple

[Install]
WantedBy=multi-user.target

/etc/systemd/system/bt-network.service

[Unit]
Description=Bluetooth NEP PAN
After=pan0.network

[Service]
ExecStart=/usr/bin/bt-network -s nap pan0
Type=simple

[Install]
WantedBy=multi-user.target

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.

DiscoverableTimeout=60
AutoEnable=true

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 pi@192.16.8.5.1

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.

Similar Posts

2 Comments

  1. I love this layout for PAN.
    I made 1 small tweak to bt-agent.service that gives the info for connection to the PAN, and would be available anytime you perform a status of bt-agent.service.
    In case whoever might use this forgets the connection command, lol

    place inside [Service]:
    ExecStartPost=sh -c ‘printf “%%s\n” “clients use: sudo bt-network -C $( bt-adapter -l | sed -rn “s/.*?(([[:xdigit:]]{2}:){5}[[:xdigit:]]{2}).*/\1/p” ) nap”‘

  2. My bad , it looks like the “-c” options, on the bt-network command, should be lower case.

    Also here’s an example of what the output looks like from the systemctl status bt-agent looks like, in reference to this modification.

    Oct 13 16:01:40 piload sh[4547]: clients use: sudo bt-network -c B8:27:EB:D3:9D:34 nap

Leave a Reply

Your email address will not be published. Required fields are marked *