Hi again mates @frollic @ncompact @pavelgl :
After reading more about how to attach functions to a push button and take a look to your fantastic scripts, I've to say that I don't have be able to accomplish my objective, well, my device uses gpio buttons (sorry for don't say it before), and there are only two physical buttons, reset and rfkill (or wifi like you prefer), the firs is used for "reset" and "wps" functions in original firmware but only for reset in OpenWrt, and the second button (rfkill) is a switch with 2 positions.
About the rfkill button, I prefer to use it in place of reset button, using the method described at wiki:
opkg update
opkg install kmod-button-hotplug
mkdir -p /etc/hotplug.d/button
cat << "EOF" > /etc/hotplug.d/button/buttons
logger "the button was ${BUTTON} and the action was ${ACTION}"
EOF
The logread shows the next:
Tue May 16 10:34:34 2023 user.notice root: the button was rfkill and the action was pressed
Tue May 16 10:34:36 2023 user.notice root: the button was rfkill and the action was released
That was to use the switch one time in each position, the pressed action when I change the position from off to on, and the released action when I change from on to off.
I've to say that I'm using the device as a managed switch, because of that, I'm not using the Wi-Fi, this is why I prefer use this button instead of the reset button, is there any way to adapt your scripts to make use of the rfkill (switch) button?
P.S.: Like the Wiki indicates, to see which buttons are available:
find /sys/firmware/devicetree/base/keys -mindepth 1 -type d | while read -r f; do printf '%s: %s\n' $(basename $f) $(hexdump -s2 -e '2/1 "%02x""\n"' $f/linux,code); done
wifi: 00f7
reset: 0198
P.S.2: I show you the rfkill script associated to wifi button:
#!/bin/sh
[ "${ACTION}" = "released" -o -n "${TYPE}" ] || exit 0
. /lib/functions.sh
rfkill_state=0
wifi_rfkill_set() {
uci set wireless.$1.disabled=$rfkill_state
}
wifi_rfkill_check() {
local disabled
config_get disabled $1 disabled
[ "$disabled" = "1" ] || rfkill_state=1
}
config_load wireless
case "${TYPE}" in
"switch")
[ "${ACTION}" = "released" ] && rfkill_state=1
;;
*)
config_foreach wifi_rfkill_check wifi-device
;;
esac
config_foreach wifi_rfkill_set wifi-device
uci commit wireless
wifi up
return 0