|
Associating With Selected Network |
Top Previous Next |
Association is a process by which your Wi-Fi device establishes a network link with an access point in the infrastructure mode or another wireless station in the ad-hoc mode.
The association process is initiated using the wln.associate method. Association is a required step before you will be able to send and receive the data over the Wi-Fi. With the wln object, association also encompasses the process of your Wi-Fi interface starting an ad-hoc network of its own. Technically, the latter is not association at all, but on the wln object it still falls under the umbrella of wln.associate. Please, note that wln.associate is a wln task, and your application should wait for this task to complete before issuing another task.
Prior to calling wln.associate, you need to specify several parameters:
| • | Set the WEP -- we have already discussed this. |
| • | Select infrastructure or ad-hoc mode using the wln.bssmode property. |
| • | Set the SSID of the network using the wln.ssid property. |
| • | For the ad-hoc mode, also set wln.defaultibsschannel. This is not necessary for the infrastructure mode as your hardware will select the channel of the access point automatically. |
|
Does any of the above sound cryptic to you? Perhaps, our Wi-Fi Parlance Primer will help! |
In the infrastructure mode, your Wi-Fi interface will attempt to associate with the access point specified by the wln.ssid. In the ad-hoc mode, the Wi-Fi will attempt to connect to the wireless station with the name, matching the one set in the wln.ssid. If such station is not found, the Wi-Fi will start an ad-hoc network of its own and name it according to the value of the wln.ssid property.
After the association task is completed, you have to check the association result. Mere task completion does not indicate success! The wln.associationstate will provide the indication.
Here is a code example:
'connect to the access point named TIBBO. This one has WEP switched off (for simplicity) wln.wepmode=PL_WLN_WEP_MODE_DISABLED wln.bssmode=PL_WLN_BSS_MODE_INFRASTRUCTURE wln.ssid="TIBBO" wln.associate While wln.task<>PL_WLN_TASK_IDLE Wend If wln.associationstate=PL_WLN_ASSOCIATED Then 'successful association! ... End If
|
Once you have achieved association, you can communicate over the Wi-Fi interface. Re-association is not allowed, you need to disassociate first. Disassociation can also happen automatically (for example, if the access point goes offline or out of range), and the wln object will be able to detect this.
Note that the Wi-Fi interface will not be able to associate with the wireless network if this network is operating on one of the channels that are not allowed by currently selected domain.
When the wln is in the associated state, the wln.rssi read-only property is constantly updated with the strength of the signal being received from the currently used wireless network. Do not confuse this with the wln.scanresultrssi property which returns the signal strength of a particular network obtained in the scan process.