@@ -16,7 +16,7 @@ class WiFiClass: public NetworkInterface
16
16
WiFiClass () {}
17
17
~WiFiClass () {}
18
18
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 ) {
20
20
sta_iface = net_if_get_wifi_sta ();
21
21
netif = sta_iface;
22
22
sta_config.ssid = (const uint8_t *)ssid;
@@ -37,10 +37,10 @@ class WiFiClass: public NetworkInterface
37
37
38
38
NetworkInterface::begin (false , NET_EVENT_WIFI_MASK);
39
39
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);
41
41
}
42
42
43
- return true ;
43
+ return status () ;
44
44
}
45
45
46
46
bool beginAP (char * ssid, char * passphrase, int channel = WIFI_CHANNEL_ANY, bool blocking = false ) {
@@ -75,14 +75,14 @@ class WiFiClass: public NetworkInterface
75
75
}
76
76
77
77
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 ,
81
81
sizeof (struct wifi_iface_status ))) {
82
82
return WL_NO_SHIELD;
83
83
}
84
84
85
- if (status .state >= WIFI_STATE_ASSOCIATED) {
85
+ if (sta_state .state >= WIFI_STATE_ASSOCIATED) {
86
86
return WL_CONNECTED;
87
87
} else {
88
88
return WL_DISCONNECTED;
@@ -94,12 +94,30 @@ class WiFiClass: public NetworkInterface
94
94
// TODO: borrow code from mbed core for scan results handling
95
95
}
96
96
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
+
111
+ String firmwareVersion ();
112
+
97
113
private:
98
114
struct net_if *sta_iface = nullptr ;
99
115
struct net_if *ap_iface = nullptr ;
100
116
101
117
struct wifi_connect_req_params ap_config;
102
118
struct wifi_connect_req_params sta_config;
119
+
120
+ struct wifi_iface_status sta_state = { 0 };
103
121
};
104
122
105
123
extern WiFiClass WiFi;
0 commit comments