Raspberry Pi wifi+ssh connection disconnecting (Ourlink rtl8192cu)

I started playing around with a new Raspberry Pi 2 that arrived yesterday. I had used a Beaglebone before (always connected to ethernet) so I knew what to expect in terms of memory and CPU limitations. What surprised me was how flaky ssh connections were when connected over wifi using this USB wifi dongle (an Ourlink RTL8188CUS/RTL8192cu chipset) from Adafruit. I could connect for a second and then if I paused for even a moment the connection would drop and I would get  a “Host is down” response if I tried to reconnect. Usually I would need to power cycle the Pi to be able to ssh in again.

Googling for similar issues I found the following advice:

  • Some 5V power sources actually deliver less than 5 volts. Also some chargers don’t deliver enough current (A) to supply both the Raspberry Pi and the wifi dongle. To guarantee that this wasn’t the issue I added a powered USB hub to run the wifi dongle. This didn’t solve the issue.
  • You can enable an ssh option to send a “null packet” every X seconds. You can set this on the server-side or on the client-side. On the server in /etc/ssh/sshd_config:
    ClientAliveInterval 60

    On the client in ~/.ssh/config:

    ServerAliveInterval 60

    This helped out considerably. This made sense since I could stay connected by just running ping in the ssh session or typing ls constantly. I would still lose connection after a while and would have to wait for something in the Pi to reset.

  • The real solution (and the point of this post) is suggested here. Apparently the wifi dongle has a power conservation mode that is causing it to disconnect from wifi. In hindsight, this is kind of obvious (I could see the Pi disconnecting from the router) but it took me forever to find this tip. Anyway this fixed everything:
    echo "options 8192cu rtw_power_mgnt=0 rtw_enusbss=0" | sudo tee --append /etc/modprobe.d/8192cu.conf

Hopefully this will save someone else some time.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s