Wifi won't auto reconnect

Having issues with your DietPi installation, or, found a bug? Post it here.
Post Reply
jptaranto
Posts: 6
Joined: Thu Oct 10, 2019 11:33 am

Wifi won't auto reconnect

Post by jptaranto »

I've attempted to troubleshoot this one by myself for some time but I haven't turned up anything.

My wifi drops out routinely as the Pi is near a microwave - I've tried changing bands and what not, but it seems the drop outs are something I need to deal with. This - until now - hasn't been a problem as the dietpi-wifi-monitor script always reconnected without issue.

After updating my Pi to the latest version of DietPi, the wifi auto reconnect script has stopped working and I can't figure out why.

I'm using a Edimax USB adapter as so:

Code: Select all

dietpi@KitchenPi:~$ lsusb
Bus 001 Device 004: ID 7392:7811 Edimax Technology Co., Ltd EW-7811Un 802.11n Wireless Adapter [Realtek RTL8188CUS]
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp. SMSC9512/9514 Fast Ethernet Adapter
Bus 001 Device 002: ID 0424:9514 Standard Microsystems Corp. SMC9514 Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
The script is running fine:

Code: Select all

dietpi@KitchenPi:~$ service dietpi-wifi-monitor status
● dietpi-wifi-monitor.service - DietPi-WiFi-Monitor
   Loaded: loaded (/etc/systemd/system/dietpi-wifi-monitor.service; enabled; vendor preset: enabled)
   Active: active (running) since Thu 2019-10-10 20:05:49 AEDT; 32min ago
  Process: 764 ExecStartPre=/bin/dash -c [ -e /sys/class/net/wlan$(sed -n 2p /DietPi/dietpi/.network) ] (code=exited, status=0/SUCCESS)
  Process: 751 ExecStartPre=/DietPi/dietpi/func/obtain_network_details (code=exited, status=0/SUCCESS)
 Main PID: 769 (dietpi-wifi-mon)
    Tasks: 2 (limit: 4915)
   CGroup: /system.slice/dietpi-wifi-monitor.service
           ├─ 769 /bin/bash /var/lib/dietpi/services/dietpi-wifi-monitor.sh
           └─2351 sleep 10

Oct 10 20:05:49 KitchenPi systemd[1]: Starting DietPi-WiFi-Monitor...
Oct 10 20:05:49 KitchenPi systemd[1]: Started DietPi-WiFi-Monitor.
Oct 10 20:05:49 KitchenPi dietpi-wifi-monitor.sh[769]: Checking connnection for: wlan0 via ping to default gateway every 10 seconds
And the connection works fine when the Pi first boots:

Code: Select all

dietpi@KitchenPi:~$ iwconfig
eth0      no wireless extensions.

lo        no wireless extensions.

wlan0     IEEE 802.11bgn  ESSID:"Black Cockatoo"  Nickname:"<WIFI@REALTEK>"
          Mode:Managed  Frequency:2.437 GHz  Access Point: F0:9F:C2:FD:8B:24   
          Bit Rate:72.2 Mb/s   Sensitivity:0/0  
          Retry:off   RTS thr:off   Fragment thr:off
          Power Management:off
          Link Quality=100/100  Signal level=82/100  Noise level=0/100
          Rx invalid nwid:0  Rx invalid crypt:0  Rx invalid frag:0
          Tx excessive retries:0  Invalid misc:0   Missed beacon:0
I've enabled logging and once the connection drops there are endless lines related to it trying to reconnect:

Code: Select all

wpa_supplicant[6518]: wlan0: Trying to associate with f0:9f:c2:fd:8b:24 (SSID='Black Cockatoo' freq=2437 MHz)
Oct 10 01:25:26 KitchenPi wpa_supplicant[6518]: wlan0: Association request to the driver failed
Oct 10 01:25:27 KitchenPi dhclient[6547]: DHCPDISCOVER on wlan0 to 255.255.255.255 port 67 interval 5
Oct 10 01:25:32 KitchenPi dietpi-wifi-monitor.sh[775]: Detected connection loss: wlan0. Reconnecting...
Oct 10 01:25:32 KitchenPi dhclient[6613]: Killed old client process
Oct 10 01:25:32 KitchenPi dietpi-wifi-monitor.sh[775]: Killed old client process
Oct 10 01:25:33 KitchenPi dhclient[6613]: Internet Systems Consortium DHCP Client 4.3.5
Oct 10 01:25:33 KitchenPi dietpi-wifi-monitor.sh[775]: Internet Systems Consortium DHCP Client 4.3.5
Oct 10 01:25:33 KitchenPi dietpi-wifi-monitor.sh[775]: Copyright 2004-2016 Internet Systems Consortium.
Oct 10 01:25:33 KitchenPi dietpi-wifi-monitor.sh[775]: All rights reserved.
Oct 10 01:25:33 KitchenPi dietpi-wifi-monitor.sh[775]: For info, please visit https://www.isc.org/software/dhcp/
Oct 10 01:25:33 KitchenPi dhclient[6613]: Copyright 2004-2016 Internet Systems Consortium.
Oct 10 01:25:33 KitchenPi dhclient[6613]: All rights reserved.
Oct 10 01:25:33 KitchenPi dhclient[6613]: For info, please visit https://www.isc.org/software/dhcp/
Oct 10 01:25:33 KitchenPi dhclient[6613]: 
Oct 10 01:25:33 KitchenPi dhclient[6613]: Listening on LPF/wlan0/74:da:38:ea:05:03
Oct 10 01:25:33 KitchenPi dhclient[6613]: Sending on   LPF/wlan0/74:da:38:ea:05:03
Oct 10 01:25:33 KitchenPi dietpi-wifi-monitor.sh[775]: Listening on LPF/wlan0/74:da:38:ea:05:03
Oct 10 01:25:33 KitchenPi dietpi-wifi-monitor.sh[775]: Sending on   LPF/wlan0/74:da:38:ea:05:03
Oct 10 01:25:33 KitchenPi dietpi-wifi-monitor.sh[775]: Sending on   Socket/fallback
Oct 10 01:25:33 KitchenPi dhclient[6613]: Sending on   Socket/fallback
Oct 10 01:25:33 KitchenPi dhclient[6613]: DHCPRELEASE on wlan0 to 192.168.1.1 port 67
Oct 10 01:25:33 KitchenPi dhclient[6613]: send_packet: Network is unreachable
Oct 10 01:25:33 KitchenPi dietpi-wifi-monitor.sh[775]: DHCPRELEASE on wlan0 to 192.168.1.1 port 67
Oct 10 01:25:33 KitchenPi dietpi-wifi-monitor.sh[775]: send_packet: Network is unreachable
Oct 10 01:25:33 KitchenPi dietpi-wifi-monitor.sh[775]: send_packet: please consult README file regarding broadcast address.
Oct 10 01:25:33 KitchenPi dietpi-wifi-monitor.sh[775]: dhclient.c:2733: Failed to send 300 byte long packet over fallback interface.
Oct 10 01:25:33 KitchenPi dhclient[6613]: send_packet: please consult README file regarding broadcast address.
Oct 10 01:25:33 KitchenPi dhclient[6613]: dhclient.c:2733: Failed to send 300 byte long packet over fallback interface.
Oct 10 01:25:34 KitchenPi wpa_supplicant[6518]: nl80211: deinit ifname=wlan0 disabled_11b_rates=0
Oct 10 01:25:34 KitchenPi wpa_supplicant[6518]: wlan0: CTRL-EVENT-TERMINATING
Oct 10 01:25:35 KitchenPi wpa_supplicant[6654]: Successfully initialized wpa_supplicant
Oct 10 01:25:35 KitchenPi kernel: [380699.855570] IPv6: ADDRCONF(NETDEV_UP): wlan0: link is not ready
Oct 10 01:25:35 KitchenPi dhclient[6659]: Internet Systems Consortium DHCP Client 4.3.5
Oct 10 01:25:35 KitchenPi dietpi-wifi-monitor.sh[775]: Internet Systems Consortium DHCP Client 4.3.5
Oct 10 01:25:35 KitchenPi dhclient[6659]: Copyright 2004-2016 Internet Systems Consortium.
Oct 10 01:25:35 KitchenPi dietpi-wifi-monitor.sh[775]: Copyright 2004-2016 Internet Systems Consortium.
Oct 10 01:25:35 KitchenPi dhclient[6659]: All rights reserved.
Oct 10 01:25:35 KitchenPi dietpi-wifi-monitor.sh[775]: All rights reserved.
Oct 10 01:25:35 KitchenPi dhclient[6659]: For info, please visit https://www.isc.org/software/dhcp/
Oct 10 01:25:35 KitchenPi dietpi-wifi-monitor.sh[775]: For info, please visit https://www.isc.org/software/dhcp/
Oct 10 01:25:35 KitchenPi dhclient[6659]: 
Oct 10 01:25:35 KitchenPi dhclient[6659]: Listening on LPF/wlan0/74:da:38:ea:05:03
Oct 10 01:25:35 KitchenPi dietpi-wifi-monitor.sh[775]: Listening on LPF/wlan0/74:da:38:ea:05:03
Oct 10 01:25:35 KitchenPi dhclient[6659]: Sending on   LPF/wlan0/74:da:38:ea:05:03
Oct 10 01:25:35 KitchenPi dietpi-wifi-monitor.sh[775]: Sending on   LPF/wlan0/74:da:38:ea:05:03
Oct 10 01:25:35 KitchenPi dhclient[6659]: Sending on   Socket/fallback
Oct 10 01:25:35 KitchenPi dietpi-wifi-monitor.sh[775]: Sending on   Socket/fallback
Oct 10 01:25:35 KitchenPi dhclient[6659]: DHCPDISCOVER on wlan0 to 255.255.255.255 port 67 interval 5
Oct 10 01:25:35 KitchenPi dietpi-wifi-monitor.sh[775]: DHCPDISCOVER on wlan0 to 255.255.255.255 port 67 interval 5
Oct 10 01:25:36 KitchenPi wpa_supplicant[6655]: wlan0: Trying to associate with f0:9f:c2:fd:8b:24 (SSID='Black Cockatoo' freq=2437 MHz)
Oct 10 01:25:36 KitchenPi wpa_supplicant[6655]: wlan0: Association request to the driver failed
Oct 10 01:25:38 KitchenPi wpa_supplicant[6655]: wlan0: Trying to associate with f0:9f:c2:fd:8b:24 (SSID='Black Cockatoo' freq=2437 MHz)
Oct 10 01:25:38 KitchenPi wpa_supplicant[6655]: wlan0: Association request to the driver failed
Oct 10 01:25:40 KitchenPi wpa_supplicant[6655]: wlan0: Trying to associate with f0:9f:c2:fd:8b:24 (SSID='Black Cockatoo' freq=2437 MHz)
Oct 10 01:25:40 KitchenPi wpa_supplicant[6655]: wlan0: Association request to the driver failed
Oct 10 01:25:40 KitchenPi dhclient[6659]: DHCPDISCOVER on wlan0 to 255.255.255.255 port 67 interval 6
Oct 10 01:25:40 KitchenPi dietpi-wifi-monitor.sh[775]: DHCPDISCOVER on wlan0 to 255.255.255.255 port 67 interval 6
Oct 10 01:25:42 KitchenPi wpa_supplicant[6655]: wlan0: Trying to associate with f0:9f:c2:fd:8b:24 (SSID='Black Cockatoo' freq=2437 MHz)
Oct 10 01:25:42 KitchenPi wpa_supplicant[6655]: wlan0: Association request to the driver failed
Oct 10 01:25:46 KitchenPi dhclient[6659]: No DHCPOFFERS received.
Oct 10 01:25:46 KitchenPi dietpi-wifi-monitor.sh[775]: No DHCPOFFERS received.
Oct 10 01:25:46 KitchenPi dietpi-wifi-monitor.sh[775]: No working leases in persistent database - sleeping.
Oct 10 01:25:46 KitchenPi dhclient[6659]: No working leases in persistent database - sleeping.
Oct 10 01:25:46 KitchenPi dietpi-wifi-monitor.sh[775]: Completed
And on it goes!

Seems like there is an issue getting a new DHCP lease via the reconnect script.

If I reboot the Pi the wifi comes back on immediately.
jptaranto
Posts: 6
Joined: Thu Oct 10, 2019 11:33 am

Re: Wifi won't auto reconnect

Post by jptaranto »

Oh and here is my network config:

Code: Select all

dietpi@KitchenPi:~$ cat /etc/network/interfaces
# Location: /etc/network/interfaces
# Please modify network settings via: dietpi-config
# Or create your own drop-ins in: /etc/network/interfaces.d/

# Drop-in configs
source interfaces.d/*

# Local
auto lo
iface lo inet loopback

# Ethernet
#allow-hotplug eth0
iface eth0 inet dhcp
address 0.0.0.0
netmask 0.0.0.0
gateway 0.0.0.0
#dns-nameservers 0.0.0.0

# WiFi
allow-hotplug wlan0
iface wlan0 inet dhcp
address 192.168.1.44
netmask 255.255.255.0
gateway 192.168.1.1
#dns-nameservers 192.168.1.1
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
User avatar
MichaIng
Site Admin
Posts: 2294
Joined: Sat Nov 18, 2017 6:21 pm

Re: Wifi won't auto reconnect

Post by MichaIng »

@jptaranto
Many thanks for your report.

We need to suppress the ifdown/ifup output it seems. This doubles with dhclient and wpa_supplicant process outputs and confuses. However yeah dhclient failes to receive an IP. Could you please try:

Code: Select all

systemctl disable --now dietpi-wifi-monitor
ifdown wlan0
sleep 10
ifup wlan0
Probably the 1 second time, we give in the script between ifdown and ifup, is not enough in your case.

What you can try as well, is to use a static IP and configure a static lease in your router? In most cases this works just well and reduces the overhead of regular DHCP leases and dhclient background process.
jptaranto
Posts: 6
Joined: Thu Oct 10, 2019 11:33 am

Re: Wifi won't auto reconnect

Post by jptaranto »

Thanks for the reply @MichaIng!

I've switched over to a static IP now. I'll see if that helps anything and then try the commands you posted.
muki
Posts: 5
Joined: Sat Apr 07, 2018 9:57 pm

Re: Wifi won't auto reconnect

Post by muki »

This thread saved my day! \o/
jptaranto
Posts: 6
Joined: Thu Oct 10, 2019 11:33 am

Re: Wifi won't auto reconnect

Post by jptaranto »

The static IP made no difference, so I've updated the script at

Code: Select all

/var/lib/dietpi/services/dietpi-wifi-monitor.sh
with

Code: Select all

ifdown $ADAPTER
sleep 10
ifup $ADAPTER
User avatar
MichaIng
Site Admin
Posts: 2294
Joined: Sat Nov 18, 2017 6:21 pm

Re: Wifi won't auto reconnect

Post by MichaIng »

@jptaranto
Okay and the sleep 10 indeed solved the issue? Then we need to increase that in our upstream script as well. If you find time, could you try if 2 seconds are enough as well? Raising from 1 to 10 for all would IMO lead to a too long WiFi downtime.
jptaranto
Posts: 6
Joined: Thu Oct 10, 2019 11:33 am

Re: Wifi won't auto reconnect

Post by jptaranto »

Hey @MichaIng, I'm afraid it hasn't fixed it... but the logs are a little clearer now.

Code: Select all

Nov 15 06:20:55 KitchenPi wpa_supplicant[30154]: wlan0: Trying to associate with f0:9f:c2:fd:8b:24 (SSID='Black Cockatoo' freq=2412 MHz)
Nov 15 06:20:55 KitchenPi wpa_supplicant[30154]: wlan0: Association request to the driver failed
Nov 15 06:21:07 KitchenPi wpa_supplicant[30154]: wlan0: Trying to associate with f0:9f:c2:fd:8b:24 (SSID='Black Cockatoo' freq=2412 MHz)
Nov 15 06:21:07 KitchenPi wpa_supplicant[30154]: wlan0: Association request to the driver failed
Nov 15 06:21:09 KitchenPi dietpi-wifi-monitor.sh[706]: Detected connection loss: wlan0. Reconnecting...
Nov 15 06:21:09 KitchenPi avahi-daemon[770]: Withdrawing address record for 192.168.1.44 on wlan0.
Nov 15 06:21:09 KitchenPi avahi-daemon[770]: Leaving mDNS multicast group on interface wlan0.IPv4 with address 192.168.1.44.
Nov 15 06:21:09 KitchenPi avahi-daemon[770]: Interface wlan0.IPv4 no longer relevant for mDNS.
Nov 15 06:21:10 KitchenPi wpa_supplicant[30154]: nl80211: deinit ifname=wlan0 disabled_11b_rates=0
Nov 15 06:21:10 KitchenPi wpa_supplicant[30154]: wlan0: CTRL-EVENT-TERMINATING
Nov 15 06:21:20 KitchenPi wpa_supplicant[30323]: Successfully initialized wpa_supplicant
Nov 15 06:21:20 KitchenPi kernel: [165035.503378] IPv6: ADDRCONF(NETDEV_UP): wlan0: link is not ready
Nov 15 06:21:20 KitchenPi avahi-daemon[770]: Joining mDNS multicast group on interface wlan0.IPv4 with address 192.168.1.44.
Nov 15 06:21:20 KitchenPi avahi-daemon[770]: New relevant interface wlan0.IPv4 for mDNS.
Nov 15 06:21:20 KitchenPi avahi-daemon[770]: Registering new address record for 192.168.1.44 on wlan0.IPv4.
Nov 15 06:21:22 KitchenPi wpa_supplicant[30324]: wlan0: Trying to associate with f0:9f:c2:fd:8b:24 (SSID='Black Cockatoo' freq=2412 MHz)
Nov 15 06:21:22 KitchenPi wpa_supplicant[30324]: wlan0: Association request to the driver failed
Nov 15 06:21:24 KitchenPi wpa_supplicant[30324]: wlan0: Trying to associate with f0:9f:c2:fd:8b:24 (SSID='Black Cockatoo' freq=2412 MHz)
Nov 15 06:21:24 KitchenPi wpa_supplicant[30324]: wlan0: Association request to the driver failed
Nov 15 06:21:25 KitchenPi wpa_supplicant[30324]: wlan0: Trying to associate with f0:9f:c2:fd:8b:24 (SSID='Black Cockatoo' freq=2412 MHz)
Nov 15 06:21:25 KitchenPi wpa_supplicant[30324]: wlan0: Association request to the driver failed
Nov 15 06:21:28 KitchenPi wpa_supplicant[30324]: wlan0: Trying to associate with f0:9f:c2:fd:8b:24 (SSID='Black Cockatoo' freq=2412 MHz)
Nov 15 06:21:28 KitchenPi wpa_supplicant[30324]: wlan0: Association request to the driver failed
Nov 15 06:21:35 KitchenPi wpa_supplicant[30324]: wlan0: Trying to associate with f0:9f:c2:fd:8b:24 (SSID='Black Cockatoo' freq=2412 MHz)
Nov 15 06:21:35 KitchenPi wpa_supplicant[30324]: wlan0: Association request to the driver failed
Nov 15 06:21:41 KitchenPi dietpi-wifi-monitor.sh[706]: Completed
I'm looking up this error message and it seems to be common with some wifi setups on rpi.
User avatar
MichaIng
Site Admin
Posts: 2294
Joined: Sat Nov 18, 2017 6:21 pm

Re: Wifi won't auto reconnect

Post by MichaIng »

@jptaranto
Hmm, are you sure this is a WPA(2) protected network? WEP requires a different /etc/wpa_supplicant/wpa_supplicant.conf entry, but should - by all means - not be used anymore.

Also, please check that the wpa_supplicant background service is not running, which is not required for ifupdown-based network setups, and might even collide:
systemctl disable --now wpa_supplicant
jptaranto
Posts: 6
Joined: Thu Oct 10, 2019 11:33 am

Re: Wifi won't auto reconnect

Post by jptaranto »

Hey @MichaIng, thanks again for keeping up with this. I've just got back from some holidays.

It's definitely a WPA2 network using AES/CCMP encryption.

I've run the command you added below. I had heard that wpa_supplicant could collide if it's already running. It seems to be disabled already however.

Code: Select all

dietpi@KitchenPi:~$ systemctl disable --now wpa_supplicant
Failed to disable unit: The name org.freedesktop.PolicyKit1 was not provided by any .service files
dietpi@KitchenPi:~$ systemctl status wpa_supplicant
● wpa_supplicant.service - WPA supplicant
   Loaded: loaded (/lib/systemd/system/wpa_supplicant.service; disabled; vendor preset: enabled)
   Active: inactive (dead)
Post Reply