0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

OpenWrt ボタン(スイッチ)

0
Last updated at Posted at 2023-08-12

:flag_jp: Japanese notation

OpenWrt_icon.png

はじめに

記事について

ボタン(スイッチ)のOpenWrt初期設定・運用ガイドです
インストールから各種設定、チューニングなどをまとめています

初心者対応構成

デバイスアクセス

PowerShellの開始

  • パワーシェル起動:キー入力:Win+x > a > はい
  • コンソールログイン (パワーシェル)
    ※192.168.1.1以外の場合、以下の形式で入力後にワンライナーを入力下さい
$ip="192.168.*.*"
  • コンソールログイン (192.168.1.1用)
    万能型ワンライナー
if(!$ip){$ip="192.168.1.1"}; ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=NUL -o GlobalKnownHostsFile=NUL -o HostKeyAlgorithms=+ssh-rsa -tt root@$ip

ボタン(スイッチ)

ボタン(スイッチ)

インストール

#! /bin/sh

# install
PATTERN="kmod-button-hotplug"
command -v opkg && opkg update && opkg install $PATTERN
command -v apk  && apk update  && apk add $PATTERN
mkdir -p /etc/hotplug.d/button
# log調査用
cat << "EOF" > /etc/hotplug.d/button/buttons
logger "the button was ${BUTTON} and the action was ${ACTION}"
EOF
# 00-button
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

reboot

該当ボタン確認

ls /etc/rc.button/

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

該当ボタンをプッシュ&リリースしてから以下を実行

logread | tail -n 1  | grep button | awk '{ print $11 }'

WiFI ON OFF & リブート

設定ボタン及びスイッチ:AOSSボタン=wps
設定デバイス:BUFFALO WSR-6000AX8

# WiFi ON ワンプッシュボタンリリース
BUTTON='wps' # AOSS BUTTON
uci add system button
uci set system.@button[-1].button=${BUTTON}
uci set system.@button[-1].action="released"
uci set system.@button[-1].handler="uci set wireless.radio0.disabled=0; uci set wireless.radio1.disabled=0; uci commit; wifi"
uci set system.@button[-1].min="0"
uci set system.@button[-1].max="2"
# WiFi OFF 5秒ボタンリリース
uci add system button
uci set system.@button[-1].button=${BUTTON}
uci set system.@button[-1].action="released"
uci set system.@button[-1].handler="uci set wireless.radio0.disabled=1; uci set wireless.radio1.disabled=1; uci commit; wifi"
uci set system.@button[-1].min="3"
uci set system.@button[-1].max="7"
# restart 10秒ボタンリリース
uci add system button
uci set system.@button[-1].button=${BUTTON}
uci set system.@button[-1].action="released"
uci set system.@button[-1].handler="sleep 70 && touch /etc/banner && reboot"
uci set system.@button[-1].min="8"
uci set system.@button[-1].max="15"
# set
uci commit system
/etc/init.d/system reload

遠隔地リモート設定

対話型だから無理じゃんねw

設定ボタン及びスイッチ:AOSSボタン=wps
設定デバイス:BUFFALO WSR-6000AX8
環境設定:セレクター型インターネット全自動接続設定 / デバイス初期設定
設定方法:デバイス初期設定をする

# internet-config
wget --no-check-certificate -O /usr/sbin/internet-config.sh https://raw.githubusercontent.com/site-u2023/config-softwire/main/internet-config.sh
# 遠隔地WAN設定 5秒ボタンリリース 
BUTTON='wps' # AOSS BUTTON
uci add system button
uci set system.@button[-1].button=${BUTTON}
uci set system.@button[-1].action="released"
uci set system.@button[-1].handler="sh /usr/sbin/internet-config.sh"
uci set system.@button[-1].min="3"
uci set system.@button[-1].max="8"
# set
uci commit system
/etc/init.d/system reload

ルーターモードとブリッジモード

検証中~

設定ボタン及びスイッチ:背面スイッチ=BTN_2
設定デバイス:BUFFALO WSR-6000AX8
環境設定:OCNバーチャルコネクト / Dumb アクセスポイント ブリッジ
設定方法:一度OCNバーチャルコネクトを設定し、次にDumb アクセスポイント ブリッジで設定しnetwork.bakを出力させる(自動)
※要DHCPサーバー接続:Dumb アクセスポイント ブリッジ設定

# スイッチ切替5秒後設定変更及び再起動
# OCNバーチャルコネクト設定
BUTTON='router' # SWITCH AUTO
uci add system button
uci set system.@button[-1].button=${BUTTON}
uci set system.@button[-1].action="released"
uci set system.@button[-1].handler="cp /etc/config/network.dump.bak /etc/config/network; uci commit; sleep 70 && touch /etc/banner && reboot"
uci set system.@button[-1].min="5"
uci set system.@button[-1].max="10"
# Dumb アクセスポイント ブリッジ設定
BUTTON='router' # SWITCH MANUAL
uci add system button
uci set system.@button[-1].button=${BUTTON}
uci set system.@button[-1].action="pressed"
uci set system.@button[-1].handler="cp /etc/config/network /etc/config/network.dump.bak; uci commit; sleep 70 && touch /etc/banner && reboot"
uci set system.@button[-1].min="5"
uci set system.@button[-1].max="10"
# set
uci commit system
/etc/init.d/system reload

フラッシュ&インストールシステム

aios.png

あとがき

参考資料(感謝:relaxed:

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?