Possible to connect to other AP via script without reboot?

Post new topic   Reply to topic    DD-WRT Forum Index -> General Questions
Author Message
chromoxdor
DD-WRT Novice


Joined: 02 Dec 2014
Posts: 44

PostPosted: Thu Nov 16, 2023 10:01    Post subject: Possible to connect to other AP via script without reboot? Reply with quote
Hi all,

i use my TP-Link ARCHER-C7 v2 in Station mode to connect wirelessly to another Router.
Sometimes i have to change to another Router since the first one becomes unavailable...
I do this via a script:
Code:
#!/bin/sh

if [ "$(nvram get wlan1_ssid)" == "Router1" ]; then
 echo "changing to Router 2"
 nvram set wlan1_ssid="Router2" && nvram set wlan1_wpa_psk="********" && nvram commit

else
 echo "changing to Router 1"
 nvram set wlan1_ssid="Router1" && nvram set wlan1_wpa_psk="********" && nvram commit

fi

echo "reboot"
reboot


My question:
(I searched in the forum for a while and i couldn´t find a working solution for this)
Is it possible to achieve the change without restarting the whole router?
(Like changing it in the WebUI and hitting "Apply Settings")
If so how? Could somebody provide me with a sample script or point me in the right direction?

Bonus question:
Could anybody get the WPS-Button to work?
I enabled it in /Services to turn of WiFi off but nothing happens. (I also tried to enable it in /Management as well but no luck)


Connection scheme:
TP-Link ---- (Station: 5Ghz wlan1) ------- Router or Router 2
|
└ AP (2.4Ghz wlan0)
|
└ VAP (5Ghz wlan1.1)

_________________
DD-WRTiles - List clients in tile layout
Sponsor
mwchang
DD-WRT Guru


Joined: 26 Mar 2013
Posts: 1858
Location: Hung Hom, Hong Kong

PostPosted: Thu Nov 16, 2023 14:59    Post subject: Re: Possible to connect to other AP via script without reboo Reply with quote
chromoxdor wrote:
Is it possible to achieve the change without restarting the whole router?
(Like changing it in the WebUI and hitting "Apply Settings")
If so how? Could somebody provide me with a sample script or point me in the right direction?

It's possible. Try these steps:
Code:
wl radio off
service nas stop
service wlconf stop
nvram set ....
nvram commit
wl -i $(nvram get wl0_ifname) ssid newname
service wlconf start
service nas start
wl radio on

("nas" is Network Authenaticaion Service, not about storage.)

Related:

DD-WRT :: View topic - VAP SSID do not broadcast after reboot
https://forum.dd-wrt.com/phpBB2/viewtopic.php?p=1139119

DD-WRT :: View topic - Set SSID by software
https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=83755

_________________
Router: Asus RT-N18U (rev. A1)

Drink, Blink, Stretch! Live long and prosper! May the Force and farces be with you!

Facebook: https://www.facebook.com/changmanwai
Website: https://sites.google.com/site/changmw
SETI@Home profile: http://setiathome.berkeley.edu/view_profile.php?userid=211832
GitHub: https://github.com/changmw/changmw
dale_gribble39
DD-WRT Guru


Joined: 11 Jun 2022
Posts: 1958

PostPosted: Thu Nov 16, 2023 17:12    Post subject: Reply with quote
The Archer C7 v2 is Atheros, not Broadcom. Those steps will not work.
_________________
"The woods are lovely, dark and deep,
But I have promises to keep,
And miles to go before I sleep,
And miles to go before I sleep." - Robert Frost

"I am one of the noticeable ones - notice me" - Dale Frances McKenzie Bozzio

<fact>code knows no gender</fact>

This is me, knowing I've ruffled your feathers, and not giving a ****
Some people are still hard-headed.

--------------------------------------
Mac Pro (Mid 2012) - Two 2.4GHz 6-Core Intel Xeon E5645 processors 64GB 1333MHz DDR3 ECC SDRAM OpenSUSE Leap 15.5
chromoxdor
DD-WRT Novice


Joined: 02 Dec 2014
Posts: 44

PostPosted: Thu Nov 16, 2023 19:34    Post subject: Reply with quote
I already tried once the commands of this a script posted here:
https://forum.dd-wrt.com/phpBB2/viewtopic.php?p=1083400#1083400

Code:
# IF WIRELESS IS IN CLIENT MODE TURN OFF
if [ "$IFMODE" = "sta" ] && [ "$WIFITOGGLE" = "1" ]; then
 if [ $(ps | grep wpa_supplicant | cut -c27-40 | grep -v grep) = wpa_supplicant ]; then
  stopservice wland >/dev/null 2>&1
  killall wpa_supplicant
  killall hostapd
  mv /tmp/wifi_cron_switch_wifi_on /tmp/wifi_cron_switch_wifi_off  >/dev/null 2>&1
 fi
fi

# IF WIRELESS IS IN CLIENT MODE TURN ON
if [ "$IFMODE" = "sta" ] && [ "$WIFITOGGLE" = "2" ]; then
 if [ "$(ps | grep wpa_supplicant | cut -c27-40 | grep -v grep)" != "wpa_supplicant" ]; then
  stopservice lan
  startservice lan
  WIRELESSIEE=`cat /tmp/wifi_cron_switch_wpa_supplicant`
  WPASUPPLICANTSTART="wpa_supplicant -B -$WIRELESSIEE -i$IFNAME -c /tmp/$IFNAME\_wpa_supplicant.conf"
  $WPASUPPLICANTSTART >/dev/null 2>&1
  sleep 10
  killall udhcpc
  UDHCPCSTART="udhcpc -i $IFNAME -p /var/run/udhcpc.pid -s /tmp/udhcpc -O routes -O msstaticroutes -O staticroutes"
  $UDHCPCSTART >/dev/null 2>&1
  mv /tmp/wifi_cron_switch_wifi_off /tmp/wifi_cron_switch_wifi_on >/dev/null 2>&1
 fi
fi


So I set the new ssid and then i call all the commands found in the script above.
After that the wireless-status page shows wlan1 as active with the new ssid but it doesn´t connect to the new AP...It does get connected (see EDIT)


What I entered in the terminal:
1:
Code:
nvram set wlan1_ssid="Router2" && nvram set wlan1_wpa_psk="*******" && nvram commit

2:
Quote:
stopservice wland >/dev/null 2>&1 && killall wpa_supplicant && killall hostapd && stopservice lan && startservice lan && wpa_supplicant -P /var/run/wlan1_wpa_supplicant.pid -B -Dnl80211 -iwlan1 -c /tmp/iwlan1\_wpa_supplicant.conf && sleep 10 && killall udhcpc && udhcpc -i wlan1 -p /var/run/udhcpc.pid -s /tmp/udhcpc -O routes -O msstaticroutes -O staticroutes



EDIT:
Removed screenshot because i made a mistake... It does get connected to the AP but it doesn´t not get a WAN IP

New screenshot:



Bildschirmfoto 2023-11-16 um 20.50.58.png
 Description:
 Filesize:  205.67 KB
 Viewed:  2610 Time(s)

Bildschirmfoto 2023-11-16 um 20.50.58.png



_________________
DD-WRTiles - List clients in tile layout
dale_gribble39
DD-WRT Guru


Joined: 11 Jun 2022
Posts: 1958

PostPosted: Thu Nov 16, 2023 22:05    Post subject: Reply with quote
Over-configuration of wifi station interface, mixed encryption, etc. Suggest "Mixed" and WPA2-PSK with AES... station modes do not require a ton of configuration to be done to work.
_________________
"The woods are lovely, dark and deep,
But I have promises to keep,
And miles to go before I sleep,
And miles to go before I sleep." - Robert Frost

"I am one of the noticeable ones - notice me" - Dale Frances McKenzie Bozzio

<fact>code knows no gender</fact>

This is me, knowing I've ruffled your feathers, and not giving a ****
Some people are still hard-headed.

--------------------------------------
Mac Pro (Mid 2012) - Two 2.4GHz 6-Core Intel Xeon E5645 processors 64GB 1333MHz DDR3 ECC SDRAM OpenSUSE Leap 15.5
chromoxdor
DD-WRT Novice


Joined: 02 Dec 2014
Posts: 44

PostPosted: Thu Nov 16, 2023 22:20    Post subject: Reply with quote
I appreciate your help. Thank you!
But how does this help me with my problem?

_________________
DD-WRTiles - List clients in tile layout
mwchang
DD-WRT Guru


Joined: 26 Mar 2013
Posts: 1858
Location: Hung Hom, Hong Kong

PostPosted: Fri Nov 17, 2023 13:55    Post subject: Reply with quote
dale_gribble39 wrote:
The Archer C7 v2 is Atheros, not Broadcom. Those steps will not work.

My apology then!!

I believe Atheros chips is more open-sourced and might allow standard Linux wifi commands. So... may still worth a try. Smile

(edit: Google keywords "dd-wrt archer ssid" got nothing. Well.. sorry then!)

_________________
Router: Asus RT-N18U (rev. A1)

Drink, Blink, Stretch! Live long and prosper! May the Force and farces be with you!

Facebook: https://www.facebook.com/changmanwai
Website: https://sites.google.com/site/changmw
SETI@Home profile: http://setiathome.berkeley.edu/view_profile.php?userid=211832
GitHub: https://github.com/changmw/changmw
chromoxdor
DD-WRT Novice


Joined: 02 Dec 2014
Posts: 44

PostPosted: Fri Dec 15, 2023 9:59    Post subject: Reply with quote
I would like to bump this topic in the hope somebody will stumble upon this and is able to help... Smile
_________________
DD-WRTiles - List clients in tile layout
Display posts from previous:    Page 1 of 1
Post new topic   Reply to topic    DD-WRT Forum Index -> General Questions All times are GMT

Navigation

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum