Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added code to change wifi channel (WLAN_2G) #33

Closed
saiballo opened this issue Feb 27, 2023 · 2 comments
Closed

Added code to change wifi channel (WLAN_2G) #33

saiballo opened this issue Feb 27, 2023 · 2 comments

Comments

@saiballo
Copy link

Hello,

I like your script, very useful. great job!

I add some code lines to change wifi channel.

if [ "$option2" = "1" ]; then WLANstate "ON";
elif [ "$option2" = "0" ]; then WLANstate "OFF";
elif [ "$option2" = "STATE" ]; then WLANstate "STATE";

becames:

if [ "$option2" = "1" ]; then WLANstate "ON";
elif [ "$option2" = "0" ]; then WLANstate "OFF";
elif [ "$option2" = "STATE" ]; then WLANstate "STATE";
elif [ "$option2" = "CHANGECH" ]; then WLANstate "CHANGECH";

then after:

action='GetInfo'
		if [ "$option2" = "STATE" ]; then
			curlOutput1=$(curl -s -k -m 5 --anyauth -u "$BoxUSER:$BoxPW" "http://$BoxIP:49000$location" -H 'Content-Type: text/xml; charset="utf-8"' -H "SoapAction:$uri#$action" -d "<?xml version='1.0' encoding='utf-8'?><s:Envelope s:encodingStyle='http://schemas.xmlsoap.org/soap/encoding/' xmlns:s='http://schemas.xmlsoap.org/soap/envelope/'><s:Body><u:$action xmlns:u='$uri'></u:$action></s:Body></s:Envelope>" | grep NewEnable | awk -F">" '{print $2}' | awk -F"<" '{print $1}')
			curlOutput2=$(curl -s -k -m 5 --anyauth -u "$BoxUSER:$BoxPW" "http://$BoxIP:49000$location" -H 'Content-Type: text/xml; charset="utf-8"' -H "SoapAction:$uri#$action" -d "<?xml version='1.0' encoding='utf-8'?><s:Envelope s:encodingStyle='http://schemas.xmlsoap.org/soap/encoding/' xmlns:s='http://schemas.xmlsoap.org/soap/envelope/'><s:Body><u:$action xmlns:u='$uri'></u:$action></s:Body></s:Envelope>" | grep NewSSID | awk -F">" '{print $2}' | awk -F"<" '{print $1}')
			echo "2,4 Ghz Network $curlOutput2 is $curlOutput1"
		fi

add this:

action='SetChannel'
if [ "$option2" = "CHANGECH" ]; then
  rand=("1" "3" "6" "9" "11") 
  NEW_CH=$( shuf -e ${rand[@]} -n1 )
  echo "change channel"; curl -k -m 5 --anyauth -u "$BoxUSER:$BoxPW" "http://$BoxIP:49000$location" -H 'Content-Type: text/xml; charset="utf-8"' -H "SoapAction:$uri#$action" -d "<?xml version='1.0' encoding='utf-8'?><s:Envelope s:encodingStyle='http://schemas.xmlsoap.org/soap/encoding/' xmlns:s='http://schemas.xmlsoap.org/soap/envelope/'><s:Body><u:$action xmlns:u='$uri'><NewChannel>$NEW_CH</NewChannel></u:$action></s:Body></s:Envelope>" -s > /dev/null;
            echo "WIFI Channel changed to $NEW_CH"
fi

I needed only 5 channels. Of course "rand" array can be simple a random number in range or something similar to

$(( ( RANDOM % 10 ) + 1 ))

@jhubig
Copy link
Owner

jhubig commented Apr 16, 2023

Hello @saiballo,

thanks. Implemented your function in the latest commit. Added all the other channels for 2.4 Ghz and also the possibility to change for 5Ghz network. Thanks for the idea. I will close the issue. Happy to see your new ideas 👍

See d54fd93

Cheers,
Johannes

@jhubig jhubig closed this as completed Apr 16, 2023
@saiballo
Copy link
Author

saiballo commented Apr 16, 2023

glad to have been helpful!

thank you Johannes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants