Skip to content

Commit

Permalink
ESP32: Read WiFi Network Diagnostics at runtime (#10313)
Browse files Browse the repository at this point in the history
  • Loading branch information
sweetymhaiske authored Oct 15, 2021
1 parent 39e2636 commit a56c83e
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 0 deletions.
88 changes: 88 additions & 0 deletions src/platform/ESP32/ConnectivityManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include <platform/internal/GenericConnectivityManagerImpl_WiFi.cpp>
#endif

#include <esp_wifi.h>
#include <lib/support/CodeUtils.h>
#include <lib/support/logging/CHIPLogging.h>
#include <platform/internal/BLEManager.h>
Expand Down Expand Up @@ -69,5 +70,92 @@ void ConnectivityManagerImpl::_OnPlatformEvent(const ChipDeviceEvent * event)
#endif
}

#if CHIP_DEVICE_CONFIG_ENABLE_WIFI
CHIP_ERROR ConnectivityManagerImpl::_GetWiFiSecurityType(uint8_t & securityType)
{
securityType = 0;
wifi_ap_record_t ap_info;
esp_err_t err;

err = esp_wifi_sta_get_ap_info(&ap_info);
if (err == ESP_OK)
{
securityType = ap_info.authmode;
}
return CHIP_NO_ERROR;
}

CHIP_ERROR ConnectivityManagerImpl::_GetWiFiChannelNumber(uint16_t & channelNumber)
{
channelNumber = 0;
wifi_ap_record_t ap_info;
esp_err_t err;

err = esp_wifi_sta_get_ap_info(&ap_info);
if (err == ESP_OK)
{
channelNumber = ap_info.primary;
}
return CHIP_NO_ERROR;
}

CHIP_ERROR ConnectivityManagerImpl::_GetWiFiRssi(int8_t & rssi)
{
rssi = 0;
wifi_ap_record_t ap_info;
esp_err_t err;

err = esp_wifi_sta_get_ap_info(&ap_info);

if (err == ESP_OK)
{
rssi = ap_info.rssi;
}
return CHIP_NO_ERROR;
}

CHIP_ERROR ConnectivityManagerImpl::_GetWiFiBeaconLostCount(uint32_t & beaconLostCount)
{
beaconLostCount = 0;
return CHIP_NO_ERROR;
}

CHIP_ERROR ConnectivityManagerImpl::_GetWiFiCurrentMaxRate(uint64_t & currentMaxRate)
{
currentMaxRate = 0;
return CHIP_NO_ERROR;
}

CHIP_ERROR ConnectivityManagerImpl::_GetWiFiPacketMulticastRxCount(uint32_t & packetMulticastRxCount)
{
packetMulticastRxCount = 0;
return CHIP_NO_ERROR;
}

CHIP_ERROR ConnectivityManagerImpl::_GetWiFiPacketMulticastTxCount(uint32_t & packetMulticastTxCount)
{
packetMulticastTxCount = 0;
return CHIP_NO_ERROR;
}

CHIP_ERROR ConnectivityManagerImpl::_GetWiFiPacketUnicastRxCount(uint32_t & packetUnicastRxCount)
{
packetUnicastRxCount = 0;
return CHIP_NO_ERROR;
}

CHIP_ERROR ConnectivityManagerImpl::_GetWiFiPacketUnicastTxCount(uint32_t & packetUnicastTxCount)
{
packetUnicastTxCount = 0;
return CHIP_NO_ERROR;
}

CHIP_ERROR ConnectivityManagerImpl::_GetWiFiOverrunCount(uint64_t & overrunCount)
{
overrunCount = 0;
return CHIP_NO_ERROR;
}
#endif // CHIP_DEVICE_CONFIG_ENABLE_WIFI

} // namespace DeviceLayer
} // namespace chip
11 changes: 11 additions & 0 deletions src/platform/ESP32/ConnectivityManagerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,17 @@ class ConnectivityManagerImpl final : public ConnectivityManager,
void _OnWiFiScanDone();
void _OnWiFiStationProvisionChange();

CHIP_ERROR _GetWiFiSecurityType(uint8_t & securityType);
CHIP_ERROR _GetWiFiChannelNumber(uint16_t & channelNumber);
CHIP_ERROR _GetWiFiRssi(int8_t & rssi);
CHIP_ERROR _GetWiFiBeaconLostCount(uint32_t & beaconLostCount);
CHIP_ERROR _GetWiFiPacketMulticastRxCount(uint32_t & packetMulticastRxCount);
CHIP_ERROR _GetWiFiPacketMulticastTxCount(uint32_t & packetMulticastTxCount);
CHIP_ERROR _GetWiFiPacketUnicastRxCount(uint32_t & packetUnicastRxCount);
CHIP_ERROR _GetWiFiPacketUnicastTxCount(uint32_t & packetUnicastTxCount);
CHIP_ERROR _GetWiFiCurrentMaxRate(uint64_t & currentMaxRate);
CHIP_ERROR _GetWiFiOverrunCount(uint64_t & overrunCount);

// ===== Members for internal use by the following friends.

friend ConnectivityManager & ConnectivityMgr(void);
Expand Down

0 comments on commit a56c83e

Please sign in to comment.