Associating With Selected Network

Top  Previous  Next

Association is a process by which your Wi-Fi device establishes a link with an access point or another wireless station running an ad-hoc network.

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. Note that wln.associate is a wln task and there is a certain correct way of handling tasks.

Wln.associate will be rejected (return 1- REJECTED) if:

Another task is currently in progress.
GA1000 add-on module is not online (wln.enabled= 0- NO).
The Wi-Fi interface is already in the non-idle state (wln.associationstate<>0- PL_WLN_NOT_ASSOCIATED). That is, you can't try to associate when you are already associated or running own ad-hoc network.

The method will return 0- ACCEPTED if the task is accepted for processing.

 

Prior to associating, you need to set the WEP  or WPA security (if required). You also need to know several key parameters about the network you are associating with:

SSID (the name) of this network;
BSSID ("MAC") of this network;
Channel on which this network operates;
BSS mode of this network (whether the network is infrastructure or ad-hoc).

 

Normally, the SSID is known, but BSSID, channel, and BSS mode require some digging. The easiest way to sniff out correct values of these parameters is through scanning. Wln.scan or wln.activescan will fill out wln.scanresultbssid, wln.scanresultchannel, and wln.scanresultbssmode R/O properties. You only need to put them to good use, as shown in the example below.

Before you look at the example, consider this: you may be able to discover the network with wln.scan, yet unable to associate with it because this network is operating on a channel which is disallowed in a currently selected domain.

 

 

'connect to the access point named TIBBO.

wln.scan("TIBBO") 'scanning for a specific network will give us necessary parameters (you can also use wln.activescan)

While wln.task<>PL_WLN_TASK_IDLE

Wend

If wln.scanresultssid<>"" Then

  'wireless network not found

End If

 

'now can associate: 'wln.scanresult...' properties contain necessary data after the scanning

wln.associate(wln.scanresultbssid, wln.scanresultssid, wln.scanresultchannel, wln.scanresultbssmode)

While wln.task<>PL_WLN_TASK_IDLE

Wend

If wln.associationstate=PL_WLN_ASSOCIATED Then

  'successful association!

  ...

End If

 

 

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.

If you are running with no security or WEP security, you can start communicating over the Wi-Fi interface as soon as you are done associating. If it is WPA you are dealing with, completing wln.associate is really just a first step. There is a lengthy and laborious message exchange to follow. It is best to delegate this to our WLN library!

When the wln. object is in the associated state, wln.rssi read-only property is constantly updated with the strength of the signal coming from the access point. Do not confuse this with the wln.scanresultrssi property which returns the signal strength of a particular network obtained during scanning.