|Top Previous Next|
True to the non-blocking operation philosophy of the entire system, the wln object does not stall the entire Tibbo BASIC/C application execution to wait for the Wi-Fi interface to complete required operation ("task"). You program gives the wln. object a task to perform, and then it is free to go and do other things.
There are nine wln. tasks:
Three tasks on the list — wln.settxpower, wln.setwep, and wln.setwpa — are so-called immediate tasks. They complete as soon as they are started. If the execution advances to the next statement in the program then you know that these tasks are done with.
All remaining tasks take time to complete, and they complete asynchronously with respect to the program execution. The following example shows a wrong way of tasking:
Here is how you should do this: use the wln.task read-only property and wait until the previous task is completed.
The above approach still needs some refinement. Just making sure that the previous task has competed will not guarantee that your next task will be accepted. This is because some tasks can only be accepted under certain conditions. For example, you can't associate while you are already associated. Try this, and wln.associate will return 1- REJECTED.
Now, this is still not all. "Task completed" is not equal to "task completed successfully". In the above example, we were trying to associate with the "NET1" network. Now, have we actually succeeded? Find out by testing the value of wln.associationstate! For every task that may result in failure there is a way to know if the execution was successful or not.
One problem with the code in the above examples is that it is, essentially, blocking. Your application is not doing anything useful while the Wi-Fi interface is associating.
To take advantage of the event-driven nature of the system, you can base your execution flow on the on_wln_task_complete event which is generated each time a task is completed. Completed_task argument of the event handler carries the code of the event that has been completed. Therefore, you can advance through steps in this manner:
Notice the on_wln_event in the code above. It allows us to catch "problems".