JacoFourie
Posts: 95
Joined: Thu Mar 10, 2016 6:51 pm

wlan0 gets de-associate after ap reboot

Sat Feb 23, 2019 12:44 pm

Hi all.

I have been running a number of Pi's in the field over the last 3 years. I have picked up some issues with the WiFi.
Wifi will work 100%. All my PI's run on UPS power. Then if there is a power failure the AP will go down as that is not on back-up power.
When the power comes back sometimes one of the 2 WiFi connections (I have 2 the on-board and a dongle for back-up) mostly wlan0 will be de-associated from the AP. I wrote this script that runs every minute with the hope to bring the adapter back but only a reboot will fix it.

Code: Select all

echo "Checking the wifi connections"

# Ping to the router
echo "Checking wlan0 .."
ping -c2 -I wlan0 192.168.1.21 > /dev/null

# If the return code from ping ($?) is not 0 (meaning there was an error)
if [ $? != 0 ]; then
    # Restart the wireless interface
    sudo ifconfig wlan0 down
    sleep 5
    sudo ifconfig wlan0 up
    echo "wlan0 reconnected at `date`"
    echo "wlan0 reconnected at `date`" >> /home/pi/network/wifi_reconnect.log
else
    echo "wlan0 is still up ..."
fi

# Ping to the router
echo "Checking wlan1 .."
ping -c2 -I wlan1 192.168.1.21 > /dev/null

# If the return code from ping ($?) is not 0 (meaning there was an error)
if [ $? != 0 ]; then
    # Restart the wireless interface
    sudo ifconfig wlan1 down
    sleep 5
    sudo ifconfig wlan1 up
    echo "wlan1 reconnected at `date`"
    echo "wlan1 reconnected at `date`" >> /home/pi/network/wifi_reconnect.log
else
    echo "wlan1 is still up ..."
fi
Why does it do this ? It seems that the WiFi on the PI is not very stable. I have set-up a syslog server for the AP to log what is going on between the PI and the AP. I will post that also.

I am still running Jessie.

Andyroo
Posts: 3771
Joined: Sat Jun 16, 2018 12:49 am
Location: Lincs U.K.

Re: wlan0 gets de-associate after ap reboot

Sat Feb 23, 2019 2:50 pm

There is currently an investigation going on into WiFi in this thread but thats Stretch.

I had major issues before Stretch with WiFi and the only way I could fix it was by making the ethernet cable active - that may not be a valid solution in your case!

edit: Have a look at this post: https://www.raspberrypi.org/forums/view ... 0#p1310151 The topic is on changing your IP address but you could ignore that part and just use the 'ip' and 'systemctl' commands rather than the old 'if up / down' commands.
Need Pi spray - these things are breeding in my house...

epoch1970
Posts: 3339
Joined: Thu May 05, 2016 9:33 am
Location: Paris, France

Re: wlan0 gets de-associate after ap reboot

Sat Feb 23, 2019 3:56 pm

Are you using wpa_supplicant?
Do you see wpa_supplicant processes running? There should be one process running by interface.

Depending on your network setup: "ifconfig up/down" is equivalent to "ip link up/down". This is different from "ifup/ifdown" which go through /etc/network/* and launch various scripts to reconfigure interfaces.
"S'il n'y a pas de solution, c'est qu'il n'y a pas de problème." Les Shadoks, J. Rouxel

JacoFourie
Posts: 95
Joined: Thu Mar 10, 2016 6:51 pm

Re: wlan0 gets de-associate after ap reboot

Sun Feb 24, 2019 4:45 pm

I can update to stretch. I will take some time but I can do it.

I have developed a controller to dry tobacco.

https://www.youtube.com/watch?v=yAx9-Uk6Lck&t=6s

There is no way to run a lan cable. It all works with WiFi. It is very stable but now and again the wifi will do this. And not matter what I do only a reboot will bring it back.

What command line command will do the same job as a reboot but only on the wifi side ?

JacoFourie
Posts: 95
Joined: Thu Mar 10, 2016 6:51 pm

Re: wlan0 gets de-associate after ap reboot

Sun Feb 24, 2019 4:55 pm

epoch1970 wrote:
Sat Feb 23, 2019 3:56 pm
Are you using wpa_supplicant?
Do you see wpa_supplicant processes running? There should be one process running by interface.

Depending on your network setup: "ifconfig up/down" is equivalent to "ip link up/down". This is different from "ifup/ifdown" which go through /etc/network/* and launch various scripts to reconfigure interfaces.
Yes I do. And I see both of them

Code: Select all

[email protected]:~ $ ps -ef | grep wpa_supplicant
root       622     1  0 Feb21 ?        00:02:37 /sbin/wpa_supplicant -s -B -P /run/wpa_supplicant.wlan1.pid -i wlan1 -D nl80211,wext -c /etc/wpa_supplicant/wpa_supplicant.conf
root       640     1  0 Feb21 ?        00:00:50 /sbin/wpa_supplicant -s -B -P /run/wpa_supplicant.wlan0.pid -i wlan0 -D nl80211,wext -c /etc/wpa_supplicant/wpa_supplicant.conf
pi        9051  7821  0 18:54 pts/9    00:00:00 grep --color=auto wpa_supplicant
Should I change the script ?

epoch1970
Posts: 3339
Joined: Thu May 05, 2016 9:33 am
Location: Paris, France

Re: wlan0 gets de-associate after ap reboot

Sun Feb 24, 2019 7:02 pm

Ahh. I didn't notice the machine is apparently multi-homed (and the same AP/config file is used for both interface.)
Usually the trouble is with connecting to 2 separate AP/subnets, and wpa_supplicant using somehow the wrong config file for one of the interfaces.

Your setup is certainly unusual. Have you done something about MAC flapping and source routing? Otherwise I'm not certain but I believe the reauth activity could create a loop, with the AP seeing responses coming from the wrong STA.
With a recent version of Raspbian (and wpa_supplicant) it is possible (and reliable I think) to have a wifi interface as a bond slave (e.g. end of this thread). Perhaps a wlan0+wlan1 bond in active/backup mode is worth a try. That would be better than source routing and fiddling with kernel tunables.

Before all that, I would try "wpa_cli -i wlan0" (enter interactive mode) and then use "status" to see what WPA supplicant thinks. Same with wlan1.
If things look wrong, try restarting the wpa_supplicant process in question.
You can also run wpa_supplicant in debug mode (-dd), it is quite verbose but you could harvest some useful keywords.

The last possibility is a driver/firmware bug. A real possibility with wifi, but application and network config are a more likely cause.
In theory, you could shutdown both interfaces and remove all kernel modules related to wifi. Then restarting the interfaces would reload modules and refresh the system same as a reboot.
In practice I've seen systems crash upon module removal or re-addition, so YMMV (by the kernel release, sometimes...)
"S'il n'y a pas de solution, c'est qu'il n'y a pas de problème." Les Shadoks, J. Rouxel

JacoFourie
Posts: 95
Joined: Thu Mar 10, 2016 6:51 pm

Re: wlan0 gets de-associate after ap reboot

Sun Feb 24, 2019 8:28 pm

I want to have a bond but when I started the project I was told I could not bond 2 wifi connections. The reason for 2 is just in case the one fails then I still have another. They both connect to the same AP but each on a separate IP. If I could have one IP on both WiFi connections that would be first prize. The idea is to have 2 AP's. Each Wifi on another but bond them together as one IP. Is that possible with WiFi on the Pi ?

Another reason is the onbaord wifi is not that strong a signal from inside the metal case. The dongle is a lot stronger and that should be the main connection and if it fails fall back to the onboard wifi.

epoch1970
Posts: 3339
Joined: Thu May 05, 2016 9:33 am
Location: Paris, France

Re: wlan0 gets de-associate after ap reboot

Sun Feb 24, 2019 10:57 pm

I expect active/backup bonding would work "100%" with the option fail_over_mac=active. The cost of that constraint is an IP address for the bond interface that could dance around, as the MAC of the bond would follow the MAC of the active slave. Since each slave keeps its original MAC, wifi authentication should be no problem.

In the default "fail_over_mac=none" behaviour, bond0 chooses a MAC among one of its slaves and keeps it. All the slaves are reassigned with this MAC as well. This used to be a problem for wifi drivers/wifi authentication but perhaps the situation is not as dire as it used to be. If it woks, this is what you want.

Right now, and if I understand correctly, with 2 interfaces on the same network and no per-interface routing table, I'm not certain why your setup works... Source-based routing can be made to work, but I am afraid the kernel would still need some extra persuasion to change route when a link goes down (STA deauthenticated), but the interface is still administratively up (nobody ran "ip link set wlan0 down")
In a relatively recent kernel you could use the tunable ignore_routes_with_linkdown=1, but if its not enough/not available, you'd need to resort to userland: ifplugd (buddy with ifupdown, so getting obsolete fast) or some script based on "ip monitor". Perhaps dbus is an option as well, I surely wouldn't know.
All in all, it is "complicated".

So yes, I'd try getting bond to work in one form or an other, it fits best I think.
"S'il n'y a pas de solution, c'est qu'il n'y a pas de problème." Les Shadoks, J. Rouxel

JacoFourie
Posts: 95
Joined: Thu Mar 10, 2016 6:51 pm

Re: wlan0 gets de-associate after ap reboot

Mon Feb 25, 2019 11:29 am

When you say my set-up should not work why do you say that? Can I not have 2 wifi connections on the same network on different IPs ? I have it that way on all my PI's. Why should it not work ?

epoch1970
Posts: 3339
Joined: Thu May 05, 2016 9:33 am
Location: Paris, France

Re: wlan0 gets de-associate after ap reboot

Mon Feb 25, 2019 12:27 pm

I should have said “have a controlled behavior” I suppose.
See https://serverfault.com/questions/41530 ... ame-subnet for an example of the fuzzy behavior Linux has by default. It works, but it’s not doing what you’d think it would do.

In the case where the 2 interfaces are connected each to a different gateway (eg 1 ISP box, 1 3G dongle), you can end up sending requests one route and listening for responses on the other, to no avail. In this case, it doesn’t work at all.
"S'il n'y a pas de solution, c'est qu'il n'y a pas de problème." Les Shadoks, J. Rouxel

Return to “Troubleshooting”