1

I have a RPi0w configured as a router, DHCP client and AP at the same time, with the onboard wifi. The versión is:

pi@xxxx:~ $ uname -a
Linux xxxx 4.9.35+ #1014 Fri Jun 30 14:34:49 BST 2017 armv6l GNU/Linux

Everything works fine, but when the wifi connection to my home AP is lost for any reason the RPi0w wont automatically reconnect. I still can access the RPi0w thru its configured AP but I do not even know how to make the RPi0w to manually reconnect its wlan0 interface (other than reboot, obviously).

ifconfig when everything is working:

pi@xxxx:~ $ ifconfig
docker0   Link encap:Ethernet  HWaddr 02:42:05:2b:91:66  
          inet addr:172.17.0.1  Bcast:0.0.0.0  Mask:255.255.0.0
          inet6 addr: fe80::782e:2cef:e117:dece/64 Scope:Link
          UP BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:603 errors:0 dropped:0 overruns:0 frame:0
          TX packets:603 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1 
          RX bytes:39868 (38.9 KiB)  TX bytes:39868 (38.9 KiB)

tun0      Link encap:UNSPEC  HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-    00-00-00  
          inet addr:10.0.0.2  P-t-P:10.0.0.2  Mask:255.255.255.0
          inet6 addr: fe80::9640:d277:12f0:1a78/64 Scope:Link
          UP POINTOPOINT RUNNING NOARP MULTICAST  MTU:1500  Metric:1
          RX packets:218 errors:0 dropped:0 overruns:0 frame:0
          TX packets:301 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:500 
          RX bytes:13188 (12.8 KiB)  TX bytes:381150 (372.2 KiB)

uap0      Link encap:Ethernet  HWaddr b8:27:eb:32:6e:46  
          inet addr:192.168.30.1  Bcast:192.168.30.255  Mask:255.255.255.0
          inet6 addr: fe80::b7b4:ee3f:a98a:3d75/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:307 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:0 (0.0 B)  TX bytes:74635 (72.8 KiB)

wlan0     Link encap:Ethernet  HWaddr b8:27:eb:32:6e:46  
          inet addr:192.168.1.132  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fe80::2863:cc5d:7107:de1e/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:68034 errors:0 dropped:0 overruns:0 frame:0
          TX packets:51900 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:13343909 (12.7 MiB)  TX bytes:24668540 (23.5 MiB)

When the wlan0 disconnects I have tried to reconnect via all the suggested solutions I have found including:

1. Change from:

wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

to:

wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf

2.

sudo ifdown --force wlan0
sudo ifup wlan0

3.

sudo systemctl restart dhcpcd

4.

1.Go to /etc/ifplugd/action.d/ and rename the ifupdown file to ifupdown.original
2.Then do: cp /etc/wpa_supplicant/ifupdown.sh ./ifupdown
3.Finally: sudo reboot

5.

sudo killall -HUP wpa_supplicant

without success, wlan0 remains disconnected. Here I copy some relevant files:

/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 lo
auto uap0
iface lo inet loopback

iface eth0 inet manual

allow-hotplug wlan0
iface wlan0 inet manual
    wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf

iface uap0 inet manual

/etc/wpa_supplicant/wpa_supplicant.conf

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

network={
    ssid="MYHOMEROUTER"
    psk="psk1"
    key_mgmt=WPA-PSK
}

network={
    ssid="SSID2"
    psk="psk2"
        key_mgmt=WPA-PSK
}

network={
    ssid="SSID3"
    psk="psk3"
    key_mgmt=WPA-PSK
}

network={
    ssid="SSID4"
    psk="psk4"
    key_mgmt=WPA-PSK
}

/etc/dhcpcd.conf

# A sample configuration for dhcpcd.
# See dhcpcd.conf(5) for details.

# Allow users of this group to interact with dhcpcd via the control socket.
#controlgroup wheel

# Inform the DHCP server of our hostname for DDNS.
hostname

# Use the hardware address of the interface for the Client ID.
clientid
# or
# Use the same DUID + IAID as set in DHCPv6 for DHCPv4 ClientID as per RFC4361.
#duid

# Persist interface configuration when dhcpcd exits.
persistent

# Rapid commit support.
# Safe to enable by default because it requires the equivalent option set
# on the server to actually work.
option rapid_commit

# A list of options to request from the DHCP server.
option domain_name_servers, domain_name, domain_search, host_name
option classless_static_routes
# Most distributions have NTP support.
option ntp_servers
# Respect the network MTU.
# Some interface drivers reset when changing the MTU so disabled by default.
#option interface_mtu

# A ServerID is required by RFC2131.
require dhcp_server_identifier

# Generate Stable Private IPv6 Addresses instead of hardware based ones
slaac private

# A hook script is provided to lookup the hostname if not set by the DHCP
# server, but it should not be run by default.
nohook lookup-hostname

# Static IP configuration for uap0.
interface uap0
static ip_address=192.168.30.1/24
static routers=192.168.30.1
static domain_name_servers=8.8.4.4 8.8.8.8

/etc/dnsmasq.conf

interface=uap0
#no-dhcp-interface=lo
#no-dhcp-interface=wlan0 
#bind-interfaces 
no-resolv
server=8.8.8.8 
domain-needed 
bogus-priv 
dhcp-range=192.168.30.50,192.168.30.150,255.255.255.0,12h

/etc/hostapd/hostapd.conf

interface=uap0
ssid=Pi0w
hw_mode=g
channel=1
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=2
wpa_passphrase=thisisnotthepassphrase
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP

Any help about how to reconnect (ideally automatically thru conf files) would be highly appreciated. Please ask for any other relevant information I should provide.

Thanks.

Antonio

I have additional information now: The connection fails when my router changes channel. At boot, in rc.local, I write hostapd.conf on the fly in order to match the wlan0 channel and then I start hostapd. When the router changes its channel, uap0 is still up with the previous channel, for example 1, and wlan0 cannot reconnect with the new, different, channel, for example 6. Any ideas about how to reconnect via some script? Any help very much appreciated.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.