Linux and USB wifi dongle issues
Not too long ago I switched my Linux server from wired ethernet to using wifi with a USB dongle (the cable was in an awkward spot). Ever since I have had problems on and off with its connection. I recently switched to a new router and began having issues again, but figured out a solution. I thought I'd share in case someone else has these same problems.
The wifi dongle I've been using is an ASUS USB-N13 802.11N USB wireless
adapter. lsusb
for it
looks like this:
Bus 002 Device 003: ID 0b05:17ab ASUSTek Computer, Inc. USB-N13 802.11n Network Adapter (rev. B1) [Realtek RTL8192CU]
Typically I try to find evidence online that someone has got it working with Linux before I buy a wifi dongle. Unfortunately there are still gaps in the support for them, but with some research I can usually find something that works well. This pick was a bit hit and miss:
- Using Raspbian Jessie (kernel 4.4.19 at the time of writing) the connection is rock solid at 144Mbps.
- Using Debian Jessie (kernel 3.16.0 at the time of writing), the connection quality varies depending on the AP's settings and the kernel module.
A tale of three routers
I previously used a Netgear WNDR3700v3 router running OpenWRT. With this router, the Debian server would lose connection every few hours. I could find no solution. I tried several things, but nothing worked.
I replaced the Netgear router with a Linksys WRT54GL (I bricked the Netgear). While the Linksys was older and did not support 802.11n, to my surprise I found that my connection was stable. I decided the Netgear router was the problem (probably something to do with my configuration I thought). In support of this, another of my devices was exhibiting similar behaviour that also went away when I started using the WRT54GL.
A week or so ago I had fiber internet installed. The company provided me with a 802.11n router, so I retired the WRT54GL. I began to have problems once more with the USB-N13.
The wifi connection on the server would hang and I would see destination host
unreachable on either end. There seemed to be no specific circumstance that
would cause it, but it was frequent. Waiting 5 minutes was often enough to have
it happen. There were no error messages I could see, even when I loaded the
module with debug=5
.
I discovered that if I kept pinging the wifi router from the server that the connection would stay stable. But I was not happy with that as a long term solution.
I tried enabling swenc=Y
on the module and nothing changed. Power management
apparently was already off. The problem kept happening.
A partial solution
I tried adjusting the settings on the router. I discovered that if I turned off WMM that the connection was stable. However the connection would drop to 18Mbps on the server (down from 72Mbps). I thought I could live with it though.
But I got to thinking that I was giving up and that I should be able to get to the bottom of the problem.
A new module
I knew that in Raspbian with the newer kernel the dongle performed very well. I considered upgrading the server to see if the kernel in Debian stretch would make any difference, though I was hesitant as I like this server to be quite stable.
I found the project
rtl8192cu-fixes on Github. This is
an updated and improved version of the module, rtl8192cu
, that the dongle
uses (apparently it is a backport). Building and installing this leads to the
module 8192cu
.
I was shocked. My connection was stable, and the connection speed jumped to 144Mbps. I could enable WMM again.
Most shockingly of all I noticed that my packet loss was at 0%. Previously it was constantly 6-10% or even higher. I assumed that since the server was so far and with so many walls between it and the router that this was just a fact of life, but apparently not.
It was all down to software defects apparently. Very frustrating, but I'm very happy now!