What I need: Connect to different wifi network on archlinux by calling python script.
What I am doing: Executing the following statements from python:
wpa_passphrase "MySSID" "MyPass"> /etc/wpa_supplicant/profile.conf
wpa_supplicant -B -i wlan0 -c /etc/wpa_supplicant/profile.conf
dhcpd wlan0
It works only for the first attempt. When it is executed the second time, it says dhcpd is already on. I dont know how to switch to another network.
I have also tried wpa_cli and again, dont know how to switch to another network.
Please suggest some fix or alternatives (uncomplicated)
Your concrete Problem is that you start wpa_supplicant and dhcp instead of re-starting them. I have a script that reads
#shutdown dhc
dhclient -r
#shutdown wpa_supplicant
killall wpa_supplicant
#down interface
ifdown --force wlan0
sleep 1
#your wpa startup here:
wpa_supplicant -t -fYOUR_LOG_FILE -cYOUR_wpa_supplicant.conf -B -iwlan0
sleep 1
#restart dhc
dhclient -nw
I guess you can do this a little more nicely by configuring your /etc/network/interfaces appropriately.
Btw. in principle, it should not be necessary to restart the dhc at all. After some while it should realize that it needs to fetch a new IP, but for me this takes to long. ;)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With