I am unable to configure a RPi3 as both a client and AP. My goal was to connect to the AP using an Android and pickup internet access via the Client mode if it was configured. I can provide internet access as the direction seems to be from the Android to the AP but as soon as I try to do something from the AP to the Android (such as WebSockets or SSE or even ping) then packet loss makes it unusable.
I can access the pi via eth0, wlan0 and connect my android via ap0 but I am seeing massive packet loss when pinging from the pi via the ap to the android. Pings from / to any other direction have zero packet loss. I know this topic has been discussed thoroughly on several threads but I have been unable to get this going reliably.
If I ifdown wlan0 the pings via the ap are 100%, as soon as I ifup wlan0 the packet loss is enormous.
It is as though the RPi3 cannot act as both a client and an AP.
Apologies for the long post, I was trying to include relevant configuration information.
android - IP: 192.168.0.14
wifi Network router: 192.168.1.254
wlan0 - IP: 192.168.1.149
ap0 - IP: 192.168.0.1
pi@raspberrypi:~ $ ping 192.168.0.14 -I ap0
PING 192.168.0.14 (192.168.0.14) from 192.168.0.1 ap0: 56(84) bytes of data.
64 bytes from 192.168.0.14: icmp_seq=18 ttl=64 time=11.8 ms
64 bytes from 192.168.0.14: icmp_seq=37 ttl=64 time=2.40 ms
........
64 bytes from 192.168.0.14: icmp_seq=49 ttl=64 time=9.81 ms
64 bytes from 192.168.0.14: icmp_seq=52 ttl=64 time=1.29 ms
--- 192.168.0.14 ping statistics ---
53 packets transmitted, 11 received, 79% packet loss, time 53814ms
rtt min/avg/max/mdev = 1.295/4.543/11.834/3.283 ms
pi@raspberrypi:~ $
Using a ping tool from my android to the pi @ 192.168.0.1 I am seeing times of 8.3ms - 38.7ms.
If I Ping a workstation on the same network as the wlan0 wifi ...
pi@raspberrypi:~ $ ping 192.168.1.103 -I wlan0
PING 192.168.1.103 (192.168.1.103) 56(84) bytes of data.
64 bytes from 192.168.1.103: icmp_seq=1 ttl=128 time=3.01 ms
64 bytes from 192.168.1.103: icmp_seq=2 ttl=128 time=5.69 ms
.......
64 bytes from 192.168.1.103: icmp_seq=6 ttl=128 time=2.91 ms
64 bytes from 192.168.1.103: icmp_seq=7 ttl=128 time=2.18 ms
--- 192.168.1.103 ping statistics ---
7 packets transmitted, 7 received, 0% packet loss, time 6008ms
rtt min/avg/max/mdev = 2.186/4.188/6.597/1.697 ms
pi@raspberrypi:~ $
Ping times from a lan workstation to the pi on wlan0 ...
C:\Users\User>ping 192.168.1.149
Pinging 192.168.1.149 with 32 bytes of data:
Reply from 192.168.1.149: bytes=32 time=6ms TTL=64
Reply from 192.168.1.149: bytes=32 time=6ms TTL=64
Reply from 192.168.1.149: bytes=32 time=5ms TTL=64
Reply from 192.168.1.149: bytes=32 time=2ms TTL=64
Ping statistics for 192.168.1.149:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 2ms, Maximum = 6ms, Average = 4ms
C:\Users\User>
So, I can ping between the Client wifi both ways without issue or loss of packets.
I can ping from the android device to the ap (the tool I use does not report lost packets but there are no delays and the times look ok).
When I ping from the ap to the android connected via the ap I get massive lost packets.
after entering ifdown wlan0 then enter pi@raspberrypi:~ $ ping 192.168.0.14 -I ap0
packet loss goes to zero and the ping times are 87ms to 368ms.
configuration files....
****************************************************************************
pi@raspberrypi:~ $ cat /etc/network/interfaces
#
# interfaces(5) file used by ifup(8) and ifdown(8)
# Please note that this file is written to be used with dhcpcd
# For static IP, consult /etc/dhcpcd.conf and 'man dhcpcd.conf'
# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d
auto eth0
iface eth0 inet dhcp
allow-hotplug wlan0
iface wlan0 inet dhcp
pre-up ifup ap0
pre-up sleep 2
pre-up wpa_supplicant -c /etc/wpa_supplicant/client.conf -i wlan0 -B
post-down killall wpa_supplicant
allow-hotplug ap0
iface ap0 inet static
pre-up iw phy phy0 interface add ap0 type __ap
address 192.168.0.1
netmask 255.255.255.0
post-down iw dev ap0 del
wpa-ssid "RPi3"
wpa-psk "raspberry"
pi@raspberrypi:~ $
****************************************************************************
pi@raspberrypi:~ $ cat /etc/hostapd/hostapd.conf
interface=ap0
driver=nl80211
hw_mode=g
channel=6
macaddr_acl=0
auth_algs=1
wpa=2
ignore_broadcast_ssid=0
wpa_key_mgmt=WPA-PSK
#wpa_pairwise=CCMP
rsn_pairwise=CCMP
wpa_passphrase=raspberry
ssid=RPi3
ieee80211n=1
wmm_enabled=0
ht_capab=[HT40][SHORT-GI-20][DSSS_CCK-40]
pi@raspberrypi:~ $
****************************************************************************
pi@raspberrypi:~ $ cat /etc/dnsmasq.conf
#log-facility=/var/log/dnsmasq.log
#log-dhcp
expand-hosts
interface=ap0
local=/home/
domain=home
bind-interfaces
domain-needed
bogus-priv
listen-address=192.168.0.1
dhcp-authoritative
dhcp-option=3,192.168.0.1
dhcp-range=192.168.0.10,192.168.0.25,255.255.255.0,12h
dhcp-option=option:router,192.168.0.1
server=192.168.0.1
server=8.8.8.8
pi@raspberrypi:~ $
****************************************************************************
pi@raspberrypi:~ $ cat /etc/wpa_supplicant/client.conf
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=US
network={
ssid="Network-ssid"
psk="Network-password"
}
pi@raspberrypi:~ $
****************************************************************************
pi@raspberrypi:~ $ cat /etc/rc.local
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
# Print the IP address
#driver issues require a restart of the wireless
sleep 1
ifdown wlan0
sleep 1
ifup wlan0
#start the node webserver
#node /var/www/server.js
_IP=$(hostname -I) || true
if [ "$_IP" ]; then
printf "My IP address is %s\n" "$_IP"
fi
exit 0
pi@raspberrypi:~ $
Routing info....
****************************************************************************
pi@raspberrypi:~ $ ip route show table all
default via 192.168.1.254 dev wlan0
192.168.0.0/24 dev ap0 proto kernel scope link src 192.168.0.1
192.168.1.0/24 dev wlan0 proto kernel scope link src 192.168.1.149
broadcast 127.0.0.0 dev lo table local proto kernel scope link src 127.0.0.1
local 127.0.0.0/8 dev lo table local proto kernel scope host src 127.0.0.1
local 127.0.0.1 dev lo table local proto kernel scope host src 127.0.0.1
broadcast 127.255.255.255 dev lo table local proto kernel scope link src 127.0.0.1
broadcast 192.168.0.0 dev ap0 table local proto kernel scope link src 192.168.0.1
local 192.168.0.1 dev ap0 table local proto kernel scope host src 192.168.0.1
broadcast 192.168.0.255 dev ap0 table local proto kernel scope link src 192.168.0.1
broadcast 192.168.1.0 dev wlan0 table local proto kernel scope link src 192.168.1.149
local 192.168.1.149 dev wlan0 table local proto kernel scope host src 192.168.1.149
broadcast 192.168.1.255 dev wlan0 table local proto kernel scope link src 192.168.1.149
2600:1700:bfc2:6cb0::/64 dev wlan0 proto kernel metric 256 expires 1209115sec pref medium
fe80::/64 dev ap0 proto kernel metric 256 pref medium
fe80::/64 dev wlan0 proto kernel metric 256 pref medium
default via fe80::d604:cdff:fe52:8c10 dev wlan0 proto ra metric 1024 expires 1315sec hoplimit 64 pref medium
unreachable default dev lo proto kernel metric 4294967295 error -101 pref medium
local ::1 dev lo table local proto none metric 0 pref medium
local 2600:1700:bfc2:6cb0:ba27:ebff:feef:2cd2 dev lo table local proto none metric 0 pref medium
local fe80::ba27:ebff:feef:2cd2 dev lo table local proto none metric 0 pref medium
local fe80::ba27:ebff:feef:2cd2 dev lo table local proto none metric 0 pref medium
ff00::/8 dev ap0 table local metric 256 pref medium
ff00::/8 dev wlan0 table local metric 256 pref medium
unreachable default dev lo proto kernel metric 4294967295 error -101 pref medium
pi@raspberrypi:~ $
version info....
****************************************************************************
pi@raspberrypi:~ $ uname -a
Linux raspberrypi 4.9.59-v7+ #1047 SMP Sun Oct 29 12:19:23 GMT 2017 armv7l GNU/Linux
****************************************************************************
pi@raspberrypi:~ $ cat /etc/os-release
PRETTY_NAME="Raspbian GNU/Linux 9 (stretch)"
NAME="Raspbian GNU/Linux"
VERSION_ID="9"
VERSION="9 (stretch)"
ID=raspbian
ID_LIKE=debian
HOME_URL="http://www.raspbian.org/"
SUPPORT_URL="http://www.raspbian.org/RaspbianForums"
BUG_REPORT_URL="http://www.raspbian.org/RaspbianBugs"
pi@raspberrypi:~ $
****************************************************************************
pi@raspberrypi:~ $ cat /etc/rpi-issue
Raspberry Pi reference 2017-11-29
Generated using pi-gen, https://github.com/RPi-Distro/pi-gen, b71bf3179310aadf9aaf2ffcdf094a88e488dce8, stage5
pi@raspberrypi:~ $
****************************************************************************
If you have any tips / hints or observe any obvious problems some direction would be appreciated.
I am not an expert but I do know enough to get myself in serous trouble and I think perhaps I did.