Check hostapd managed WLAN DFS status and trigger interface reboot when DFS brings down the interface. Compatible on OpenWrt.
This script write a pid file for checking concurrent running instances, so it's safe to call it from crontab.
Modify the code to best suit your needs. Things which you should definitely configure:
send_web_requestfunction andURL,TOKENvalue to implement your own notification method. The one I am using: ttimasdf/wework-webhook: Push notification through webhook to Wechat Work application- Check the interface name, which is currently hard coded to
wlan0(andradio0), the 802.11a WLAN interface on my router. - install
bashif you are using OpenWrt. Busyboxashis untested. If your router has insufficient storage for packages, maybe you should change a router 😉 - install a crontab entry for this script with
crontab -e* * * * * /root/cron-wlan0-dfs.sh
It's done!
log messages print out both to stdout and openwrt system log. If you are using other log systems, modify the log function as needed.
The raw result from LLM is omitted for conciseness. I've also add some minor changes before final releasing.
Write a bash script for a cron job following these requirements:
- The script check the output of
hostapd_cli -i wlan0 statusand check for itsstate. store the state in/var/run/wlan0-last-statefile.- read the last state before storing state, if state is changing, notify the state change by
curl -v https://webhook.com/wework/appid/text -H "X-WW-Auth: $token" -d 'msg content'- if the state changes from
ENABLEDsomething else, likeDFSorDISABLED, restart the WiFi by/sbin/wifi up radio0. and monitor the state once per second for 2 minutes, notify state changes inside this time period.- Since this script is a one-shot running once a minute. if any previous script is still running, the subsequent script running should be skipped. the running state is maintained by a pid file
/var/run/cron-wlan0-dfs.pidand the running check is done through checking the pid number. no additional lock file is needed.- log output should be wrapped by a helper function like:
log() { echo "$1" logger -t "wlan_checker" "$1" }
Request for changes.
- In
restart_and_monitor_wifi, the send_web_request should be called only when there's state change in wlan0 interface, like maintain a variableprevious_stateand check with currentstate.- In
send_web_request, the function should log the message content tologfunction.- In
send_web_request, curl should use$HOME/root_vm.crtas trusted root certificate, and remove-vflag- abstract the
hostapd_clicall for wlan0 check to a new function and return the state string likeENABLEDDFS, and add a condition wherehostapd_cli -i wlan0 statuscontains string likewpa_ctrl_open: No such file or directoryin stderr. In this case, return the caseDISABLED.