Open motters opened 1 month ago
Seem you can access netif via
auto if = (struct netif*) esp_netif_get_netif_impl(network::wifi::get_netif());
However i'm not sure how to enable MIB2_STATS
Hi @motters, thanks for addressing this. So just to confirm, for now, you only want to use the lwIP mib_stats
feature, correct?
Hi,
Yes.
How can we access mib_stats feature (struct stats_mib2_netif_ctrs) for each network interface (WiFi, Ethernet, OpenThread)? Then we can wrap some REST APIs around it.
Cheers!
Hi @motters , just ask the question how to enable the feature mib_stats in lwip
to who is responsable to LwIP, and here are the replies:
For now, we do not have a menuconfigration to enable this feature via idf.py menuconfig
. And if you want to use this feature, you can refer to here: https://docs.espressif.com/projects/esp-idf/en/stable/esp32/api-guides/lwip.html#customized-lwip-options-from-esp-idf-build-system.
I have tried this, and it might work with these two changes:
components/lwip/CMakeLists.txt
idf_component_get_property(lwip lwip COMPONENT_LIB)
target_compile_definitions(${lwip} PRIVATE "-DMIB2_STATS=1")
LWIP_STATS
via idf.py menuconfig
then build your apps.
Please have a try. The LwIP group will support to enable this feature via idf.py menuconfig
later.
Thanks @zwx1995esp I'll give this a try and report back what information can be obtained.
@zwx1995esp Sorry slow on this. I've tried the about bit still cannot access.
I cannot access the lwip_netif struct
error: invalid use of incomplete type 'esp_netif_t' {aka 'struct esp_netif_obj'} 56 | auto wifi_data = esp_netif_get_handle_from_ifkey("WIFI_STA_DEF")->lwip_netif;
I cannot include the struct esp_netif_t as it's defined with esp_netif_lwip_internal.h which is not accessible.
Hi, @motters try this:
netif *wifi_data = esp_netif_get_netif_impl(esp_netif_get_handle_from_ifkey("WIFI_STA_DEF"));
@zwx1995esp Thanks thats works netif *wifi_data = (struct netif*) esp_netif_get_netif_impl(esp_netif_get_handle_from_ifkey("WIFI_STA_DEF"));
However to gain access to wifi_data->mib2_counters
i had to open esp/v5.1/esp-idf/components/lwip/lwip/src/include/lwip/opt.h
and add #define MIB2_STATS 1
to line 2251
The code now compiles however the values within mib2_counters are always zero no matter how much data is transferred via the interface.
The code now compiles however the values within mib2_counters are always zero no matter how much data is transferred via the interface.
Hi @motters , this seems to be related to the lwIP components. you can create an issue in ESP-IDF to ask for some help from the person responsible for lwIP components.
Checklist
Feature description
It would be nice to be able to obtain interface statistics to monitor data usage.
Global stats for all interfaces seem to be available at
lwip/stats.h
easily enough. However it combines all interfaces (OpenThread, Wifi, Ethernet etc).It would be better if these stats were accessible for each interface. These seem to be available through via
stats_mib2_netif_ctrs
at:esp_netif_get_handle_from_ifkey("WIFI_STA_DEF")->lwip_netif->mib2_counters
However i cannot access this struct without getting compiler errors:
error: invalid use of incomplete type 'esp_netif_t' {aka 'struct esp_netif_obj'}
With
stats_mib2_netif_ctrs
,lwip/stats.h
andOpenThread History Functions
it would be possible to gain useful statistics on each interface.Use cases
This would help when the border router is using a cellular interface. Allowing you to keep track for any data increases and where the increase came from.
It also gives a deep in sight into the use of the OpenThread network and backbone.
Alternatives
lwip/stats.h
andOpenThread History Functions
are available but they don't give all the information such astotal number of octets received on the interface
whichstats_mib2_netif_ctrs
does.Additional context
How can we access the
stats_mib2_netif_ctrs
for each interface?