expose wifi sta error count and message
This commit is contained in:
@@ -109,6 +109,7 @@ wifi_ps_type_t _sleepEnabled = WIFI_PS_MIN_MODEM;
|
|||||||
std::atomic<WiFiStaStatus> _sta_status{WiFiStaStatus::NO_SHIELD};
|
std::atomic<WiFiStaStatus> _sta_status{WiFiStaStatus::NO_SHIELD};
|
||||||
std::optional<espchrono::millis_clock::time_point> _wifiConnectFailFlag;
|
std::optional<espchrono::millis_clock::time_point> _wifiConnectFailFlag;
|
||||||
uint8_t _wifiConnectFailCounter{};
|
uint8_t _wifiConnectFailCounter{};
|
||||||
|
std::string _last_sta_error_message;
|
||||||
|
|
||||||
// scan
|
// scan
|
||||||
std::optional<espchrono::millis_clock::time_point> scanStarted;
|
std::optional<espchrono::millis_clock::time_point> scanStarted;
|
||||||
@@ -132,6 +133,8 @@ const WiFiState &wifiStateMachineState{_wifiState};
|
|||||||
cpputils::Signal<> scanResultChanged{};
|
cpputils::Signal<> scanResultChanged{};
|
||||||
const std::optional<espchrono::millis_clock::time_point> &lastStaSwitchedFromConnected{_lastStaSwitchedFromConnected};
|
const std::optional<espchrono::millis_clock::time_point> &lastStaSwitchedFromConnected{_lastStaSwitchedFromConnected};
|
||||||
const std::optional<espchrono::millis_clock::time_point> &lastStaSwitchedToConnected{_lastStaSwitchedToConnected};
|
const std::optional<espchrono::millis_clock::time_point> &lastStaSwitchedToConnected{_lastStaSwitchedToConnected};
|
||||||
|
const uint8_t &sta_error_count{_wifiConnectFailCounter};
|
||||||
|
const std::string &last_sta_error_message{_last_sta_error_message};
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
#define WifiEventIdValues(x) \
|
#define WifiEventIdValues(x) \
|
||||||
@@ -1184,10 +1187,17 @@ void wifi_event_callback(const config &config, const WifiEvent &event)
|
|||||||
};
|
};
|
||||||
|
|
||||||
const auto reason = event.wifi_sta_disconnected.reason;
|
const auto reason = event.wifi_sta_disconnected.reason;
|
||||||
ESP_LOGW(TAG, "WIFI_STA_DISCONNECTED ssid=\"%.*s\" bssid=%s reason=%u(%s)",
|
{
|
||||||
ssid.size(), ssid.data(),
|
auto msg = fmt::format("{} WIFI_STA_DISCONNECTED ssid=\"{}\" bssid={} reason={}({})",
|
||||||
toString(mac_t{event.wifi_sta_disconnected.bssid}).c_str(),
|
espchrono::millis_clock::now().time_since_epoch().count(),
|
||||||
reason, reason2str(reason));
|
ssid, toString(mac_t{event.wifi_sta_disconnected.bssid}),
|
||||||
|
reason, reason2str(reason));
|
||||||
|
ESP_LOGW(TAG, "%.*s", msg.size(), msg.data());
|
||||||
|
_last_sta_error_message += msg;
|
||||||
|
_last_sta_error_message += '\n';
|
||||||
|
if (_last_sta_error_message.size() > 1024)
|
||||||
|
_last_sta_error_message = _last_sta_error_message.substr(_last_sta_error_message.size() - 1024);
|
||||||
|
}
|
||||||
|
|
||||||
switch (reason)
|
switch (reason)
|
||||||
{
|
{
|
||||||
@@ -2081,7 +2091,7 @@ wifi_config_t make_sta_config(std::string_view ssid, std::string_view password,
|
|||||||
}
|
}
|
||||||
|
|
||||||
esp_err_t wifi_sta_begin(const config &config, const wifi_entry &sta_config,
|
esp_err_t wifi_sta_begin(const config &config, const wifi_entry &sta_config,
|
||||||
int32_t channel, std::optional<mac_t> bssid, bool connect)
|
int32_t channel, std::optional<mac_t> bssid, bool connect)
|
||||||
{
|
{
|
||||||
if (const auto result = wifi_enable_sta(true, config); result != ESP_OK)
|
if (const auto result = wifi_enable_sta(true, config); result != ESP_OK)
|
||||||
{
|
{
|
||||||
|
@@ -44,6 +44,9 @@ void init(const config &config);
|
|||||||
//! Call repeatedly, approx. every 100ms
|
//! Call repeatedly, approx. every 100ms
|
||||||
void update(const config &config);
|
void update(const config &config);
|
||||||
|
|
||||||
|
extern const uint8_t &sta_error_count;
|
||||||
|
extern const std::string &last_sta_error_message;
|
||||||
|
|
||||||
//! Tells the status of the STA interface (connected, ...)
|
//! Tells the status of the STA interface (connected, ...)
|
||||||
WiFiStaStatus get_sta_status();
|
WiFiStaStatus get_sta_status();
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user