wifimngr: use ruleng for WPS LED handling instead of script

This commit is contained in:
Sukru Senli 2021-02-20 14:01:49 +01:00
parent 262e346eb4
commit 2f51c4fc69
4 changed files with 86 additions and 49 deletions

View file

@ -13,8 +13,6 @@ start_service() {
# procd_set_param stderr 1 #for debugging only
procd_set_param respawn
procd_close_instance
wps-monitor
}
reload_service() {

View file

@ -0,0 +1,84 @@
{
"wps_active": {
"if_operator" : "OR",
"if" : [
{
"event": "wifi.ap",
"match": {
"event":"wps-pbc-active"
}
},
{
"event": "wifi.bsta",
"match": {
"event":"wps-pbc-active"
}
}
],
"then" : [
{
"object": "led.wps",
"method":"set",
"args" : {
"state": "notice"
},
"timeout": 1
}
]
},
"wps_success": {
"if_operator" : "OR",
"if" : [
{
"event": "wifi.ap",
"match": {
"event":"wps-reg-success"
}
},
{
"event": "wifi.bsta",
"match": {
"event":"wps-success"
}
}
],
"then" : [
{
"object": "led.wps",
"method":"set",
"args" : {
"state": "ok",
"timeout": 30
},
"timeout": 1
}
]
},
"wps_timeout": {
"if_operator" : "OR",
"if" : [
{
"event": "wifi.ap",
"match": {
"event":"wps-timeout"
}
},
{
"event": "wifi.bsta",
"match": {
"event":"wps-timeout"
}
}
],
"then" : [
{
"object": "led.wps",
"method":"set",
"args" : {
"state": "off"
},
"timeout": 1
}
]
}
}

View file

@ -0,0 +1,2 @@
uci -q set ruleng.wps=rule
uci -q set ruleng.wps.recipe='/etc/ruleng/wps.json'

View file

@ -1,47 +0,0 @@
#!/bin/sh
. /usr/share/libubox/jshn.sh
if [ -f /tmp/wps-monitor.pid ]; then
kill -9 $(cat /tmp/wps-monitor.pid) 2>/dev/null
rm -f /tmp/wps-monitor.pid
fi
[ "$1" == "stop" ] && exit
WPSENABLED=0
for vif in $(uci show wireless | grep wifi-iface | awk -F[.,=] '{print$2}'); do
[ "$(uci -q get wireless.$vif.wps_pushbutton)" == "1" ] && WPSENABLED=1
done
if [ $WPSENABLED -eq 0 ]; then
ubus call led.wps set '{"state":"off"}'
exit
fi
ubus listen wifi.ap wifi.bsta | \
while read wpsevent ; do
#echo "wps-monitor got event: $event" >/dev/console
json_load "$wpsevent"
if json_select wifi.ap >/dev/null; then
json_get_var event event
if [ "$event" == "wps-pbc-active" ]; then
ubus call led.wps set '{"state":"notice"}'
elif [ "$event" == "wps-reg-success" ]; then
ubus call led.wps set '{"state":"ok","timeout":30}'
elif [ "$event" == "wps-timeout" ]; then
ubus call led.wps set '{"state":"off"}'
fi
elif json_select wifi.bsta >/dev/null; then
json_get_var event event
if [ "$event" == "wps-pbc-active" ]; then
ubus call led.wps set '{"state":"notice"}'
elif [ "$event" == "wps-success" ]; then
ubus call led.wps set '{"state":"ok","timeout":30}'
elif [ "$event" == "wps-timeout" ]; then
ubus call led.wps set '{"state":"off"}'
fi
fi
done &
echo $(($!-1)) $! >/tmp/wps-monitor.pid