I have a script in /etc which gets 2 arguments, interface (wlan0) and event (CONNECTED) from wpa_cli
I can manually call the script
wpa_cli -i wlan0 -a /etc/wlan0_connected.sh -B
and it works, it calls my script, passes the 2 args, and the script does it’s thing (writes to log files)…
Now, how do I create a service, to start the wpa_cli cmd on startup, so when the rpiz2w is rebooted it will be monitoring the wlan0 interface and logging the connected disconnect events?
[Unit]
Description=Daemon to receive the wpa_supplicant event
[Service]
#Type=simple
Type=forking
# call wpa_cli pass as arg -a for action script, path to script, interface wlan0, run in Background
ExecStart=/usr/sbin/wpa_cli -a /etc/wpa_ntfy.sh -i wlan0 -B
[Install]
WantedBy=multi-user.target
it shows the wifi disconnecting at 2 am and 8:30, but my script defined by action is not called. i hope this helps.
Jun 06 02:38:26 DietPi wpa_supplicant[1074]: wlan0: CTRL-EVENT-DISCONNECTED bssid=94:a6:7e:de:6b:f1 reason=3 locally_generated=1
Jun 06 02:38:27 DietPi wpa_supplicant[1074]: wlan0: CTRL-EVENT-REGDOM-CHANGE init=CORE type=WORLD
Jun 06 02:38:27 DietPi wpa_supplicant[1074]: wlan0: CTRL-EVENT-REGDOM-CHANGE init=USER type=COUNTRY alpha2=US
Jun 06 02:38:27 DietPi wpa_supplicant[1074]: p2p-dev-wlan0: CTRL-EVENT-DSCP-POLICY clear_all
Jun 06 02:38:27 DietPi wpa_supplicant[1074]: p2p-dev-wlan0: CTRL-EVENT-DSCP-POLICY clear_all
Jun 06 02:38:27 DietPi wpa_supplicant[1074]: nl80211: deinit ifname=p2p-dev-wlan0 disabled_11b_rates=0
Jun 06 02:38:27 DietPi wpa_supplicant[1074]: p2p-dev-wlan0: CTRL-EVENT-TERMINATING
Jun 06 02:38:27 DietPi wpa_supplicant[1074]: wlan0: CTRL-EVENT-DSCP-POLICY clear_all
Jun 06 02:38:27 DietPi wpa_supplicant[1074]: wlan0: CTRL-EVENT-DSCP-POLICY clear_all
Jun 06 02:38:27 DietPi wpa_supplicant[1074]: nl80211: deinit ifname=wlan0 disabled_11b_rates=0
Jun 06 02:38:27 DietPi wpa_supplicant[1074]: wlan0: CTRL-EVENT-TERMINATING
Jun 06 02:38:28 DietPi wpa_supplicant[16694]: Successfully initialized wpa_supplicant
Jun 06 02:38:28 DietPi wpa_supplicant[16694]: nl80211: kernel reports: Registration to specific type not supported
Jun 06 02:38:29 DietPi wpa_supplicant[16697]: wlan0: Trying to associate with 92:fd:1e:86:9f:72 (SSID='mySSID' freq=2422 MHz)
Jun 06 02:38:29 DietPi wpa_supplicant[16697]: wlan0: Associated with 92:fd:1e:86:9f:72
Jun 06 02:38:29 DietPi wpa_supplicant[16697]: wlan0: CTRL-EVENT-SUBNET-STATUS-UPDATE status=0
Jun 06 02:38:29 DietPi wpa_supplicant[16697]: wlan0: CTRL-EVENT-REGDOM-CHANGE init=COUNTRY_IE type=COUNTRY alpha2=US
Jun 06 02:38:32 DietPi wpa_supplicant[16697]: wlan0: CTRL-EVENT-DISCONNECTED bssid=92:fd:1e:86:9f:72 reason=15
Jun 06 02:38:32 DietPi wpa_supplicant[16697]: BSSID 92:fd:1e:86:9f:72 ignore list count incremented to 2, ignoring for 10 seconds
Jun 06 02:38:32 DietPi wpa_supplicant[16697]: wlan0: CTRL-EVENT-REGDOM-CHANGE init=CORE type=WORLD
Jun 06 02:38:32 DietPi wpa_supplicant[16697]: wlan0: CTRL-EVENT-REGDOM-CHANGE init=USER type=COUNTRY alpha2=US
Jun 06 02:38:32 DietPi wpa_supplicant[16697]: wlan0: Trying to associate with 94:a6:7e:de:6b:f1 (SSID='mySSID-basement' freq=2462 MHz)
Jun 06 02:38:32 DietPi wpa_supplicant[16697]: wlan0: Associated with 94:a6:7e:de:6b:f1
Jun 06 02:38:32 DietPi wpa_supplicant[16697]: wlan0: CTRL-EVENT-SUBNET-STATUS-UPDATE status=0
Jun 06 02:38:32 DietPi wpa_supplicant[16697]: wlan0: CTRL-EVENT-REGDOM-CHANGE init=COUNTRY_IE type=COUNTRY alpha2=US
Jun 06 02:38:32 DietPi wpa_supplicant[16697]: wlan0: WPA: Key negotiation completed with 94:a6:7e:de:6b:f1 [PTK=CCMP GTK=CCMP]
Jun 06 02:38:32 DietPi wpa_supplicant[16697]: wlan0: CTRL-EVENT-CONNECTED - Connection to 94:a6:7e:de:6b:f1 completed [id=0 id_str=]
Jun 06 08:27:05 DietPi wpa_supplicant[16697]: wlan0: CTRL-EVENT-DISCONNECTED bssid=94:a6:7e:de:6b:f1 reason=3 locally_generated=1
Jun 06 08:27:05 DietPi wpa_supplicant[16697]: wlan0: CTRL-EVENT-REGDOM-CHANGE init=CORE type=WORLD
Jun 06 08:27:05 DietPi wpa_supplicant[16697]: wlan0: CTRL-EVENT-REGDOM-CHANGE init=USER type=COUNTRY alpha2=US
Jun 06 08:27:05 DietPi wpa_supplicant[16697]: p2p-dev-wlan0: CTRL-EVENT-DSCP-POLICY clear_all
Jun 06 08:27:06 DietPi wpa_supplicant[16697]: p2p-dev-wlan0: CTRL-EVENT-DSCP-POLICY clear_all
Jun 06 08:27:06 DietPi wpa_supplicant[16697]: nl80211: deinit ifname=p2p-dev-wlan0 disabled_11b_rates=0
Jun 06 08:27:06 DietPi wpa_supplicant[16697]: p2p-dev-wlan0: CTRL-EVENT-TERMINATING
Jun 06 08:27:06 DietPi wpa_supplicant[16697]: wlan0: CTRL-EVENT-DSCP-POLICY clear_all
Jun 06 08:27:06 DietPi wpa_supplicant[16697]: wlan0: CTRL-EVENT-DSCP-POLICY clear_all
Jun 06 08:27:06 DietPi wpa_supplicant[16697]: nl80211: deinit ifname=wlan0 disabled_11b_rates=0
Jun 06 08:27:06 DietPi wpa_supplicant[16697]: wlan0: CTRL-EVENT-TERMINATING
Jun 06 08:27:07 DietPi wpa_supplicant[27413]: Successfully initialized wpa_supplicant
Jun 06 08:27:07 DietPi wpa_supplicant[27413]: nl80211: kernel reports: Registration to specific type not supported
Jun 06 08:27:07 DietPi wpa_supplicant[27417]: wlan0: Trying to associate with 92:fd:1e:86:9f:72 (SSID='mySSID' freq=2422 MHz)
Jun 06 08:27:07 DietPi wpa_supplicant[27417]: wlan0: Associated with 92:fd:1e:86:9f:72
Jun 06 08:27:07 DietPi wpa_supplicant[27417]: wlan0: CTRL-EVENT-SUBNET-STATUS-UPDATE status=0
Jun 06 08:27:07 DietPi wpa_supplicant[27417]: wlan0: CTRL-EVENT-REGDOM-CHANGE init=COUNTRY_IE type=COUNTRY alpha2=US
Jun 06 08:27:07 DietPi wpa_supplicant[27417]: wlan0: WPA: Key negotiation completed with 92:fd:1e:86:9f:72 [PTK=CCMP GTK=CCMP]
Jun 06 08:27:07 DietPi wpa_supplicant[27417]: wlan0: CTRL-EVENT-CONNECTED - Connection to 92:fd:1e:86:9f:72 completed [id=1 id_str=]
Jun 06 08:30:36 DietPi wpa_supplicant[27417]: wlan0: CTRL-EVENT-DISCONNECTED bssid=92:fd:1e:86:9f:72 reason=3 locally_generated=1
Jun 06 08:30:37 DietPi wpa_supplicant[27417]: wlan0: CTRL-EVENT-REGDOM-CHANGE init=CORE type=WORLD
Jun 06 08:30:37 DietPi wpa_supplicant[27417]: wlan0: CTRL-EVENT-REGDOM-CHANGE init=USER type=COUNTRY alpha2=US
Jun 06 08:30:37 DietPi wpa_supplicant[27417]: p2p-dev-wlan0: CTRL-EVENT-DSCP-POLICY clear_all
Jun 06 08:30:37 DietPi wpa_supplicant[27417]: p2p-dev-wlan0: CTRL-EVENT-DSCP-POLICY clear_all
Jun 06 08:30:37 DietPi wpa_supplicant[27417]: nl80211: deinit ifname=p2p-dev-wlan0 disabled_11b_rates=0
Jun 06 08:30:37 DietPi wpa_supplicant[27417]: p2p-dev-wlan0: CTRL-EVENT-TERMINATING
Jun 06 08:30:37 DietPi wpa_supplicant[27417]: wlan0: CTRL-EVENT-DSCP-POLICY clear_all
Jun 06 08:30:37 DietPi wpa_supplicant[27417]: wlan0: CTRL-EVENT-DSCP-POLICY clear_all
Jun 06 08:30:37 DietPi wpa_supplicant[27417]: nl80211: deinit ifname=wlan0 disabled_11b_rates=0
Jun 06 08:30:37 DietPi wpa_supplicant[27417]: wlan0: CTRL-EVENT-TERMINATING
Jun 06 08:30:38 DietPi wpa_supplicant[27602]: Successfully initialized wpa_supplicant
Jun 06 08:30:38 DietPi wpa_supplicant[27602]: nl80211: kernel reports: Registration to specific type not supported
Jun 06 08:30:38 DietPi wpa_supplicant[27605]: wlan0: Trying to associate with 94:a6:7e:de:6b:f1 (SSID='mySSID-basement' freq=2462 MHz)
Jun 06 08:30:38 DietPi wpa_supplicant[27605]: wlan0: Associated with 94:a6:7e:de:6b:f1
Jun 06 08:30:38 DietPi wpa_supplicant[27605]: wlan0: CTRL-EVENT-SUBNET-STATUS-UPDATE status=0
Jun 06 08:30:38 DietPi wpa_supplicant[27605]: wlan0: CTRL-EVENT-REGDOM-CHANGE init=COUNTRY_IE type=COUNTRY alpha2=US
Jun 06 08:30:39 DietPi wpa_supplicant[27605]: wlan0: WPA: Key negotiation completed with 94:a6:7e:de:6b:f1 [PTK=CCMP GTK=CCMP]
Jun 06 08:30:39 DietPi wpa_supplicant[27605]: wlan0: CTRL-EVENT-CONNECTED - Connection to 94:a6:7e:de:6b:f1 completed [id=0 id_str=]
i will add, my router has a script which sends me a NTFY when a wireless device connects, so that allows me to see when the rpi is re-joining the wifi, and i can correlate the timestamps to the log on the rpi.
I gave up on trying to get the wpa_sup service to work as I needed it, and searhced for other methods to achieve what I wanted. I found mention of “NetworkManger”, but that is not installed in DietPi. Then I learned about ifupdown, which they claim is old, but it is still used by Debian, and since DietPi is Debian, I found it did exactly what I wanted.
When my wifi interface is brought up (especially after a wi-fi re-connect due to bad location), any scripts located in /etc/network/if-up.d are run
#!/bin/sh
# 2026-06-07 5:53 pm
# whenever a network interface is brought up, i.e. it is active (including when wifi re-connects after being dropped)
# any scripts in the folder /etc/network/if-up.d
# will be run
# make sure the script file is executable chmod +x scriptname
# this script ensures the interface is wlan0 (the main wifi)
# and then does stuff, ie write to log files
# environment variables are available, i found them using google search
# Only run if the interface being brought up is wlan0
if [ "$IFACE" = "wlan0" ]; then
# Place your custom commands below this line
echo "wlan0 is up at $(date)" >> /var/log/wlan0_custom.log
echo "mode is $MODE" >> /var/log/wlan0_custom.log
echo "addrfam is $ADDRFAM" >> /var/log/wlan0_custom.log
echo "logical is $LOGICAL" >> /var/log/wlan0_custom.log
echo "method is $METHOD" >> /var/log/wlan0_custom.log
echo "phase is $PHASE" >> /var/log/wlan0_custom.log
MY_HOSTNAME=$(hostname)
echo "hostname is $MY_HOSTNAME" >> /var/log/wlan0_custom.log
MAC_ADDR=$(ip link show dev "$IFACE" | awk '/ether/ {print $2}')
echo "maccaddr is $MAC_ADDR" >> /var/log/wlan0_custom.log
# Extract SSID
SSID=$(iw dev wlan0 link | grep "SSID:" | awk -F': ' '{print $2}')
echo "SSID is $SSID" >> /var/log/wlan0_custom.log
# Extract Signal Strength in dBm
SIGNAL=$(iw dev wlan0 link | grep "signal:" | awk -F': ' '{print $2}' | xargs)
echo "ssid signal dBm is $SIGNAL" >> /var/log/wlan0_custom.log
fi