Skip to content

Instantly share code, notes, and snippets.

@AzimsTech
Last active December 23, 2022 20:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AzimsTech/d04eec7f991f53ffe9431fbda1fe5663 to your computer and use it in GitHub Desktop.
Save AzimsTech/d04eec7f991f53ffe9431fbda1fe5663 to your computer and use it in GitHub Desktop.
[ OpenWrt ] Restart Wifi by WPS button

Instructions

  1. Installing Hotplug Buttons

    opkg update
    opkg install kmod-button-hotplug
    
    mkdir -p /etc/hotplug.d/button
  2. Create WPS button handler

    cat << "EOF" > /etc/hotplug.d/button/00-button
    source /lib/functions.sh
    
    do_button () {
        local button
        local action
        local handler
        local min
        local max
    
        config_get button "${1}" button
        config_get action "${1}" action
        config_get handler "${1}" handler
        config_get min "${1}" min
        config_get max "${1}" max
    
        [ "${ACTION}" = "${action}" -a "${BUTTON}" = "${button}" -a -n "${handler}" ] && {
            [ -z "${min}" -o -z "${max}" ] && eval ${handler}
            [ -n "${min}" -a -n "${max}" ] && {
                [ "${min}" -le "${SEEN}" -a "${max}" -ge "${SEEN}" ] && eval ${handler}
            }
        }
    }
    
    config_load system
    config_foreach do_button button
    EOF
    
    uci add system button
    uci set system.@button[-1].button="wps"
    uci set system.@button[-1].action="pressed"
    uci set system.@button[-1].handler="ifup wwan && wifi up"
    uci commit system 
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment