Use bluetooth as ssh terminal for pi zero stretch - hydrogeologger/pyduino GitHub Wiki

Note

May need to vnc in to rpi to enable bluetooth or

rfkill unblock bluetooth

use bluetooth as ssh terminal for pi zero stretch

apt-get install bluez-tools

Go to 'superuser' mode and create the file /etc/systemd/network/pan0.netdev, add the following lines

[NetDev]
Name=pan0
Kind=bridge

Create the file /etc/systemd/network/pan0.network, write:

[Match]
Name=pan0

[Network]
Address=172.20.1.1/24
DHCPServer=yes

Create the file /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

Create the file /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

run the following commands in prompt:

systemctl enable systemd-networkd
systemctl enable bt-agent
systemctl enable bt-network
systemctl start systemd-networkd
systemctl start bt-agent
systemctl start bt-network
systemctl status systemd-networkd
systemctl status bt-agent
systemctl status bt-network

root@hydrogeologgermini:/home/pi# systemctl status systemd-networkd
● systemd-networkd.service - Network Service
   Loaded: loaded (/lib/systemd/system/systemd-networkd.service; enabled; vendor preset: enabled)
   Active: active (running) since Thu 2019-09-05 15:35:09 AEST; 26min ago
     Docs: man:systemd-networkd.service(8)
 Main PID: 19479 (systemd-network)
   Status: "Processing requests..."
   CGroup: /system.slice/systemd-networkd.service
           └─19479 /lib/systemd/systemd-networkd

Sep 05 15:35:09 hydrogeologgermini systemd[1]: Started Network Service.
Sep 05 15:35:10 hydrogeologgermini systemd-networkd[19479]: pan0: IPv6 enabled for interface: Success
Sep 05 15:37:33 hydrogeologgermini systemd-networkd[19479]: bnep0: Gained carrier
Sep 05 15:37:33 hydrogeologgermini systemd-networkd[19479]: pan0: Gained carrier
Sep 05 15:37:34 hydrogeologgermini systemd-networkd[19479]: pan0: Gained IPv6LL
Sep 05 15:37:34 hydrogeologgermini systemd-networkd[19479]: bnep0: Gained IPv6LL
Sep 05 15:37:47 hydrogeologgermini systemd-networkd[19479]: pan0: Configured
Sep 05 15:45:31 hydrogeologgermini systemd-networkd[19479]: bnep1: Gained carrier
Sep 05 15:45:33 hydrogeologgermini systemd-networkd[19479]: bnep1: Gained IPv6LL
Sep 05 15:51:51 hydrogeologgermini systemd-networkd[19479]: bnep1: Lost carrier
root@hydrogeologgermini:/home/pi# systemctl status bt-agent
● bt-agent.service - Bluetooth Auth Agent
   Loaded: loaded (/etc/systemd/system/bt-agent.service; enabled; vendor preset: enabled)
   Active: active (running) since Thu 2019-09-05 15:35:09 AEST; 26min ago
 Main PID: 19493 (bt-agent)
   CGroup: /system.slice/bt-agent.service
           └─19493 /usr/bin/bt-agent -c NoInputNoOutput

Sep 05 15:35:09 hydrogeologgermini systemd[1]: Started Bluetooth Auth Agent.
Sep 05 15:35:10 hydrogeologgermini bt-agent[19493]: Agent registered
Sep 05 15:35:10 hydrogeologgermini bt-agent[19493]: Default agent requested
root@hydrogeologgermini:/home/pi# systemctl status bt-network
● bt-network.service - Bluetooth NEP PAN
   Loaded: loaded (/etc/systemd/system/bt-network.service; enabled; vendor preset: enabled)
   Active: active (running) since Thu 2019-09-05 15:35:12 AEST; 26min ago
 Main PID: 19522 (bt-network)
   CGroup: /system.slice/bt-network.service
           └─19522 /usr/bin/bt-network -s nap pan0

Sep 05 15:35:12 hydrogeologgermini systemd[1]: Started Bluetooth NEP PAN.
Sep 05 15:35:12 hydrogeologgermini bt-network[19522]: NAP server registered



$ifconfig
bnep0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 169.254.210.230  netmask 255.255.0.0  broadcast 169.254.255.255
        inet6 fe80::ba27:ebff:fe24:a884  prefixlen 64  scopeid 0x20<link>
        ether b8:27:eb:24:a8:84  txqueuelen 1000  (Ethernet)
        RX packets 548  bytes 117855 (115.0 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 716  bytes 273287 (266.8 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 371  bytes 114249 (111.5 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 371  bytes 114249 (111.5 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

pan0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.20.1.1  netmask 255.255.255.0  broadcast 172.20.1.255
        inet6 fe80::1863:73ff:fe7e:35da  prefixlen 64  scopeid 0x20<link>
        inet6 fe80::851c:1de:fe19:5a9f  prefixlen 64  scopeid 0x20<link>
        ether 1a:63:73:7e:35:da  txqueuelen 1000  (Ethernet)
        RX packets 969  bytes 249474 (243.6 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 197  bytes 41101 (40.1 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

wlan0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 10.184.50.59  netmask 255.255.252.0  broadcast 10.184.51.255
        inet6 fe80::561b:75d4:7491:65ce  prefixlen 64  scopeid 0x20<link>
        ether b8:27:eb:db:57:7b  txqueuelen 1000  (Ethernet)
        RX packets 33287  bytes 16147666 (15.3 MiB)
        RX errors 0  dropped 3  overruns 0  frame 0
        TX packets 4782  bytes 608587 (594.3 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

Finally

sudo bt-adapter --set Discoverable 1

Note:

  • The above command will set to 0 after reboot, so we will need to permanently set the Bluetooth discoverable by editing the file /etc/bluetooth/main.conf
DiscoverableTimeout = 0
  • If swapping RPI hardware, bluetooth discoverable will be set back to 0 again.

Connecting by Windows 10, go to bluetooth -> add bluetooth or device -> bluetooth (now searching for device) -> click connecting -> right click bluetooth icon and right click and select 'join a personal area network' -> right click the device and select 'connect using access point' -> open up putty and ssh to

In stretch, no password is needed, after paired, it is necessary to right click the bluetooth icon -> join a personal area network 172.20.1.1

Note: It is strongly suggested that the user of the datalogger need to change their datalogger name to a unique name, so that user will not be confused by which dataloggers to connect to, when multiple loggers having the same name are powered on at the same time in a confined space (e.g., lab).

Assuming the default datalogger name is 'raspberrypi', and your desired name is 'hydrogeologger' (which could be infiltration_project,dp, and so on, without space) you could change the name by issuing the following command as superuser:

sed -i '${s/raspberrypi/hydrogeologger/}' /etc/hosts
sed -i '${s/raspberrypi/hydrogeologger/}' /etc/hostname

then reboot the pi

reference: https://raspberrypi.stackexchange.com/questions/29504/how-can-i-set-up-a-bluetooth-pan-connection-with-a-raspberry-pi-and-an-ipod

Run the line below when hostapd does not start at reboot

sudo /usr/sbin/hostapd -dd /etc/hostapd/hostapd.conf

⚠️ **GitHub.com Fallback** ⚠️