Skip to content

Commit b460521

Browse files
Splitting the definition of Wifi interface from socket wrapper
1 parent db649d0 commit b460521

File tree

3 files changed

+33
-7
lines changed

3 files changed

+33
-7
lines changed

libraries/WiFi/library.properties

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
name=WiFi
2+
version=1.0.0
3+
author=Arduino
4+
maintainer=Arduino <[email protected]>
5+
sentence=Enables WIFI connection
6+
paragraph=With this library you can use the WiFi to connect to Internet.
7+
category=Communication
8+
url=https://github.com/arduino/ArduinoCore-zephyr/tree/master/libraries/WiFi
9+
architectures=renesas,renesas_portenta
10+
includes=WiFi.h
File renamed without changes.

libraries/SocketWrapper/WiFi.h renamed to libraries/WiFi/src/WiFi.h

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
97111
private:
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

105121
extern WiFiClass WiFi;

0 commit comments

Comments
 (0)