Step 1: The Simplest Example

This and other projects in the Code Examples section are published on our website under the name "test_wln_lib".

Let's start with a simple example of connecting to an access point named "TIBB1", which is configured for WEP64 security. The password is "12345678AB". All your code really has to do is start the "Wi-Fi engine" by calling wln_start().

To illustrate the use of callback procedures, we set green status LED on in callback_wln_ok(). We turn this LED off in callback_wln_failure().

Debug output we've got after running the code:

** Tibbo Basic **


WLN> ---START---
WLN> ACTIVE SCAN for TIBB1
WLN> ASSOCIATE with TIBB1 (bssid: 192.63.14.197.236.216, ch: 11)
WLN> ---OK(associated in WEP64, WEP128, or no-security mode)---

You can test the "association persistence" by turning your access point off and on. You will see how the library will restore the association:

** Tibbo Basic **


WLN> ERROR: disassociation (or link loss with the access point)
WLN> ACTIVE SCAN for TIBB1
WLN> ERROR: access point not found
WLN> ACTIVE SCAN for TIBB1
WLN> ERROR: access point not found
...
WLN> ACTIVE SCAN for TIBB1
WLN> ASSOCIATE with TIBB1 (bssid: 192.63.14.197.236.216, ch: 11)
WLN> ---OK(associated in WEP64, WEP128, or no-security mode)---

And here is the code itself...

** Tibbo Basic **


'DEFINES-------------------------------------------------------------
#define WLN_DEBUG_PRINT 1

#if PLATFORM_ID=EM500 or PLATFORM_ID=EM500W
 #define WLN_RESET_MODE 1 'there will be no dedicated reset, and all other lines are fixed
#elif PLATFORM_ID=EM1206 or PLATFORM_ID=EM1206W
 #define WLN_CLK PL_IO_NUM_14
 #define WLN_CS PL_IO_NUM_15
 #define WLN_DI PL_IO_NUM_12
 #define WLN_DO PL_IO_NUM_13
 #define WLN_RST PL_IO_NUM_11
#else
 'EM1000, NB1010,...
 #define WLN_CLK PL_IO_NUM_53
 #define WLN_CS PL_IO_NUM_49
 #define WLN_DI PL_IO_NUM_52
 #define WLN_DO PL_IO_NUM_50
 #define WLN_RST PL_IO_NUM_51
#endif

'INCLUDES------------------------------------------------------------
include "sock\trunk\sock.tbh" 'this lib is necessary for the WLN lib's operation
include "wln\trunk\wln.tbh"

** Tibbo Basic **


include "global.tbh"

'====================================================================
sub on_sys_init()
 if wln_start("TIBB1",WLN_SECURITY_MODE_WEP64,"12345678AB",PL_WLN_DOMAIN_FCC)<>WLN_STATUS_OK then
         sys.halt
 end if
end sub

'--------------------------------------------------------------------
sub on_sys_timer()
 wln_proc_timer()
end sub

'--------------------------------------------------------------------
sub on_sock_data_arrival()
 wln_proc_data()
end sub

'--------------------------------------------------------------------
sub on_wln_task_complete(completed_task as pl_wln_tasks)
 wln_proc_task_complete(completed_task)
end sub

'--------------------------------------------------------------------
sub on_wln_event(wln_event as pl_wln_events)
 wln_proc_event(wln_event)
end sub

** Tibbo Basic **


include "global.tbh"

'====================================================================
sub callback_wln_ok()
 pat.play("G~",PL_PAT_CANINT)
end sub

'--------------------------------------------------------------------
sub callback_wln_failure(wln_state as en_wln_status_codes)
 pat.play("-",PL_PAT_CANINT)
end sub

'--------------------------------------------------------------------
sub callback_wln_pre_buffrq(required_buff_pages as byte)
end sub

'--------------------------------------------------------------------
sub callback_wln_rescan_result(current_rssi as byte, scan_rssi as byte, different_ap as no_yes)
end sub