@@ -19,23 +19,36 @@ class WiFiClass: public NetworkInterface
19
19
WiFiClass () {}
20
20
~WiFiClass () {}
21
21
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 ) {
23
23
sta_iface = net_if_get_wifi_sta ();
24
24
netif = sta_iface;
25
25
sta_config.ssid = (const uint8_t *)ssid;
26
26
sta_config.ssid_length = strlen (ssid);
27
27
sta_config.psk = (const uint8_t *)passphrase;
28
28
sta_config.psk_length = strlen (passphrase);
29
29
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
+
30
40
// Register the Wi-Fi event callback
31
41
net_mgmt_init_event_callback (&wifiCb, scanEventDispatcher, NET_EVENT_WIFI_SCAN_RESULT | NET_EVENT_WIFI_SCAN_DONE);
32
42
33
43
net_mgmt_add_event_callback (&wifiCb);
34
44
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 ))
36
51
37
- // Check if the network we were seekin was found and attempt to connect to it
38
- if (getSoughtNetworkFound () != true )
39
52
{
40
53
int ret = net_mgmt (NET_REQUEST_WIFI_CONNECT, sta_iface, &sta_config,
41
54
sizeof (struct wifi_connect_req_params ));
0 commit comments