Skip to content

Commit 07fd0fd

Browse files
net_iface: virtual disconnect method + wifi
Making disconnect method virtual and overriding it in wifi class
1 parent 9a630c4 commit 07fd0fd

4 files changed

Lines changed: 18 additions & 1 deletion

File tree

libraries/SocketWrapper/SocketHelpers.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,5 +55,5 @@ class NetworkInterface {
5555
int begin(bool blocking = true, uint64_t additional_event_mask = 0);
5656

5757
void end();
58-
bool disconnect();
58+
virtual bool disconnect();
5959
};

libraries/WiFi/src/WiFi.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,3 +109,18 @@ int32_t WiFiClass::RSSI() {
109109
}
110110
return 0;
111111
}
112+
113+
bool WiFiClass::disconnect() {
114+
int ret;
115+
if (status() == WL_CONNECTED) {
116+
ret = net_mgmt(NET_REQUEST_WIFI_DISCONNECT, netif, NULL, 0);
117+
118+
if (ret != 0) {
119+
LOG_ERR("Error on Wifi Disconnect %d", ret);
120+
}
121+
}
122+
123+
ret = NetworkInterface::disconnect();
124+
125+
return ret;
126+
}

libraries/WiFi/src/WiFi.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ class WiFiClass : public NetworkInterface {
4242

4343
String firmwareVersion();
4444

45+
bool disconnect() override;
4546
private:
4647
struct net_if *sta_iface = nullptr;
4748
struct net_if *ap_iface = nullptr;

loader/llext_exports.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ FORCE_EXPORT_SYM(net_if_get_wifi_sap);
187187
FORCE_EXPORT_SYM(net_mgmt_NET_REQUEST_WIFI_CONNECT);
188188
FORCE_EXPORT_SYM(net_mgmt_NET_REQUEST_WIFI_IFACE_STATUS);
189189
FORCE_EXPORT_SYM(net_mgmt_NET_REQUEST_WIFI_AP_ENABLE);
190+
FORCE_EXPORT_SYM(net_mgmt_NET_REQUEST_WIFI_DISCONNECT);
190191
#endif
191192

192193
#if defined(CONFIG_BT)

0 commit comments

Comments
 (0)