Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save rfairley/70cec17b26b48ee328539c37af1cede8 to your computer and use it in GitHub Desktop.
Save rfairley/70cec17b26b48ee328539c37af1cede8 to your computer and use it in GitHub Desktop.
Raspberry Pi 3 B headless setup and systemd unit announcing IP address through audio jack

Headless setup

For headless setup using Wifi, follow: https://www.raspberrypi.org/documentation/configuration/wireless/headless.md

An example wpa_supplicant.conf file can be found here, as well as other ways to find the IP address of the RPi (nmap, Apple's Bonjour): https://blog.erratasec.com/2018/08/provisioning-headless-raspberry-pi.html#.XNeVuKQpAaF

The command wpa_passphrase can be used to generate a hash of your Wifi network's security key, instead of store it in plaintext in the wpa_supplicant.conf file.

To initially find the IP address of the RPi, I logged into my home router's admin console to find the DHCP-assigned IP address. After doing that I could ssh pi@<ip address> and add the following unit for later use:

Systemd unit announcing IP address through audo jack

utra-say-ip.service (copy it to /etc/systemd/system/utra-say-ip.service):

[Unit]
Description=Say the host IP address out through speaker
Before=systemd-user-sessions.service
Wants=network-online.target
After=network-online.target

[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/home/pi/say_ip_address

[Install]
WantedBy=multi-user.target

And the say_ip_address script (at /home/pi/say_ip_address):

#!/bin/bash

for i in {1..5}
do
        hostname -I | festival --tts
        sleep 1
done

Once the scripts are in place, do:

sudo apt install festival
chmod +x /home/pi/say_ip_address
sudo systemctl enable utra-say-ip

Then, doing systemctl reboot, the RPi should announce its Wifi IP address through the audo jack when you have speakers or headphones connected. You can then SSH into the Pi using that address.

Note the Pi is only configured to connect to the networks you specified in wpa_supplicant.conf.

This method is based on: https://www.instructables.com/id/How-a-headless-Raspberry-Pi-can-tell-you-its-IP-ad/

Another interesting gist to provision the Pi (ideally we wouldn't have to add in the above unit and script and enable it manually - this would be done at install time): https://gist.github.com/RichardBronosky/fa7d4db13bab3fbb8d9e0fff7ea88aa2

@rfairley
Copy link
Author

To find pi IP address by scanning network:

sudo nmap -sP 192.168.1.0/24 | awk '/^Nmap/{ip=$NF}/B8:27:EB/{print ip}'

(https://raspberrypi.stackexchange.com/questions/13936/find-raspberry-pi-address-on-local-network)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment