Update this project:
This guide will be talking about using iwconfig to tune your connection settings. Out of the box, the default values are very liberal, good for high bandwidth under optimal conditions. In reality you are never quite as close to the access point as you'd like to be, channels are close enough to overlap, and lots of people are trying to share the connection. The default settings are not good under these conditions. Keep the `iwconfig` man page open while reading this. I'll just give a single example of various commands. The man page will go into much greater detail regarding how you can optimally tune these. First and most important is knowing what type of interference is causing the trouble. ## Attenuation > *[noun] the property of something that has been weakened* Attenuation happens when the AP is far away or there are reflective surfaces or absorptive volumes in the way. Reflective surfaces include aluminum siding or galvanized window screen. Signals will not get through these, instead bouncing off. New energy efficient windows may also reflect; they use a very thin metallic layer to reflect heat. Incidentally they reflect radio frequencies as well. Absorptive volumes are much more obvious. Wifi predominately uses 2.4GHz. Microwaves operate on the same frequency because water absorbs these frequencies, heating the water up. Thus any large body of water between you and the AP will reduce the signal. Trees (and their localized humidity from transpiration) are a major source. A less obvious source is cement, concrete and cinder block. These are typically 50% water by weight. Most other construction materials are relatively dry and do not cause problems. Symptoms: * Weak signal. Options: * Move the radio to a clearer line of site. * Add a directional antenna to make up for the lost gain. * Increase transmitter power. * Get a more sensitive receiver. * Slow the connection speed to improve the signal-to-noise ratio (SNR). ## Noise > *[noun] electrical activity that can disturb communication* Where attenuation lowers the signal, noise raises the noise floor. Relatively speaking, both have the same effect: worse SNR. As such, the symptoms are the same, as are the above options to fix it. (With one small correction, increasing the sensitivity will not help.) Normally noise is environmental, or at least an unintentional side effect. There is one special case otherwise. First, a small aside. The concept of 50% is very important in engineering. Often a hard demarcation line does not exist. Many measurable qualities just fade away and never actually stop. So we need a threshold to label where something ends. That number is often 50%. Once something crosses the 50% threshold, it no longer exists. Where this 50% transition occurs is one of the most important specifications on many designs. So please be understanding. The designers of 802.11 placed all the channels as closely together as possible, on the 50% power transitions. In theory, this means two channels will never interfere with each other. But only when all other things are equal. In practice, if your AP is on channel 2 and your neighbor's is on channel 1, you will not be able to use your wifi when in your neighbor's house. Your signal is too far away and too attenuated. (In some cases you get around with a directional antenna.) To your connection, nearby stations are noise. The usual techniques for noise apply, except that a more powerful transmitter will interfere with your neighbor's connection. If you like making antennas then this can cause other problems. The access points in your area can blind your receiver during range testing. For example in a developed area you might have difficulty seeing past a hundred meters. During a power outage without all those local APs gumming up the airwaves, the same antenna might pick out APs a kilometer away. ## Contention > *[noun] the act of competing for a prize* When multiple people use the same access point, things start getting exciting. First, everyone works at the slowest speed. If one person is connecting with an ancient B wifi adapter, no one is going faster than 11Mb. (For high end multi-antenna access points, this may not hold true.) The bigger problem of contention is that only one radio may use the channel at a time. Everyone takes turns and must complete for their share of the bandwidth. This is probably the biggest problem with wifi on linux. The default settings are tuned for optimal throughput and these defaults are horrible for situations with lots of contention. Symptoms: * Can't establish a connection. * Can't get an IP address. * Frequent timeouts on webpages. * Lots of excessive retries and invalid packets. Options: * Increase speed. The faster everyone is connected, the shorter their time slice is and the less contention you will run in to. This is something that must usually be enforced on the wireless AP, not at the client level. * Fragment your packets. Normally packets are set in one piece, as large as possible. Use `iwconfig wlan0 frag 256` to chop the packets up smaller. This hurts your throughput, but makes the packets much more likely to slip by everyone else's. * Enable rts handshaking. Before sending a packet, handshake with the AP to guarantee that it is listening. This really hurts your throughput but does wonders for getting the attention of the access point. The default is to only perform the handshake on packets bigger than 2kB. Force it for all packets with `iwconfig wlan0 rts 1`. * Increase the retry levels. Persistence is key for pushing through a crowd and this holds true for wireless contention as well. Normally your card gives up after seven attempts at sending a packet. Thirty is more reasonable, tune with `iwconfig wlan0 retry 30`. ## What about iwpriv? Iwpriv is a shockingly powerful tool. Basically all the non-standard features are wedged into there. Some options are pointless, others are wonderful, all vary between drivers, none are very well documented. Experiment with your wifi cards. Iwpriv will probably need an entire essay on its own. ## After connecting You need an IP address. Normally `dhcpcd` is exceedingly slow and in poor environments frequently times out. Dhcpcd will run about forty times faster with `dhdpcd -A wlan0`. Before Amtrak started putting wifi on trains, `-A` was crucial to pulling off a git push or imap pull while blasting through a station. Basically `-A` trusts that the AP is not malicious and skips the check that your new IP is unique to the network. ## Legal issues Adding gain or transmitter power can fix many problems and increase reliability. But only to an extent. The FCC has [very comprehensive rules](http://www.wlanantennas.com/faq.php) about this sort of thing. Note that there are different rules for omnidirectional and directional antennas. Increasing gain while decreasing power is often improves the connection, and extends battery life for very remote transmitters. There is a gray area I've heard some people talk about but have never heard of anyone getting in trouble for. Basically, even if your gain and tx power are low enough you are not using a certified radio. Replacing the antenna can annul the entire device. I've never heard of this being a problem, but it is something to be aware of.