Skip to content

Commit d9d43fd

Browse files
committed
WiFi: add SSID() and RSSI()
1 parent 3ac4639 commit d9d43fd

File tree

1 file changed

+31
-17
lines changed

1 file changed

+31
-17
lines changed

libraries/SocketWrapper/WiFi.h

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -79,32 +79,46 @@ class WiFiClass : public NetworkInterface {
7979
return true;
8080
}
8181

82-
int status() {
83-
struct wifi_iface_status status = {0};
84-
85-
if (net_mgmt(NET_REQUEST_WIFI_IFACE_STATUS, netif, &status,
86-
sizeof(struct wifi_iface_status))) {
87-
return WL_NO_SHIELD;
88-
}
89-
90-
if (status.state >= WIFI_STATE_ASSOCIATED) {
91-
return WL_CONNECTED;
92-
} else {
93-
return WL_DISCONNECTED;
94-
}
95-
return WL_NO_SHIELD;
96-
}
82+
int status() {
83+
if (net_mgmt(NET_REQUEST_WIFI_IFACE_STATUS, netif, &sta_state,
84+
sizeof(struct wifi_iface_status))) {
85+
return WL_NO_SHIELD;
86+
}
87+
88+
if (sta_state.state >= WIFI_STATE_ASSOCIATED) {
89+
return WL_CONNECTED;
90+
} else {
91+
return WL_DISCONNECTED;
92+
}
93+
return WL_NO_SHIELD;
94+
}
9795

9896
int8_t scanNetworks() {
9997
// TODO: borrow code from mbed core for scan results handling
10098
}
10199

100+
char* SSID() {
101+
if (status() == WL_CONNECTED) {
102+
return (char *)sta_state.ssid;
103+
}
104+
return nullptr;
105+
}
106+
107+
int32_t RSSI() {
108+
if (status() == WL_CONNECTED) {
109+
return sta_state.rssi;
110+
}
111+
return 0;
112+
}
113+
102114
private:
103115
struct net_if *sta_iface = nullptr;
104116
struct net_if *ap_iface = nullptr;
105117

106-
struct wifi_connect_req_params ap_config;
107-
struct wifi_connect_req_params sta_config;
118+
struct wifi_connect_req_params ap_config;
119+
struct wifi_connect_req_params sta_config;
120+
121+
struct wifi_iface_status sta_state = { 0 };
108122
};
109123

110124
extern WiFiClass WiFi;

0 commit comments

Comments
 (0)