ZPMMaker
Posts: 42
Joined: Sun Aug 23, 2015 11:04 am
Location: Australia

Running two WiFi adapters on the one Pi

Thu Aug 10, 2017 3:23 am

Howdy,

I'm using a Raspberry Pi Zero Wireless. I need to connect to a camera (which uses an ad hoc wifi network) in order to send the camera commands, and then transfer images from the camera onto the RPi. I then need to connect to a second WiFi network in order to connect to the Internet (so that the image can be uploaded to a server).

I was planning on using the Zero W's internal WiFi adapter to connect to the camera (as it'll be close by) and a USB WiFi adapter with an external aerial to connect to the local WiFi for internet access (as the WiFi router for internet access will be much further away).

An alternative may be to use only the Pi's internal WiFi adapter, and somehow programmatically switch the connection from camera to internet wifi and vice versa as required.

Either way, I have no idea how to do either of these things.

I tried following some websites that explained how to alter the wpa_supplicant.conf or /etc/network/interfaces files, but I ended up just bricking the Pi completely (i.e. after rebooting, it would claim "no wireless interfaces found" - I resolved this by simply reinstalling Raspbian from the disk image).

Unfortunately, there is no other way of connecting to this camera - it's WiFi or not all. Which is a real pain.

So, could someone please explain, either:

A) How to use two WiFi adapters to connect to two separate WiFi networks simultaneously, and how to force a specific adapter to only connect to a specific network (and prevent it from connecting to other networks), or

B) How to programmatically switch one WiFi adapter between networks (preferably in Bash)?


I'd prefer option A, as that would mean the Pi would always be connected to the internet (the Pi and camera system are going to be installed in remote locations and the Pi will be headless, so it's important that it always has internet access so I can SSH into it using Remot3.it if something stuffs up).

Thanks in advance!
Dave

P.S.: I'm not using a Raspberry Pi camera module. This is a third-party camera.

coltreign
Posts: 2
Joined: Thu Aug 10, 2017 5:33 pm

Re: Running two WiFi adapters on the one Pi

Thu Aug 10, 2017 5:53 pm

I don't have experience with the specific application you're referring to, but I've connected to two networks simultaneously using a TP-Link TL-WN821N via USB in addition to the native wifi card or ethernet. You should be able to configure your connections manually via command line. Check out this link https://www.thepolyglotdeveloper.com/20 ... pberry-pi/. As far as programatically switching between networks, I'd consider looking into something like a python script to get that done effectively.

ZPMMaker
Posts: 42
Joined: Sun Aug 23, 2015 11:04 am
Location: Australia

Re: Running two WiFi adapters on the one Pi

Sat Aug 12, 2017 9:11 am

Thanks, but that link is for setting up connections to two separate WiFi networks in case the RPi is moved (e.g. a mobile set-up going from home WiFi to work WiFi). I need to know how to bind them to a specific adapter, and having both adapters connected to their respective WiFi networks, simultaneously.

User avatar
elkberry
Posts: 167
Joined: Wed Dec 28, 2016 9:21 pm

Re: Running two WiFi adapters on the one Pi

Sat Aug 12, 2017 1:36 pm

As you need to/can specify a wpa config file with each network interface, I would imagine that you can use different wpa configuration files for different interfaces, as the parameter to wpa-conf in /etc/network/interfaces. That should allow connecting your two wlan interfaces to different networks. However, I haven't tested that myself, it's just an idea that came to me when reading the question.
From ZX81 to Raspberry Pi, but wait ... where's the 7805 gone?

ZPMMaker
Posts: 42
Joined: Sun Aug 23, 2015 11:04 am
Location: Australia

Re: Running two WiFi adapters on the one Pi

Sun Aug 13, 2017 4:17 am

elkberry wrote:
Sat Aug 12, 2017 1:36 pm
you can use different wpa configuration files for different interfaces, as the parameter to wpa-conf in /etc/network/interfaces.
Yes, that's possible, but after rebooting, I find that both adapters only connect to my internet WiFi network, rather than connecting to the two different networks (i.e. I end up with two simultaneous connections to the Internet WiFi, and the camera WiFi is ignored). So I effectively need a way of saying "wlan0 can only connect to X network, and should never connect to any other network" and "wlan1 can only connect to Y network, and should never connect to any other network".

User avatar
elkberry
Posts: 167
Joined: Wed Dec 28, 2016 9:21 pm

Re: Running two WiFi adapters on the one Pi

Sun Aug 13, 2017 6:52 am

I'm under the impression that you did misunderstood me. I'm not talking about swapping wpa conf files, but using two simultaneously. At the same time, one for wlan0, another for wlan1. As in:

Code: Select all

iface wlan0 inet auto
  wpa-conf /etc/wpa_supplicant/wpa_supplicant_wlan0.conf
 
 iface wlan1 inet auto
  wpa-conf /etc/wpa_supplicant/wpa_supplicant_wlan1.conf
From ZX81 to Raspberry Pi, but wait ... where's the 7805 gone?

ZPMMaker
Posts: 42
Joined: Sun Aug 23, 2015 11:04 am
Location: Australia

Re: Running two WiFi adapters on the one Pi

Sun Aug 13, 2017 9:18 am

elkberry wrote:
Sun Aug 13, 2017 6:52 am
I'm under the impression that you did misunderstood me. I'm not talking about swapping wpa conf files, but using two simultaneously. At the same time, one for wlan0, another for wlan1. As in:

Code: Select all

iface wlan0 inet auto
  wpa-conf /etc/wpa_supplicant/wpa_supplicant_wlan0.conf
 
 iface wlan1 inet auto
  wpa-conf /etc/wpa_supplicant/wpa_supplicant_wlan1.conf
Yes, I had misunderstood. Thanks for clarifying!
I have just tested your idea out and it works perfectly!

Thank you very much for your help. :D

User avatar
elkberry
Posts: 167
Joined: Wed Dec 28, 2016 9:21 pm

Re: Running two WiFi adapters on the one Pi

Sun Aug 13, 2017 11:39 am

Glad to hear that it works. You're welcome!
From ZX81 to Raspberry Pi, but wait ... where's the 7805 gone?

ZPMMaker
Posts: 42
Joined: Sun Aug 23, 2015 11:04 am
Location: Australia

Re: Running two WiFi adapters on the one Pi

Sun Aug 20, 2017 11:20 am

Hello, I'm back...

It turns out I need to have the camera on wlan0 and the internet WiFi on wlan1.

Unfortunately, when I switch the .conf files over, both adapters connect to the correct WiFi networks, but - for some reason - it can't access the Internet via wlan1 (and trying to SSH into the RPi from another computer on the same network that wlan1 is on also doesn't work - it just times out).

I have no idea what the cause of this may be...

Any suggestions please on how to either diagnose or fix the issue?

Thanks,
David

SurferTim
Posts: 875
Joined: Sat Sep 14, 2013 9:27 am
Location: Miramar Beach, Florida

Re: Running two WiFi adapters on the one Pi

Sun Aug 20, 2017 2:47 pm

Post the result of "route". The lowest metric will be used for the gateway. You can set the metric in /etc/dhcpcd.conf.

Code: Select all

interface wlan0
metric 300

interface wlan1
metric 200
The alternative is don't use a gateway on wlan0 in the RPi.

ZPMMaker
Posts: 42
Joined: Sun Aug 23, 2015 11:04 am
Location: Australia

Re: Running two WiFi adapters on the one Pi

Mon Aug 21, 2017 8:47 am

SurferTim wrote:
Sun Aug 20, 2017 2:47 pm
Post the result of "route". The lowest metric will be used for the gateway. You can set the metric in /etc/dhcpcd.conf.

Code: Select all

interface wlan0
metric 300

interface wlan1
metric 200
The alternative is don't use a gateway on wlan0 in the RPi.
Howdy, thanks for being willing to help me. :)
Here's a screenshot showing the results of the route command.
Image

Honestly, I have no idea what any of it means, though.
Could you please clarify... do I just copy this:

Code: Select all

interface wlan0
metric 300

interface wlan1
metric 200
into anywhere in /etc/dhcpcd.conf?

Thanks for your help. :)

SurferTim
Posts: 875
Joined: Sat Sep 14, 2013 9:27 am
Location: Miramar Beach, Florida

Re: Running two WiFi adapters on the one Pi

Mon Aug 21, 2017 12:01 pm

You are going to have a routing problem there. It appears that wlan0 and wlan1 have the same localnet. How are these interfaces getting their network settings?

ZPMMaker
Posts: 42
Joined: Sun Aug 23, 2015 11:04 am
Location: Australia

Re: Running two WiFi adapters on the one Pi

Mon Aug 21, 2017 1:15 pm

SurferTim wrote:
Mon Aug 21, 2017 12:01 pm
You are going to have a routing problem there. It appears that wlan0 and wlan1 have the same localnet. How are these interfaces getting their network settings?
Basically, I just plugged in the USB wifi adapter, and then in the wifi connection thingy in the upper right corner of the Raspbian GUI, I connected each WiFi adapter to their respective networks.

I then also created local.conf and camera.conf to replace the wpa_supplicant.conf file, and then referenced the two .conf files in /network/interfaces, as per the above.

That's all I've done so far.

SurferTim
Posts: 875
Joined: Sat Sep 14, 2013 9:27 am
Location: Miramar Beach, Florida

Re: Running two WiFi adapters on the one Pi

Mon Aug 21, 2017 1:41 pm

I don't see how you are going to do that. Your routing table must be able to determine which device is being used, and there is no easy way to determine that with duplicate localnets. Is there any way to change the localnet on one of the routers?

ZPMMaker
Posts: 42
Joined: Sun Aug 23, 2015 11:04 am
Location: Australia

Re: Running two WiFi adapters on the one Pi

Tue Aug 22, 2017 8:12 am

SurferTim wrote:
Mon Aug 21, 2017 1:41 pm
Is there any way to change the localnet on one of the routers?
Sadly, no.

ZPMMaker
Posts: 42
Joined: Sun Aug 23, 2015 11:04 am
Location: Australia

Re: Running two WiFi adapters on the one Pi

Tue Aug 22, 2017 10:08 am

Hmm, I may have an alternative solution: a 4G USB modem.
I'll test that tomorrow.

SurferTim
Posts: 875
Joined: Sat Sep 14, 2013 9:27 am
Location: Miramar Beach, Florida

Re: Running two WiFi adapters on the one Pi

Tue Aug 22, 2017 11:08 am

ZPMMaker wrote:
Tue Aug 22, 2017 10:08 am
Hmm, I may have an alternative solution: a 4G USB modem.
I'll test that tomorrow.
Hopefully, it won't use the 192.168.1.x localnet.

User avatar
DougieLawson
Posts: 29790
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website

Re: Running two WiFi adapters on the one Pi

Tue Aug 22, 2017 1:01 pm

SurferTim wrote:
Tue Aug 22, 2017 11:08 am
ZPMMaker wrote:
Tue Aug 22, 2017 10:08 am
Hmm, I may have an alternative solution: a 4G USB modem.
I'll test that tomorrow.
Hopefully, it won't use the 192.168.1.x localnet.
Eh?

192.168.xxx.yyy/24 is available for any usage as long as you are routing it locally and not onto the public internet. Just like 172.[16-31].xxx.yyy/16 and 10.www.xxx.yyyy/8.
Microprocessor, Raspberry Pi & Arduino Hacker
Mainframe database troubleshooter
MQTT Evangelist
Twitter: @DougieLawson

Since 2012: 1B*5, 2B*2, B+, A+, Zero*2, 3B*3

Please post ALL technical questions on the forum. Do not send private messages.

SurferTim
Posts: 875
Joined: Sat Sep 14, 2013 9:27 am
Location: Miramar Beach, Florida

Re: Running two WiFi adapters on the one Pi

Tue Aug 22, 2017 1:15 pm

Yes, Dougie, that is true. However, this user has two networks assigned 192.168.1.x, one on wlan0 and an identical subnet on wlan1. That is the routing problem. Apparently, the OP has no access to either router's setup to change one to a different localnet. If the modem has the same localnet (192.168.1.x) it will not solve the routing problem.

User avatar
DougieLawson
Posts: 29790
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website

Re: Running two WiFi adapters on the one Pi

Wed Aug 23, 2017 1:18 am

SurferTim wrote:
Tue Aug 22, 2017 1:15 pm
Yes, Dougie, that is true. However, this user has two networks assigned 192.168.1.x, one on wlan0 and an identical subnet on wlan1. That is the routing problem. Apparently, the OP has no access to either router's setup to change one to a different localnet. If the modem has the same localnet (192.168.1.x) it will not solve the routing problem.
That's not a routing problem if the two halves of 192.168.1.xxx don't overlap. Both interfaces will then be in the same subnet and it will "just work". The hard part happens when wlan0 is 192.168.1.xxx/24 and wlan1 is 192.168.2.xxx/24 - then the solution is to change the subnet mask from /24 (255.255.255.0) to /22 (255.255.252.0) to force the two networks to overlap.
Microprocessor, Raspberry Pi & Arduino Hacker
Mainframe database troubleshooter
MQTT Evangelist
Twitter: @DougieLawson

Since 2012: 1B*5, 2B*2, B+, A+, Zero*2, 3B*3

Please post ALL technical questions on the forum. Do not send private messages.

SurferTim
Posts: 875
Joined: Sat Sep 14, 2013 9:27 am
Location: Miramar Beach, Florida

Re: Running two WiFi adapters on the one Pi

Wed Aug 23, 2017 1:33 am

The OP has no access to change anything in the routers. This is the output of "route". They do overlap. Read the thread.
wlan0 192.168.1.0 255.255.255.0
wlan1 192.168.1.0 255.255.255.0

User avatar
DougieLawson
Posts: 29790
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website

Re: Running two WiFi adapters on the one Pi

Wed Aug 23, 2017 2:13 am

Then he/she is up a gum tree without a paddle. It'll be 100% impossible to get that working.
Microprocessor, Raspberry Pi & Arduino Hacker
Mainframe database troubleshooter
MQTT Evangelist
Twitter: @DougieLawson

Since 2012: 1B*5, 2B*2, B+, A+, Zero*2, 3B*3

Please post ALL technical questions on the forum. Do not send private messages.

ZPMMaker
Posts: 42
Joined: Sun Aug 23, 2015 11:04 am
Location: Australia

Re: Running two WiFi adapters on the one Pi

Wed Aug 23, 2017 2:19 am

Dang. OK.
Thanks.

Is there some (non-networky) alternative then?

I need to connect to the camera via WiFi to issue commands and retrieve photos.
I then need to send that photo to my AWS S3 account (hence the need for internet access).

Is there perhaps a way of having two RPi's (one connected to the camera via WiFi, and the other connected to the local WiFi for internet access), and transferring the images via e.g. a USB cable between the two so that the second RPi can upload it?

*scratches head*

User avatar
DougieLawson
Posts: 29790
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website

Re: Running two WiFi adapters on the one Pi

Wed Aug 23, 2017 2:24 am

Connect the Raspberry & camera to the same router/switch and allow DHCP to assign the IP addresses, that will avoid any IP address conflicts. The raspberry will be able to reach both the camera and the router with no problems.
Microprocessor, Raspberry Pi & Arduino Hacker
Mainframe database troubleshooter
MQTT Evangelist
Twitter: @DougieLawson

Since 2012: 1B*5, 2B*2, B+, A+, Zero*2, 3B*3

Please post ALL technical questions on the forum. Do not send private messages.

ZPMMaker
Posts: 42
Joined: Sun Aug 23, 2015 11:04 am
Location: Australia

Re: Running two WiFi adapters on the one Pi

Wed Aug 23, 2017 3:15 am

DougieLawson wrote:
Wed Aug 23, 2017 2:24 am
Connect the Raspberry & camera to the same router/switch and allow DHCP to assign the IP addresses, that will avoid any IP address conflicts. The raspberry will be able to reach both the camera and the router with no problems.
Sorry, I need to clarify; the camera creates an ad hoc network of its own. It can't connect to other WiFi networks.

Return to “Advanced users”

Who is online

Users browsing this forum: No registered users and 16 guests