@@ -12,25 +12,41 @@ String WiFiClass::firmwareVersion() {
1212#endif 
1313}
1414
15- int  WiFiClass:: beginconst  char  *ssid, const  char  *passphrase, wl_enc_type security ,
16- 					  bool  blocking) {
15+ int  begin (const  char  *ssid, const  char  *passphrase,
16+ 		  wifi_security_type security = WIFI_SECURITY_TYPE_NONE,  bool  blocking =  true ) {
1717	sta_iface = net_if_get_wifi_sta ();
1818	netif = sta_iface;
1919	sta_config.ssid  = (const  uint8_t  *)ssid;
2020	sta_config.ssid_length  = strlen (ssid);
2121	sta_config.psk  = (const  uint8_t  *)passphrase;
2222	sta_config.psk_length  = strlen (passphrase);
2323
24+ 	//  The user might provide the security type as well
25+ 	if  (security != WIFI_SECURITY_TYPE_NONE) {
26+ 		sta_config.security  = security;
27+ 	} else  {
28+ 		sta_config.security  = WIFI_SECURITY_TYPE_PSK;
29+ 	}
30+ 	sta_config.channel  = WIFI_CHANNEL_ANY;
31+ 	sta_config.band  = WIFI_FREQ_BAND_2_4_GHZ;
32+ 	sta_config.bandwidth  = WIFI_FREQ_BANDWIDTH_20MHZ;
33+ 
2434	//  Register the Wi-Fi event callback
2535	net_mgmt_init_event_callback (&wifiCb, scanEventDispatcher,
2636								 NET_EVENT_WIFI_SCAN_RESULT | NET_EVENT_WIFI_SCAN_DONE);
2737
2838	net_mgmt_add_event_callback (&wifiCb);
2939
30- 	(void )scanNetworks ();
40+ 	//  If the network we are scanning for is found, the connection parameters will be updated
41+ 	//  automatically;
42+ 	(void )scanNetworks (); //  This is a blocking function call
43+ 
44+ 	//  Attempt to connect with either default parameters, or the updated ones after the scan
45+ 	//  completed
46+ 	if  ((sta_config.ssid  != NULL ) && (sta_config.ssid_length  != 0u ) && (sta_config.psk  != NULL ) &&
47+ 		(sta_config.psk_length  != 0u ))
3148
32- 	//  Check if the network we were seekin was found and attempt to connect to it
33- 	if  (getSoughtNetworkFound () != true ) {
49+ 	{
3450		int  ret = net_mgmt (NET_REQUEST_WIFI_CONNECT, sta_iface, &sta_config,
3551						   sizeof (struct  wifi_connect_req_params ));
3652		if  (ret) {
0 commit comments