Skip to content

Commit c1e0d04

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

File tree

4 files changed

+49
-10
lines changed

4 files changed

+49
-10
lines changed

libraries/SocketWrapper/WiFi.cpp

Lines changed: 0 additions & 3 deletions
This file was deleted.

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

libraries/WiFi/src/WiFi.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#include "WiFi.h"
2+
3+
WiFiClass WiFi;
4+
5+
String WiFiClass::firmwareVersion() { // TODO integrate fw version detection
6+
#if defined(ARDUINO_PORTENTA_C33)
7+
return "v1.5.0"
8+
#if defined(ARDUINO_PORTENTA_H7) || defined(ARDUINO_OPTA) || defined(ARDUINO_GIGA) ||\
9+
defined(ARDUINO_NICLA_VISION) || defined(ARDUINO_NICLA_SENSE_ME)
10+
return "v0.0.0"
11+
#else
12+
return "v0.0.0";
13+
#endif
14+
}

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

Lines changed: 25 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,30 @@ 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+
111+
String firmwareVersion();
112+
97113
private:
98114
struct net_if *sta_iface = nullptr;
99115
struct net_if *ap_iface = nullptr;
100116

101117
struct wifi_connect_req_params ap_config;
102118
struct wifi_connect_req_params sta_config;
119+
120+
struct wifi_iface_status sta_state = { 0 };
103121
};
104122

105123
extern WiFiClass WiFi;

0 commit comments

Comments
 (0)