6

I have set up a raspberry pi as a wifi access point. At this point, all I want to do is ssh the rpi. I'm finding that the ssh sessions hang for 5-30 seconds ever 1 to 6 minutes or so. My laptop is the only client connected to the AP. If I set up a continuous ping from my laptop to the AP address, the average ping time is around 1-4ms, but then every so often, excessive delays of around 100-500ms or timeouts for up to 5-30 seconds will occur. This occurs whether there is an ssh session active or not. By comparison, if I ping the ethernet port, all delays are 1ms or less and I have no timeouts. I have tried changing channels with no benefit.

What is interesting is that if I disable wifi 'n' mode (now running in g), wmm and ht_capab in hostapd.conf, I greatly improve the situation with very few (if any) timeouts. With these disabled, usual ping times are 1-2ms with occasional delay of 120ms.

lsmod shows the following modules:

-Module Size Used by
-aes_generic 31536 1
-8021q 17966 0
-garp 6295 1 8021q
-stp 1969 1 garp
-llc 5440 2 stp,garp
-snd_bcm2835 15846 0
-snd_pcm 77560 1 snd_bcm2835
-snd_page_alloc 5145 1 snd_pcm
-snd_seq 53329 0
-snd_seq_device 6438 1 snd_seq
-snd_timer 19998 2 snd_pcm,snd_seq
-snd 58447 5 snd_bcm2835,snd_timer,snd_pcm,snd_seq,snd_seq_device
-arc4 1676 2
-rt2800usb 14940 0
-rt2800lib 55351 1 rt2800usb
-rt2x00usb 11215 1 rt2800usb
-rt2x00lib 42334 3 rt2x00usb,rt2800lib,rt2800usb
-mac80211 273413 3 rt2x00lib,rt2x00usb,rt2800lib
-cfg80211 184163 2 mac80211,rt2x00lib
-rfkill 18202 2 cfg80211
-crc_ccitt 1522 1 rt2800lib
-leds_gpio 2235 0
-led_class 3562 2 leds_gpio,rt2x00lib

hostapd.conf

-interface=wlan0
-driver=nl80211
-ctrl_interface_group=0
-ssid=ivoPI

-hw_mode=g
-ieee80211n=1
-wmm_enabled=1

-channel=5
-#macaddr_acl=0
-auth_algs=3
-#ignore_broadcast_ssid=0
-wpa=3
-wpa_passphrase=*******
-wpa_key_mgmt=WPA-PSK
-wpa_pairwise=TKIP
-rsn_pairwise=CCMP

-ht_capab=[HT20][SHORT-GI-20] #[RX-STBC1]

If anyone can help out here, it would be greatly appreciated. cheers

Ivo

Further to the above:

I have now tried the wifi adapter above, along with another, in client mode. The first adapter has rt3072 chip with rtl2800usb / cfg80211 driver. The second adapter has a Realtek rtl8188us chip with r8712u staging driver. Each adapter (separately), was connected to a powered hub. The pi didn't have the Ethernet connected.

First adapter With low processor load and no shell or shell with no traffic, there was no typical ping results. Delays appeared to be totally random from 2ms to 320ms - all over the place. There were occasional timeouts. When top was run at 0.01 sec, pings became very steady at 2-3ms with occasional single ping delays of 195-222ms. I observed on timeout 5 sec over a period of about 20 minutes.

second adaptor With low processor load and no shell or shell with no traffic, typical ping results were 1-2ms. Ping results were generally very stable. Under load - top running 0.01 sec, ping delay was around 2-3ms with occasional 166-200ms single ping delays. I didn't observe any timeouts.

So what does one conclude from this? It looks to me to be a driver problem with rtl2800usb / cfg80211 or some other related component. One could almost fix the problem by running top continuously, but it does seem kind of wasteful!! and I do still get the occasional timeout. I don't know yet whether it was the higher processor load or the increased tcp/ip traffic that made the improvement.

Ivo
  • 61

3 Answers3

6

I had the same problems with different wifi sticks on my raspberry. I tried different power supplies, different Raspberrys and also an active USB hub. So I was lucky to see your observation, that disabling wifi 'n' mode, wmm and ht_capab could lead to better results. I disabled n-mode and wmm on my wifi router Asus RT-N66U (running openwrt/tomato), and the ping time decreases from 10-100ms to 1-3ms, and the connection was very stable. Before that, the connection went down very often (after 30-60min) and where very slow in general.

But disabling the n-mode for the complete wifi network could not be the solution, so I find another recommendation (https://github.com/xbianonpi/xbian/issues/217):

  • Create the file /etc/modprobe.d/8192cu.conf which contains the line:

    options 8192cu rtw_power_mgnt=0 rtw_enusbss=0
    
  • Reboot

That switches off power saving of the wifi stick and USB autosuspend.

  • You can check if power saving mode is switched off:

    cat /sys/module/8192cu/parameters/rtw_power_mgnt
    

Since 24 hours the wifi connection is stable now on two different Raspberries. The ping times are slightly larger (5-6 ms) than disabling n-mode and wmm on the wifi router, but very stable and with only small variations.

Kartik
  • 2,004
1

I had the same problem with my Pi and the 8192cu module, and I couldn't get any of these suggestions to fix the problem.

In the end out of desperation I checked what other wifi access points were active in the area, and to my surprise, a neighbour had set up a new wifi network on the same channel as mine was using. Switching to a different channel fixed the problem!

No more 20,000ms pings or 40% packet loss, great! Sometimes the easiest solutions are the most difficult :-)

Malvineous
  • 6,883
1

Do you get the same behaviour with it on the network as just a client? I have not tested it in as much detail as you, but my pi is inclined a bit this way too sometimes; I've only had it a few weeks and have been attributing it to the 8192cu driver which is glitchy in other ways -- eg, it will not work on a power hub, only when plugged directly in.

Meaning the dongle has to be on one of the pi's underpowered usb ports -- they deliver at most 140 mA instead of the USB 2.0 standard 500 mA (see here)-- which I think must make a wifi device prone to problems. I have it pinging the router every five seconds and when the ping fails, it reconnects (I'm not using NetworkManager or any system daemon, which would normally handle that...anyway if it reconnects right away it takes ~15 seconds); looking at the log for this it has happened 3 times in the past 30 hours, which is not so bad, but it has not been doing anything either. On friday I was compiling on it via ssh (so, maxing the processor continuously for a long time) and it happened frequently (maybe every 5-10 minutes? fortunately this just freezes the ssh i/o for a bit).

I may end up getting a beefier adapter that will work on the power hub if it remains a problem. If you want to use it as an access point, I think you should definitely use an external power hub if you are not already. Apparently, it is common for them not to be regulated internally so each port can draw up to the hub capacity (2-4 amps) and not just 500mA, meaning you can also power the pi off it; some implicit references to that here. I have one of the belkin hubs and get about 0.05-0.1 volts less on the hub than on a 2A 5V charger. Now, with the wifi adapter plugged into the pi (and it is a wee lil nano one), it gets another 0.05-0.1 volts less, which is not inconsiderable since the optimal range is 4.75-5.25V -- according to my multimeter I am right at the bottom of that on the hub with the nano adapter when idle.

I would guess working on a g network demands less from the wifi adapter since it is slower than n.

Oh and BTW there is an rpi stack exchange :)

goldilocks
  • 87,661
  • 30
  • 204
  • 262
  • Thanks for the tip on the rpi stack exchange - I will try both forums now that I've started here. – Ivo Feb 11 '13 at 22:34
  • I don't believe the problem is related to power. I did have the wifi adapter plugged directly into a pi usb port, however the pi is supplied via a good supply and I have modified the wiring so that the input power to the pi is also routed directly to the power pins on the usb connectors. But to be sure I tried with a powered up and the results don't seem to be materially different. I don't think I had the same problems when I had the pi operating as a client on our network. It is hard to know for sure because our router is subject to regular resets for some reason. – Ivo Feb 11 '13 at 23:05
  • I do intend to go back and load my image that had the client configuration to see what I can learn with ping tests but I it will be less obvious as more 'blocks' are involved in the ping circuit.

    At the moment all I have is my laptop client and the pi with powered hub and Digitech hi power dongle. I don't even have an ethernet connection. I notice that if I don't have an ssh running typical responses are 2-4ms with bursts of typically 80-110-90ms affecting 3 or 4 sequential 1 second pings. On top of that there will be the occasional timeout - which I think is around 5 sec.

    – Ivo Feb 11 '13 at 23:05
  • The above is all running in mode g. If I start a shell session, there is no difference. However if I then load the processor up by running top at 0.01 sec intervals, the typical ping latency goes down to around 1ms. Of course it varies but you get a pretty good impression, that the latency has approximately halved. Superimposed on top of that are the 3 or 4 sequential bursts as described above. My feeling is that there is some sort of conflict going on; the bursts of longer delay occuring when the ping arrives when some other conflicting task is running. – Ivo Feb 11 '13 at 23:05
  • @man Ivo: have a look at man nice if you aren't aware of it: http://en.wikipedia.org/wiki/Nice_%28Unix%29. Start hostapd manually at -10; if that works you can put in the init script. – goldilocks Feb 12 '13 at 12:52
  • Thanks goldilocks. I will try that but I have also found that I get ping timeouts when my adapter is working in normal client mode - see edited original post. Hostapd is not running under those circumstances. I can't understand why the performance improves when the 'system' is loaded up in both the client and Master modes. It's as if something needs a wakeup! – Ivo Feb 12 '13 at 22:36
  • I tried changing nice of the hostapd service and it didn't seem to make any material difference, which I don't find overly surprising given the system is lightly loaded and the timeouts can be around 20 seconds with HT/WMM on. I did however find that disabling wifi dongle power_save in client mode made a big difference to the large and random ping times. This is not an option in AP mode, but the ping times are fairly stable in that mode anyway - its just the wretched timeouts that I need to address. Any more ideas anyone? – Ivo Feb 14 '13 at 04:52