0
0
mirror of https://github.com/Doodle3D/doodle3d-firmware.git synced 2024-12-22 11:03:48 +01:00

Changed logic

Now instead of rotinging through all wifi configs the button just removes all other configs and only leaves the doodle3d AP
This commit is contained in:
olijf 2016-04-08 14:47:06 +02:00
parent 52650da0fe
commit a8bdd5c188

View File

@ -4,24 +4,43 @@
. /lib/functions.sh . /lib/functions.sh
handle_interface() { count_networks() {
local config="$1" local config="$1"
logger $config logger $config
count=$((count + 1)) count=$((count + 1))
# run commands for every interface section # run commands for every interface section
}
find_network() {
local config="$1"
succes=false
#logger $(uci get wireless.$config.ssid)
network_name=$(uci get wireless.$config.ssid)
if [ ${network_name:0:8} != "Doodle3D" ]
then
logger "deleting network $network_name"
uci delete wireless.$config
else
$succes=true
logger "enabled $network_name"
uci set wireless.$config.disabled=0
fi
} }
logger "$BUTTON pressed for $SEEN seconds" logger "$BUTTON pressed for $SEEN seconds"
if [ "$SEEN" -lt 1 ] if [ "$SEEN" -gt 4 ]
then then
#see https://github.com/Doodle3D/doodle3d-firmware/blob/master/src/network/wlanconfig.lua#L188 for reference #count number of networks
#check if network on top is in STA mode config_load wireless
if [ $(uci get wireless.@wifi-iface[1].mode) == "ap" ] config_foreach count_networks wifi-iface
logger $count
#if number of networks is less than 1 (or 1) do nothing
if [ $count -gt 1 ]
then then
logger "switching to AP $(uci get wireless.@wifi-iface[1].ssid)" logger "switching to AP"
if [ $(uci get wireless.@wifi-iface[1].network) != "wlan" ] #edge case when only the factory default openwrt network is available config_foreach find_network wifi-iface
if [ $succes != false ]
then then
uci set wireless.@wifi-iface[1].network=wlan logger "wireless somehow not found"
fi fi
#configure dhcp #configure dhcp
uci delete network.wlan uci delete network.wlan
@ -36,35 +55,9 @@ then
uci set dhcp.wlan.limit=150 uci set dhcp.wlan.limit=150
uci set dhcp.wlan.interface=wlan uci set dhcp.wlan.interface=wlan
uci set wireless.@wifi-iface[0].disabled=1 #disable current config
uci set wireless.@wifi-iface[1].disabled=0 #enable last used network
config_load wireless
config_foreach handle_interface wifi-iface
logger $count
uci reorder wireless.@wifi-iface[0]=$count #reorder networks so last used config goes to the top again
uci commit #commit changes uci commit #commit changes
/etc/init.d/network reload #reload network module so changes become effective /etc/init.d/network reload #reload network module so changes become effective
logger "setting status flag in /tmp/networkstatus.txt" logger "setting status flag in /tmp/networkstatus.txt"
echo "4|" > /tmp/networkstatus.txt echo "4|" > /tmp/networkstatus.txt
else
logger "switching to STA $(uci get wireless.@wifi-iface[1].ssid)"
uci set wireless.@wifi-iface[0].disabled=1 #disable current config
uci set wireless.@wifi-iface[1].disabled=0 #enable last used network
config_load wireless
config_foreach handle_interface wifi-iface
logger $count
uci reorder wireless.@wifi-iface[0]=$count #reorder networks so last used config goes to the top again
uci delete network.wlan
uci set network.wlan=interface
uci set network.wlan.proto=dhcp
uci delete dhcp.wlan
uci commit #commit changes
/etc/init.d/network reload #reload network module so changes become effective
echo "2|" > /tmp/networkstatus.txt
fi fi
fi fi