Wan-to-Lan via Script driven by BTN-Switch (GL-MT300N-V2 fw3.216)

I would like to set up my MT300N-V2 so that when I change the switch on the side of the router the WAN port changes to a LAN port and changing the switch back would revert the setting. I am not sure I am going about this the correct way. When I execute my scripts manually, I see a change in luci but not the same change as when making the selection under the web interface. I thought I saw a post by alzhao that listed the changes but I can no longer find the post.

Can anyone shed some light on what happens when changing Wan to Lan in the Web interface? Should the web interface reflect the change made by the script?

So far I have created three scripts , one for wan-lan, one for lan-wan and one to listen to GPIO0 and launch one of the other scripts. See below:

#Change WAN port to LAN
uci set network.wan.ifname=‘eth0.1’
uci commit network
/etc/init.d/network restart

#Change LAN port to WAN
uci set network.wan.ifname=‘eth0’
uci commit network
/etc/init.d/network restart

while true; do
SWITCH_STATE=$(cat /sys/class/gpio/gpio0/value)
if [ “$SWITCH_STATE” -eq 0 ]; then
# Run wan_to_lan.sh when switch is low (towards WAN)
# Run lan_to_wan.sh when switch is high (towards LAN)
sleep 1

If anyone can help that would be greatly appreciated.
Thank You,

I’ve made my own version of port switching but with hotplugging and map switch status to button events.

It works for me. Hope this can help you.