Skip to content
Merged
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
3 changes: 2 additions & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ jobs:

- name: Install PlatformIO
run: |
python -c "$(curl -fsSL https://raw.githubusercontent.com/platformio/platformio/master/scripts/get-platformio.py)"
curl -fsSL https://raw.githubusercontent.com/platformio/platformio-core-installer/master/get-platformio.py -o get-platformio.py
python get-platformio.py
echo "/home/runner/.platformio/penv/bin" >> $GITHUB_PATH

- name: Copy secrets and clear SSID
Expand Down
2 changes: 2 additions & 0 deletions include/ntptimeclient.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ class NTPTimeClient
}

static bool UpdateClockFromWeb(WiFiUDP * pUDP);

static void ShowUptime();
};


Expand Down
5 changes: 5 additions & 0 deletions src/network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,17 @@ DRAM_ATTR std::mutex NTPTimeClient::_clockMutex;
g_ptrSystem->DeviceConfig().RemovePersisted();
RemoveEffectManagerConfig();
}
else if (str.equalsIgnoreCase("uptime"))
{
NTPTimeClient::ShowUptime();
}
else
{
debugA("Unknown Command. Extended Commands:");
debugA("clock Refresh time from server");
debugA("stats Display buffers, memory, etc");
debugA("clearsettings Reset persisted user settings");
debugA("uptime Show system uptime, reset reason");
}
}
#endif
Expand Down
41 changes: 41 additions & 0 deletions src/ntptimeclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,3 +150,44 @@ bool NTPTimeClient::UpdateClockFromWeb(WiFiUDP * pUDP)

return true;
}

// Not NTP related. Convenience utility for debugging. Callable from gdb
// serial shell, or network log debugger.

void NTPTimeClient::ShowUptime()
{
struct timeval timeval = { 0 };
// Microseconds since boot. File wrap bugreport in 292 million years.
auto uptime = esp_timer_get_time();

timeval.tv_sec = uptime / MICROS_PER_SECOND;
// timeval.tv_nsec = uptime % NANOS_PER_SECOND;

char buf[128];
struct tm *tm = gmtime(&timeval.tv_sec);
// No, I don't care about leap seconds.
strftime(buf, sizeof(buf), "%X", tm);
int ndays = timeval.tv_sec / (24 * 60 * 60);
debugI("Uptime: %d days - %s", ndays, buf);

const char* reason_text = "Unknown";
esp_reset_reason_t reason = esp_reset_reason();
switch (reason)
{
case ESP_RST_POWERON: reason_text = "Power On"; break;
case ESP_RST_EXT: reason_text = "External Pin"; break;
case ESP_RST_SW: reason_text = "Software Restart"; break;
case ESP_RST_PANIC: reason_text = "Panic"; break;
case ESP_RST_INT_WDT: reason_text = "Watchdog barked"; break;
case ESP_RST_TASK_WDT: reason_text = "Task Watchdog barked"; break;
case ESP_RST_WDT: reason_text = "Other Watchdog barked"; break;
case ESP_RST_DEEPSLEEP: reason_text = "Reset in deep sleep"; break;
case ESP_RST_BROWNOUT: reason_text = "Brownout"; break;
case ESP_RST_SDIO: reason_text = "Reset over SDIO"; break;
// Documented, but not defined in ESP-IDF esp_system.h (v5.1.0) yet.
// case ESP_RST_USB: reason_text = "Reset by USB peripheral"; break;
default: reason_text = "Unknown"; break;
}
debugI("Last boot reason: (%d): %s", reason, reason_text);

}