Step 4: Roaming Between Access Points
|Top Previous Next|
This and other projects in the Code Examples section are published on our website under the name "test_wln_lib".
Finally, here is the coolest example of them all — the code for a mobile device that roams between several access points that all have the same SSID (name). Typically, you use such a setup to create a larger wireless network. The example from the previous topic would work, but not very well if your device was mobile.
Say, you walk around with your GA1000-based gadget in your pocket. At boot, it would execute wln_start(), which would in turn search for the target wireless network, find several access points, and select the one with the strongest signal. The GA1000 would then latch onto this access point and won't let go until the signal gets so bad that the association is lost. The WLN library would then try to find a better access point to work with. Sounds like there is no problem, right?
Wrong! In practice, you will find that at a certain distance from the access point you get into the "grey area of communications" where the link between your gadget and the access point becomes spotty, but not quite bad enough for the association to fail. And, since the association won't quite fail, your device won't try to find a better access point to link to. Meanwhile, you will experience data delivery delays, unstable comms, etc.
Here is the solution. Additional code in on_sys_timer periodically checks current signal strength (wln.rssi). Whenever it falls below a predefined constant RSSI_THRESHOLD, the code will do wln_rescan() in an attempt to "find a better deal". Rescan result is checked in callback_wln_rescan_result(). If a different and better access point is found, wln_change() will switch your device to using it.
It is important to understand why the program searches for better access points only when the signal drops below RSSI_THRESHOLD. Scanning is a disruptive process that temporarily interferes with data comms. There is no reason to scan if the current signal is perfect! Exactly what value should RSSI_THRESHOLD have depends on your device, antenna, etc. Find it through trial and error.