Skip to content

Instantly share code, notes, and snippets.

@matteodelabre
Last active December 3, 2021 03:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matteodelabre/91f02eee2904c5f0cb75f0847ec045f9 to your computer and use it in GitHub Desktop.
Save matteodelabre/91f02eee2904c5f0cb75f0847ec045f9 to your computer and use it in GitHub Desktop.
Display wlan0 IP address on screen on reMarkable
#!/usr/bin/env bash
# /home/root/monitor_wlan0_ip.sh
iface=wlan0
get_dbus_iface() {
dbus-send --system --dest=fi.w1.wpa_supplicant1 --print-reply=literal \
/fi/w1/wpa_supplicant1 \
fi.w1.wpa_supplicant1.GetInterface \
"string:$iface" \
| sed 's/^ *//g'
}
get_interface_state() {
dbus-send --system --dest=fi.w1.wpa_supplicant1 --print-reply=literal \
"$(get_dbus_iface)" \
org.freedesktop.DBus.Properties.Get \
string:fi.w1.wpa_supplicant1.Interface string:State \
| awk '{print $2}'
}
monitor_interface() {
dbus-monitor --system "type=signal,sender='fi.w1.wpa_supplicant1',interface='fi.w1.wpa_supplicant1.Interface',member=PropertiesChanged" --profile
}
get_ip() {
ip addr show "$iface" | awk '/inet /{print $2}' | cut -d'/' -f1
}
print_ip() {
fbink --flash -x 30 -y 310 "$(printf " %-15s " "$1")" 2> /dev/null
}
last_ip=
monitor_interface | while read line; do
if [[ $(get_interface_state) = "completed" ]]; then
cur_ip="$(get_ip)"
if [[ -z $cur_ip ]]; then
print_ip "ip pending..."
while [[ -z $cur_ip ]]; do
cur_ip="$(get_ip)"
sleep 1s
done
fi
else
cur_ip="wlan offline"
fi
if [[ $cur_ip != "$last_ip" ]]; then
last_ip="$cur_ip"
print_ip "$cur_ip"
fi
done
# /etc/systemd/system/monitor-wlan0-ip.service
[Unit]
Description=Monitor and print wlan0 IP
After=home.mount xochitl.service rm2fb.service
[Service]
Environment=PATH=/opt/sbin:/opt/bin:/opt/usr/bin:/sbin:/bin:/usr/bin
WorkingDirectory=/home/root
ExecStartPre=/bin/sleep 30
ExecStart=/home/root/monitor_wlan0_ip.sh
Restart=on-failure
[Install]
WantedBy=multi-user.target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment