Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add reset reason in AboutHelper.cpp #1

Open
wants to merge 2 commits into
base: esp32
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
- SSDP (Service discovery) support in main.cpp
- LED callback in WiFiManager loop in main.cpp
- Implement other TODO's in main.cpp
- Reset reason in AboutHelper.cpp

# esp8266_milight_hub [![Build Status](https://travis-ci.org/sidoh/esp8266_milight_hub.svg?branch=master)](https://travis-ci.org/sidoh/esp8266_milight_hub) [![License][shield-license]][info-license]

Expand Down
44 changes: 34 additions & 10 deletions lib/Settings/AboutHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,47 @@ String AboutHelper::generateAboutString(bool abbreviated) {
return body;
}

char *getResetReason(void)
{
esp_reset_reason_t reset_reason = esp_reset_reason();

static char str[55];

switch (reset_reason)
{
case ESP_RST_UNKNOWN: strcpy (str, "Reset reason can not be determined"); break;
case ESP_RST_POWERON: strcpy (str, "Reset due to power-on event"); break;
case ESP_RST_EXT: strcpy (str, "Reset by external pin (not applicable for ESP32)"); break;
case ESP_RST_SW: strcpy (str, "Software reset via esp_restart"); break;
case ESP_RST_PANIC: strcpy (str, "Software reset due to exception/panic"); break;
case ESP_RST_INT_WDT: strcpy (str, "Reset (software or hardware) due to interrupt watchdog"); break;
case ESP_RST_TASK_WDT: strcpy (str, "Reset due to task watchdog"); break;
case ESP_RST_WDT: strcpy (str, "Reset due to other watchdogs"); break;
case ESP_RST_DEEPSLEEP: strcpy (str, "Reset after exiting deep sleep mode"); break;
case ESP_RST_BROWNOUT: strcpy (str, "Brownout reset (software or hardware)"); break;
case ESP_RST_SDIO: strcpy (str, "Reset over SDIO"); break;
}

return str;
}

void AboutHelper::generateAboutObject(JsonDocument& obj, bool abbreviated) {
obj["firmware"] = QUOTE(FIRMWARE_NAME);
obj["version"] = QUOTE(MILIGHT_HUB_VERSION);
obj["ip_address"] = WiFi.localIP().toString();
#ifdef ESP8266
obj["reset_reason"] = ESP.getResetReason();
#elif ESP32
// TODO get reset reason
#endif
#ifdef ESP8266
obj["reset_reason"] = ESP.getResetReason();
#elif ESP32
obj["reset_reason"] = getResetReason();
#endif

if (! abbreviated) {
obj["variant"] = QUOTE(FIRMWARE_VARIANT);
obj["free_heap"] = ESP.getFreeHeap();
#ifdef ESP8266
obj["arduino_version"] = ESP.getCoreVersion();
#elif ESP32
obj["arduino_version"] = ESP.getSdkVersion();
#endif
#ifdef ESP8266
obj["arduino_version"] = ESP.getCoreVersion();
#elif ESP32
obj["arduino_version"] = ESP.getSdkVersion();
#endif
}
}