@@ -16,7 +16,7 @@ class WiFiClass: public NetworkInterface
1616 WiFiClass () {}
1717 ~WiFiClass () {}
1818
19- bool begin (const char * ssid, const char * passphrase, wl_enc_type security = ENC_TYPE_UNKNOWN, bool blocking = false ) {
19+ int begin (const char * ssid, const char * passphrase, wl_enc_type security = ENC_TYPE_UNKNOWN, bool blocking = true ) {
2020 sta_iface = net_if_get_wifi_sta ();
2121 netif = sta_iface;
2222 sta_config.ssid = (const uint8_t *)ssid;
@@ -37,10 +37,10 @@ class WiFiClass: public NetworkInterface
3737
3838 NetworkInterface::begin (false , NET_EVENT_WIFI_MASK);
3939 if (blocking) {
40- net_mgmt_event_wait_on_iface (sta_iface, NET_EVENT_WIFI_AP_STA_CONNECTED , NULL , NULL , NULL , K_FOREVER);
40+ net_mgmt_event_wait_on_iface (sta_iface, NET_EVENT_WIFI_CONNECT_RESULT , NULL , NULL , NULL , K_FOREVER);
4141 }
4242
43- return true ;
43+ return status () ;
4444 }
4545
4646 bool beginAP (char * ssid, char * passphrase, int channel = WIFI_CHANNEL_ANY, bool blocking = false ) {
@@ -75,14 +75,14 @@ class WiFiClass: public NetworkInterface
7575 }
7676
7777 int status () {
78- struct wifi_iface_status status = { 0 } ;
79-
80- if (net_mgmt (NET_REQUEST_WIFI_IFACE_STATUS, netif, &status ,
78+ sta_iface = net_if_get_wifi_sta () ;
79+ netif = sta_iface;
80+ if (net_mgmt (NET_REQUEST_WIFI_IFACE_STATUS, netif, &sta_state ,
8181 sizeof (struct wifi_iface_status ))) {
8282 return WL_NO_SHIELD;
8383 }
8484
85- if (status .state >= WIFI_STATE_ASSOCIATED) {
85+ if (sta_state .state >= WIFI_STATE_ASSOCIATED) {
8686 return WL_CONNECTED;
8787 } else {
8888 return WL_DISCONNECTED;
@@ -94,12 +94,28 @@ class WiFiClass: public NetworkInterface
9494 // TODO: borrow code from mbed core for scan results handling
9595 }
9696
97+ char * SSID () {
98+ if (status () == WL_CONNECTED) {
99+ return (char *)sta_state.ssid ;
100+ }
101+ return nullptr ;
102+ }
103+
104+ int32_t RSSI () {
105+ if (status () == WL_CONNECTED) {
106+ return sta_state.rssi ;
107+ }
108+ return 0 ;
109+ }
110+
97111private:
98112 struct net_if *sta_iface = nullptr ;
99113 struct net_if *ap_iface = nullptr ;
100114
101115 struct wifi_connect_req_params ap_config;
102116 struct wifi_connect_req_params sta_config;
117+
118+ struct wifi_iface_status sta_state = { 0 };
103119};
104120
105121extern WiFiClass WiFi;
0 commit comments