@@ -19,23 +19,36 @@ class WiFiClass: public NetworkInterface
1919 WiFiClass () {}
2020 ~WiFiClass () {}
2121
22- int begin (const char * ssid, const char * passphrase, wl_enc_type security = ENC_TYPE_UNKNOWN , bool blocking = true ) {
22+ int begin (const char * ssid, const char * passphrase, wifi_security_type security = WIFI_SECURITY_TYPE_NONE , bool blocking = true ) {
2323 sta_iface = net_if_get_wifi_sta ();
2424 netif = sta_iface;
2525 sta_config.ssid = (const uint8_t *)ssid;
2626 sta_config.ssid_length = strlen (ssid);
2727 sta_config.psk = (const uint8_t *)passphrase;
2828 sta_config.psk_length = strlen (passphrase);
2929
30+ // The user might provide the security type as well
31+ if (security != WIFI_SECURITY_TYPE_NONE){
32+ sta_config.security = security;
33+ }else {
34+ sta_config.security = WIFI_SECURITY_TYPE_PSK;
35+ }
36+ sta_config.channel = WIFI_CHANNEL_ANY;
37+ sta_config.band = WIFI_FREQ_BAND_2_4_GHZ;
38+ sta_config.bandwidth = WIFI_FREQ_BANDWIDTH_20MHZ;
39+
3040 // Register the Wi-Fi event callback
3141 net_mgmt_init_event_callback (&wifiCb, scanEventDispatcher, NET_EVENT_WIFI_SCAN_RESULT | NET_EVENT_WIFI_SCAN_DONE);
3242
3343 net_mgmt_add_event_callback (&wifiCb);
3444
35- (void )scanNetworks ();
45+ // If the network we are scanning for is found, the connection parameters will be updated automatically;
46+ (void )scanNetworks (); // This is a blocking function call
47+
48+ // Attempt to connect with either default parameters, or the updated ones after the scan completed
49+ if ((sta_config.ssid != NULL ) && (sta_config.ssid_length != 0u ) &&
50+ (sta_config.psk != NULL ) && (sta_config.psk_length != 0u ))
3651
37- // Check if the network we were seekin was found and attempt to connect to it
38- if (getSoughtNetworkFound () != true )
3952 {
4053 int ret = net_mgmt (NET_REQUEST_WIFI_CONNECT, sta_iface, &sta_config,
4154 sizeof (struct wifi_connect_req_params ));
0 commit comments