Dual wifi ?1 home 2 work

Hiya Is it possible to have a the same pi connect to different networks at different locations?
I would like it to be able to connect to the work wifi while I’m at work, and my home network when I’m home, I have all the passwords and router acess point names.
I’m just not sure about how to do it

Thanks

I think you add the work one to the wpa_supplicant.conf file (assuming you already have the home one on there)

sudo nano /etc/wpa_supplicant/wpa_supplicant.conf

This will bring up the following, just enter the relevant details, (the home one should already be in there) and fingers crossed it will pick up the work one when you boot it up.

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=GB

network={
ssid=“MyHomeNetwork”
psk=“MyHomePassword”
key_mgmt=WPA-PSK
}

network={
ssid=“MyWorkNetwork”
psk=“MyWorkPassword”
}

1 Like

In theory I think @Steve_Lambert is right but PiMuiscbox keeps the file at /etc/wpa.conf and it also rewrites the file on every boot so you’ll lose your changes. The easiest thing would be to put the suggested contents in /etc/wpa.conf but then edit /opt/musicbox/startup.sh and comment/delete the section that rewrites the file. You would want to keep the part that brings the interface up though.

1 Like

Apologies, I didn’t read that it was PiMusicbox, thanks Nick, nice new picture BTW, takes years off you!!.

Haha thanks! The other one wasn’t doing me any favours but I’m stuck with it on my badge at work. Probably forever.

Ok having a look at startup.sh I can’t see a section that rewrites the WPA.conf or at least it isn’t obvious to me. ? Sorry .

Edit can’t get it :frowning:

Apologies for delay, kept missing a fi and couldn’t understand why it wouldn’t work.
It works now for me, but I only have 1 network specified, you’ll have to try both when set up.
Make sure and backup the sd card before starting, if it fails it won’t connect to wifi at all and you will need to rewrite the card - which I have done numerous times
Hope it works for you - good luck

Log in via SSH using root and musicbox
sudo nano /opt/musicbox/startup.sh

Scroll down to the line “if [ “$INI__network__wifi_network” != “” ]”
Delete or # everything between the first line and the #enable wifi line there is also a fi at the very end that I missed loads of times so make sure and delete that as well.


if [ “$INI__network__wifi_network” != “” ]
then
#put wifi settings for wpa roaming
#
# If wifi_country is set then include a country=XX line
if [ “$INI__network__wifi_country” != “” ]
then
WIFICOUNTRY=“country=$INI__network__wifi_country”
else
WIFICOUNTRY=""
fi
if [ “INI__network__wifi_password" != "" ] then password_length={#INI__network__wifi_password}
if [ $password_length -gt 63 ]
then
PSK=”$INI__network__wifi_password"
else
PSK=""$INI__network__wifi_password""
fi
cat >/etc/wpa.conf <<EOF
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
$WIFICOUNTRY
network={
ssid="$INI__network__wifi_network"
psk=$PSK
scan_ssid=1
}
EOF
else
#if no password is given, set key_mgmt to NONE
cat >/etc/wpa.conf <<EOF
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
$WIFICOUNTRY
network={
ssid="$INI__network__wifi_network"
key_mgmt=NONE
scan_ssid=1
}
EOF
fi


#enable wifi
ifdown wlan0		Remove # from this line
ifup wlan0

/etc/init.d/networking restart

fi Delete this line

ctrl x to save and exit.

Next
Open /etc/wpa.conf

sudo nano /etc/wpa.conf - it should show your network details.
Copy and paste underneath, then fill in correct names etc.
ctrl x to save and exit


        ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
        update_config=1

        network={
            ssid="myhomenetworks"
            psk="myhomepassword"
            scan_ssid=1
        }

        network={
            ssid="myworknetworks"
            psk="myworkpassword"
            scan_ssid=1
        }

Reboot and fingers crossed.
If you can hook up to hdmi to check progress as it reboots it’s easier to spot any errors.

Make sure and backup the sd card before starting, if it fails it won’t connect to wifi at all and you will need to rewrite the card

1 Like

Thank you I just noticed this reply sorry, I’ll try this asap thank you again. I’ll try to remember to report back.