Jump to content

OPi Zero AP + Client mode (Solved)


Jaco Fourie

Recommended Posts

Hi all.

 

I followed this tutorial and I got the AP and client mode working. wlan0 using the onboard wifi as the AP and wlan1 using a usb dongle as the client connecting to my wifi network.

 

But when I connect to the PI and got an IP address via dnsmasq I am not able to get to the pi its self.

 

I can not access anything on the PI. I have a web server running on it. How do I get to the services on the Pi it self via the AP I created.

 

Basically what I want to do is have the client connect to the wifi network if there is one or if the pi is in range of the wifi network. But then if there is no network then I want to connect to the AP from my phone and still get to the web interface running on the Pi.

 

I am able to ping my iphone from the pi if I use wlan0 as the interface (the AP wifi adapter). So the AP part is working. I think I have a config issue someware.

 

Hope somebody can help me.

 

Link to comment
Share on other sites

Keep in mind, that wifi (XR819) on opi 0 is questionable, if you look through the H2/H3 subforum you'll see a lot of suport questions. 

xradio.jpg.1c69083744245eebd36492d86b12e4b3.jpg

Seems that @moebius and @Bubba were successful (connecting it to an AP not using it as AP), whereas others (including me) are running into trouble quite often. :P Since my use cases of the OPi0 hasn't anything to do with wifi, it doesn't matter. 

Using all these cheap wifi modules in AP mode is a second topic. Sometimes it works, sometimes not. But performance would always be 'not that exciting'. Usage as a 'IoT server' whereas some ESP8266 modules send their data to it should be possible but don't expect wifi-router like performance. :) If you can live with that keep on going. Otherwise, think about your needs first and then decide which hardware is capable to do the job.  Maybe a mPCIe capable board with a AR9380 3x3 MIMO wifi card fulfills your needs much better. Since I don't know your use case, I can't give you an answer to that. ;) 

Link to comment
Share on other sites

OK so here is my Interfaces file

 

auto lo
auto eth0
auto wlan0
auto wlan1

iface eth0 inet dhcp
iface lo inet loopback

allow-hotplug wlan0
allow-hotplug wlan1

iface wlan0 inet static
address 10.64.9.1
netmask 255.255.255.0
network 10.64.9.0

iface wlan1 inet static
address 10.64.9.77
netmask 255.255.255.0
network 10.64.9.0
broadcast 10.64.9.255
gateway 10.64.9.20
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf





 

Here is my /etc/hostapd.conf file

 

ssid=OPi
interface=wlan0
hw_mode=g
channel=7
#bridge=br0
driver=nl80211

logger_syslog=0
logger_syslog_level=0

wmm_enabled=1
ieee80211n=1
wpa=2
preamble=1

#wpa_psk=66eb31d2b48d19ba216f2e50c6831ee11be98e2fa3a8075e30b866f4a5ccda27
wpa_passphrase=12345678
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP
auth_algs=1
macaddr_acl=0

noscan=1

 

Here is my  /etc/dnsmasq.conf file

 

interface=wlan0
no-dhcp-interface=wlan1
bind-interfaces
server=8.8.8.8
domain-needed
bogus-priv
dhcp-range=10.64.9.150,10.64.9.200,12h

 

I can connect to the Pi AP and I get an IP. That all works fine.

 

But I can not get to the web page running on 10.64.9.77 or 10.64.9.1

 

I can ping from the Pi to the mobile devices if I use wlan0 as interface but not the other way around.

 

 

 

 

Link to comment
Share on other sites

3 hours ago, Igor said:

You can try to use this wizard - https://github.com/armbian/config - it should create everything for you. It's under active development and I still find some issues every day :) 

 

I tried that first but I could not get it to be both AP and Client at the same time. I could set-up a AP only or a client only. How do I set-up one wifi link as hotspot and the other as client with this tool as when I tried it it would say the wifi is in use it will remove it.

 

Link to comment
Share on other sites

First setup ap and than connect to wifi with another adapter ... it used to work for me even on 5 connections and one AP. I am still working on it and bugs are possible ...

Wrote on mobile

Link to comment
Share on other sites

I got some other questions now. Will play with it and let you know. So it seems I am missing the bridge part in my config if I look at what the tool is doing.

As I stated only one of the 2 wifi links will be active. If there is a wifi network then the pi will connect to it via the client link and the user will connect to the same wifi network and interact with the web interface.

If there is no wifi network then the user should be able to connect to the Pi AP and get an ip address. Then the user should be able to navigate to the same web page to interact with the web interface.

Link to comment
Share on other sites

2 minutes ago, martinayotte said:

Having 2 interfaces on the same subnet is kind of looking for troubles ...

Why ? I have been using multiple wifi connections for years. If the one fails the other takes its place.

But in this case I will have only one.

Please explain why you state that.

 

Regards.

Link to comment
Share on other sites

If you check the routes, you should have default gateway for each of your interfaces.

But several times, you will see that some of those default gateways are not present because they are duplicates of each others.

This means that if you connect to one interfaces, maybe responses packets will come back from another interface.

That why we say often in this forum, especially related to eth0/wlan0 same subnet conflicting each other, that if you are doing SSH on wlan0, and you are disconnecting eth0 cable, the SSH will freeze.

 

Link to comment
Share on other sites

I got it working to a point. I can have it in AP mode and have everything working from the Pi. Or I can have it in client mode. But not both at the same time.

Probably have to sort out some IP routing. But I am making progress. I don't need it to be both at the same time. I just want to see if I can get it to work that way.

Link to comment
Share on other sites

I got it working using this configuration. The wifi client and AP links will work 100% if the eth0 lan cable is plugged in. I can get to the 10.64.9.0 subnet from a mobile device connected to the AP. But as soon as I unplug the eth0 cable the client wifi link will be inaccessible. I can no longer get to 10.64.9.77 from the 10.64.9.0 subnet. but I can still get to it from the AP side

 

I dont need both to work at the same time. I ca use the cable for that while testing but if it works with the cable why does it not work with 2 wifi links ?

 

This statement seems to enable the fact that I can get to the Pi content without having to bridge the 2 adapters

iptables -t nat -A POSTROUTING -s 172.24.1.0/24 ! -d 172.24.1.0/24 -j MASQUERADE

 

Interfaces config file

 

auto lo
# bro
auto eth0
auto wlan0
auto wlan1

iface eth0 inet static
address 10.64.9.78
netmask 255.255.255.0
network 10.64.9.0
broadcast 10.64.9.255
gateway 10.64.9.20

iface lo inet loopback

allow-hotplug wlan0
allow-hotplug wlan1

allow-hotplug wlan0
iface wlan0 inet static

address 172.24.1.1
netmask 255.255.255.0
network 172.24.1.0
broadcast 172.24.1.255

iface wlan1 inet static
address 10.64.9.77
netmask 255.255.255.0
network 10.64.9.0
broadcast 10.64.9.255
gateway 10.64.9.20
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

/etc/dnsmasq.conf

interface=wlan0                         # Use interface wlan0
listen-address=172.24.1.1                                       # Explicitly specify the address to listen on
bind-interfaces                                                 # Bind to the interface to make sure we aren't sending      $
server=8.8.8.8                                                  # Forward DNS requests to Google DNS
domain-needed                                                           # Don't forward short names
bogus-priv                                                              # Never forward addresses in the non-routed address $
dhcp-range=172.24.1.50,172.24.1.150,12h # Assign IP addresses between 172.24.1.50 and 172.24.1.150 with                     $

 

 

Link to comment
Share on other sites

On 30/08/2017 at 3:30 PM, martinayotte said:

Having 2 interfaces on the same subnet is kind of looking for troubles ...

Dude you are 100% correct. I never knew this. You are not allowed to have the interfaces on the same subnet. What I did was replace the static ip of eth0 to dhcp and left the cable unplugged and then the wifi came up and now all is working 100%. Thank you for the help .

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
×
×
  • Create New...

Important Information

Terms of Use - Privacy Policy - Guidelines