|Top Previous Next|
True to the non-blocking operation philosophy of TiOS, the wln. object does not stall the entire Tibbo BASIC/C application execution to wait for the Wi-Fi interface to complete an operation ("task"). You program gives the wln. object a task to perform, and then it is free to go and do other things. The only exceptions are the wln.boot and Wln.waitforupgradecompletion methods. They stall your system until they are done executing.
There are nine Wi-Fi activities that are implemented as tasks:
•Setting TX power (wln.settxpower).
The wln. object can only handle one task at a time. Before executing the next task method, your app must make sure that the previous task has completed. You can find this out through the wln.task read-only property. Three tasks on the list — wln.setwep, and wln.setwpa , and wln.settxpower — 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.
Each task method returns an accepted_rejected status code indicating whether the task was accepted for processing. Tasks may be rejected for a variety of reasons, so it is important to check this code.
The following example shows a wrong way of tasking:
Three things are wrong here. First, the code does not check if each task is accepted or rejected. Second, it doesn't wait for the first task to complete before starting the second task. Third, "task completed" is not equal to "task completed successfully." For example, the association task will eventually be completed no matter what, but this won't guarantee that you are associated — you must check this separately.
Here is how you should do this:
One problem with this code is that it is blocking. Essentially, it nullifies all our effort that went into building an asynchronous system. Your application is not doing anything useful while the Wi-Fi interface is scanning or associating.
To take advantage of the event-driven nature of TiOS, you can base your execution flow on the on_wln_task_complete event, which is generated each time a task completes. The completed_task argument of the event handler carries the code of the event that has been completed. Therefore, you can advance through your app's execution steps in the following manner: