Created
June 27, 2019 02:25
-
-
Save stickperson/354e79bf5e2af848f8ae7f6a88e5080f to your computer and use it in GitHub Desktop.
Script to run WPS on pi
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# automate WPS Push Button using wpa_supplicant | |
# see also: https://w1.fi/cgit/hostap/plain/wpa_supplicant/README-WPS | |
# to make this run at startup, create a systemd unit that has "Requires=wpa_supplicant.service" and "After=wpa_supplicant.service" | |
INHIBIT="/etc/wpa_supplicant/wps_inhibit" | |
# Should probably sleep here as well and check the status after 10s or so. If not COMPLETED either wifi is down or wifi creds changed. | |
if [ -e $INHIBIT ]; then | |
exit 0 | |
fi | |
while /bin/true; do | |
state="$( wpa_cli status | sed -n 's/wpa_state=\(.*\)/\1/p')" | |
if [ "$state" = "COMPLETED" ]; then | |
touch $INHIBIT | |
exit 0 | |
fi | |
wpa_cli wps_pbc | |
# wps_pbc returns immediately but will start an action that lasts 2 minutes | |
sleep 120 | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment