From 039fbbb4c35cf58611a75e667e5d995840153ec0 Mon Sep 17 00:00:00 2001 From: olijf Date: Tue, 5 Apr 2016 14:24:29 +0200 Subject: [PATCH] Use WPS button to switch configs Added a functionality for the WPS button. (next to the leds) --- Makefile | 4 ++++ src/script/wifi-switch-netconfig.sh | 22 ++++++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100755 src/script/wifi-switch-netconfig.sh diff --git a/Makefile b/Makefile index abb567e..6d22833 100644 --- a/Makefile +++ b/Makefile @@ -101,6 +101,10 @@ define Package/wifibox/install #$(INSTALL_DIR) $(1)/www $(INSTALL_DIR) $(1)/www/cgi-bin + #copy wps button script to procd folder + $(INSTALL_DIR) $(1)/etc/rc.button/ + $(INSTALL_BIN) $(WIFIBOX_BASE_DIR)/script/wifi-switch-netconfig.sh $(1)/etc/rc.button/wps + ### create all files in /usr/share/lua/autowifi (autowifi) $(CP) $(WIFIBOX_BASE_DIR)/opkg.conf $(1)/$(TGT_LUA_DIR_SUFFIX)/ diff --git a/src/script/wifi-switch-netconfig.sh b/src/script/wifi-switch-netconfig.sh new file mode 100755 index 0000000..41ebc3a --- /dev/null +++ b/src/script/wifi-switch-netconfig.sh @@ -0,0 +1,22 @@ +#!/bin/sh + +[ "${ACTION}" = "released" ] || exit 0 + +. /lib/functions.sh + +logger "$BUTTON pressed for $SEEN seconds" +if [ "$SEEN" -lt 1 ] +then + #see https://github.com/Doodle3D/doodle3d-firmware/blob/master/src/network/wlanconfig.lua#L188 for reference + #check if network on top is enabled + uci get wireless.@wifi-iface[0].disabled + RESULT=$? + if [ $RESULT -eq 0 ] + then + uci set wireless.@wifi-iface[0].disabled=1 #disable current config + uci set wireless.@wifi-iface[1].disabled=0 #enable last used network + uci reorder wireless.@wifi-iface[0]=2 #reorder networks so last used config goes to the top again + uci commit wireless #commit changes + /etc/init.d/network reload #reload network module so changes become effective + fi +fi