Skip to content

Commit bf97e36

Browse files
committed
Add extra interface info for Printable
1 parent 4127270 commit bf97e36

File tree

6 files changed

+111
-15
lines changed

6 files changed

+111
-15
lines changed

libraries/Ethernet/src/ETH.cpp

+9-2
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@
4242
#include "esp_netif_defaults.h"
4343
#include "esp_eth_phy.h"
4444

45-
// extern void add_esp_interface_netif(esp_interface_t interface, esp_netif_t* esp_netif); /* from WiFiGeneric */
46-
4745
static ETHClass * _ethernets[3] = { NULL, NULL, NULL };
4846
static esp_event_handler_instance_t _eth_ev_instance = NULL;
4947

@@ -59,6 +57,7 @@ static void _eth_event_cb(void* arg, esp_event_base_t event_base, int32_t event_
5957
}
6058
}
6159

60+
// This callback needs to be aware of which interface it should match against
6261
static void onEthConnected(arduino_event_id_t event, arduino_event_info_t info)
6362
{
6463
if(event == ARDUINO_EVENT_ETH_CONNECTED){
@@ -747,6 +746,14 @@ void ETHClass::end(void)
747746
{
748747
destroyNetif();
749748

749+
if(_eth_ev_instance != NULL){
750+
if(esp_event_handler_unregister(ETH_EVENT, ESP_EVENT_ANY_ID, &_eth_event_cb) == ESP_OK){
751+
_eth_ev_instance = NULL;
752+
}
753+
}
754+
755+
Network.removeEvent(onEthConnected, ARDUINO_EVENT_ETH_CONNECTED);
756+
750757
if(_eth_handle != NULL){
751758
if(esp_eth_stop(_eth_handle) != ESP_OK){
752759
log_e("Failed to stop Ethernet");

libraries/Networking/src/ESP_Network_Interface.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ static ESP_Network_Interface * getNetifByEspNetif(esp_netif_t *esp_netif){
2626
return NULL;
2727
}
2828

29-
// static ESP_Network_Interface * getNetifByID(ESP_Network_Interface_ID id){
30-
// if(id < ESP_NETIF_ID_MAX){
31-
// return _interfaces[id];
32-
// }
33-
// return NULL;
34-
// }
29+
ESP_Network_Interface * getNetifByID(ESP_Network_Interface_ID id){
30+
if(id < ESP_NETIF_ID_MAX){
31+
return _interfaces[id];
32+
}
33+
return NULL;
34+
}
3535

3636
static void _ip_event_cb(void* arg, esp_event_base_t event_base, int32_t event_id, void* event_data) {
3737
if (event_base == IP_EVENT){

libraries/Networking/src/ESP_Network_Manager.cpp

+16
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66
#include "ESP_Network_Manager.h"
7+
#include "ESP_Network_Interface.h"
78
#include "esp_netif.h"
89
#include "lwip/ip_addr.h"
910
#include "lwip/dns.h"
@@ -158,4 +159,19 @@ bool ESP_Network_Manager::setHostname(const char * name)
158159
return true;
159160
}
160161

162+
ESP_Network_Interface * getNetifByID(ESP_Network_Interface_ID id);
163+
164+
size_t ESP_Network_Manager::printTo(Print & out) const {
165+
size_t bytes = 0;
166+
167+
for (int i = 0; i < ESP_NETIF_ID_MAX; ++i){
168+
ESP_Network_Interface * iface = getNetifByID((ESP_Network_Interface_ID)i);
169+
if(iface != NULL && iface->netif() != NULL){
170+
bytes += out.println(*iface);
171+
}
172+
}
173+
return bytes;
174+
}
175+
176+
161177
ESP_Network_Manager Network;

libraries/Networking/src/ESP_Network_Manager.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include "IPAddress.h"
1010
#include "WString.h"
1111

12-
class ESP_Network_Manager : public ESP_Network_Events {
12+
class ESP_Network_Manager : public ESP_Network_Events, public Printable {
1313
public:
1414
ESP_Network_Manager();
1515

@@ -18,6 +18,8 @@ class ESP_Network_Manager : public ESP_Network_Events {
1818
uint8_t * macAddress(uint8_t * mac);
1919
String macAddress();
2020

21+
size_t printTo(Print & out) const;
22+
2123
static const char * getHostname();
2224
static bool setHostname(const char * hostname);
2325
static bool hostname(const String& aHostname) { return setHostname(aHostname.c_str()); }

libraries/WiFi/src/AP.cpp

+31-1
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,37 @@ uint8_t APClass::stationCount(){
304304
}
305305

306306
size_t APClass::printDriverInfo(Print & out) const{
307-
return 0;
307+
size_t bytes = 0;
308+
wifi_config_t info;
309+
wifi_sta_list_t clients;
310+
if(!started()){
311+
return bytes;
312+
}
313+
if(esp_wifi_get_config(WIFI_IF_AP, &info) != ESP_OK){
314+
return bytes;
315+
}
316+
bytes += out.print(",");
317+
bytes += out.print((const char*)info.ap.ssid);
318+
bytes += out.print(",CH:");
319+
bytes += out.print(info.ap.channel);
320+
321+
if(info.ap.authmode == WIFI_AUTH_OPEN){ bytes += out.print(",OPEN"); }
322+
else if(info.ap.authmode == WIFI_AUTH_WEP){ bytes += out.print(",WEP"); }
323+
else if(info.ap.authmode == WIFI_AUTH_WPA_PSK){ bytes += out.print(",WWPA_PSK"); }
324+
else if(info.ap.authmode == WIFI_AUTH_WPA2_PSK){ bytes += out.print(",WWPA2_PSK"); }
325+
else if(info.ap.authmode == WIFI_AUTH_WPA_WPA2_PSK){ bytes += out.print(",WWPA_WPA2_PSK"); }
326+
else if(info.ap.authmode == WIFI_AUTH_ENTERPRISE){ bytes += out.print(",WEAP"); }
327+
else if(info.ap.authmode == WIFI_AUTH_WPA3_PSK){ bytes += out.print(",WWPA3_PSK"); }
328+
else if(info.ap.authmode == WIFI_AUTH_WPA2_WPA3_PSK){ bytes += out.print(",WWPA2_WPA3_PSK"); }
329+
else if(info.ap.authmode == WIFI_AUTH_WAPI_PSK){ bytes += out.print(",WWAPI_PSK"); }
330+
else if(info.ap.authmode == WIFI_AUTH_OWE){ bytes += out.print(",WOWE"); }
331+
else if(info.ap.authmode == WIFI_AUTH_WPA3_ENT_192){ bytes += out.print(",WWPA3_ENT_SUITE_B_192_BIT"); }
332+
333+
if(esp_wifi_ap_get_sta_list(&clients) == ESP_OK) {
334+
bytes += out.print(",STA:");
335+
bytes += out.print(clients.num);
336+
}
337+
return bytes;
308338
}
309339

310340

libraries/WiFi/src/STA.cpp

+46-5
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,7 @@ void STAClass::setSortMethod(wifi_sort_method_t sortMethod){
616616
}
617617

618618
String STAClass::SSID() const {
619-
if(WiFiGenericClass::getMode() == WIFI_MODE_NULL){
619+
if(!started()){
620620
return String();
621621
}
622622
wifi_ap_record_t info;
@@ -627,7 +627,7 @@ String STAClass::SSID() const {
627627
}
628628

629629
String STAClass::psk() const {
630-
if(WiFiGenericClass::getMode() == WIFI_MODE_NULL){
630+
if(!started()){
631631
return String();
632632
}
633633
wifi_config_t conf;
@@ -638,7 +638,7 @@ String STAClass::psk() const {
638638
uint8_t * STAClass::BSSID(uint8_t* buff){
639639
static uint8_t bssid[6];
640640
wifi_ap_record_t info;
641-
if(WiFiGenericClass::getMode() == WIFI_MODE_NULL){
641+
if(!started()){
642642
return NULL;
643643
}
644644
esp_err_t err = esp_wifi_sta_get_ap_info(&info);
@@ -668,7 +668,7 @@ String STAClass::BSSIDstr(){
668668
}
669669

670670
int8_t STAClass::RSSI(){
671-
if(WiFiGenericClass::getMode() == WIFI_MODE_NULL){
671+
if(!started()){
672672
return 0;
673673
}
674674
wifi_ap_record_t info;
@@ -679,7 +679,48 @@ int8_t STAClass::RSSI(){
679679
}
680680

681681
size_t STAClass::printDriverInfo(Print & out) const {
682-
return 0;
682+
size_t bytes = 0;
683+
wifi_ap_record_t info;
684+
if(!started()){
685+
return bytes;
686+
}
687+
if(esp_wifi_sta_get_ap_info(&info) != ESP_OK){
688+
return bytes;
689+
}
690+
bytes += out.print(",");
691+
bytes += out.print((const char*)info.ssid);
692+
bytes += out.print(",CH:");
693+
bytes += out.print(info.primary);
694+
bytes += out.print(",RSSI:");
695+
bytes += out.print(info.rssi);
696+
bytes += out.print(",");
697+
if(info.phy_11ax){
698+
bytes += out.print("AX");
699+
} else if(info.phy_11n){
700+
bytes += out.print("N");
701+
} else if(info.phy_11g){
702+
bytes += out.print("G");
703+
} else if(info.phy_11b){
704+
bytes += out.print("B");
705+
}
706+
if(info.phy_lr){
707+
bytes += out.print(",");
708+
bytes += out.print("LR");
709+
}
710+
711+
if(info.authmode == WIFI_AUTH_OPEN){ bytes += out.print(",OPEN"); }
712+
else if(info.authmode == WIFI_AUTH_WEP){ bytes += out.print(",WEP"); }
713+
else if(info.authmode == WIFI_AUTH_WPA_PSK){ bytes += out.print(",WPA_PSK"); }
714+
else if(info.authmode == WIFI_AUTH_WPA2_PSK){ bytes += out.print(",WPA2_PSK"); }
715+
else if(info.authmode == WIFI_AUTH_WPA_WPA2_PSK){ bytes += out.print(",WPA_WPA2_PSK"); }
716+
else if(info.authmode == WIFI_AUTH_ENTERPRISE){ bytes += out.print(",EAP"); }
717+
else if(info.authmode == WIFI_AUTH_WPA3_PSK){ bytes += out.print(",WPA3_PSK"); }
718+
else if(info.authmode == WIFI_AUTH_WPA2_WPA3_PSK){ bytes += out.print(",WPA2_WPA3_PSK"); }
719+
else if(info.authmode == WIFI_AUTH_WAPI_PSK){ bytes += out.print(",WAPI_PSK"); }
720+
else if(info.authmode == WIFI_AUTH_OWE){ bytes += out.print(",OWE"); }
721+
else if(info.authmode == WIFI_AUTH_WPA3_ENT_192){ bytes += out.print(",WPA3_ENT_SUITE_B_192_BIT"); }
722+
723+
return bytes;
683724
}
684725

685726
/**

0 commit comments

Comments
 (0)