diff --git a/lib/patrix/console.cpp b/lib/patrix/console.cpp index 25d7c58..b8ca4e5 100644 --- a/lib/patrix/console.cpp +++ b/lib/patrix/console.cpp @@ -10,6 +10,8 @@ char consoleBuffer[64] = ""; char *consoleBufferW = consoleBuffer; +const char * getFlashChipMode(); + void consoleLoop() { uint8_t i = 0; while (Serial.available() > 0 && i++ < 100) { @@ -52,13 +54,56 @@ void consoleHandle(const char *cmd) { info("mqtt : reconnect mqtt"); info("debug : toggle debug log"); } else if (strcmp(cmd, "info") == 0) { - info("HOSTNAME: %17s", HOSTNAME); - info("MAC: %17s", WiFi.macAddress().c_str()); - info("IP: %17s", WiFi.localIP().toString().c_str()); - info("Gateway: %17s", WiFi.gatewayIP().toString().c_str()); - info("SSID: %17s", WiFi.SSID().c_str()); - info("BSSID: %17s", WiFi.BSSIDstr().c_str()); - info("RSSI: %17d", WiFi.RSSI()); + uint64_t millis = getUptimeMillis(); + uint64_t seconds = millis / 1000; + uint32_t minutes = seconds / 60; + uint32_t hours = minutes / 60; + uint16_t days = hours / 24; + char datetime[26]; + getDateTime(datetime, sizeof datetime); + + info("WiFi:"); + info(" hostname: %s", HOSTNAME); + info(" mac: %s", WiFi.macAddress().c_str()); + info(" ip: %s", WiFi.localIP().toString().c_str()); + info(" gateway: %s", WiFi.gatewayIP().toString().c_str()); + info(" ssid: %s", WiFi.SSID().c_str()); + info(" bssid: %s", WiFi.BSSIDstr().c_str()); + info(" rssi: %d", WiFi.RSSI()); + + info("Time:"); + info(" uptime: %dd %2dh %2dm %2ds", days, hours % 24, minutes % 60, seconds % 60); + info(" sys: %s", datetime); + + info("Chip:"); + info(" model: %s", ESP.getChipModel()); + info(" cores: %d", ESP.getChipCores()); + info(" freq: %d", ESP.getCpuFreqMHz()); + + info("Flash:"); + info(" mode: %s", getFlashChipMode()); + info(" size: %d", ESP.getFlashChipSize()); + info(" speed: %d", ESP.getFlashChipSpeed()); + + info("Heap:"); + info(" size: %d", ESP.getHeapSize()); + info(" free: %d", ESP.getFreeHeap()); + info(" minFree: %d", ESP.getMinFreeHeap()); + info(" maxAlloc: %d", ESP.getMaxAllocHeap()); + + info("PS RAM:"); + info(" size: %d", ESP.getPsramSize()); + info(" free: %d", ESP.getFreePsram()); + info(" minFree: %d", ESP.getMinFreePsram()); + info(" maxAlloc: %d", ESP.getMaxAllocPsram()); + + info("SDK:"); + info(" size: %d", ESP.getSketchSize()); + info(" free: %d", ESP.getFreeSketchSpace()); + info(" MD5: %s", ESP.getSketchMD5().c_str()); + + info("SDK:"); + info(" version: %s", ESP.getSdkVersion()); } else if (strcmp(cmd, "reboot") == 0) { info("Rebooting..."); delay(500); @@ -77,3 +122,24 @@ void consoleHandle(const char *cmd) { info("Unknown command: %s", cmd); } } + +const char * getFlashChipMode() { + switch (ESP.getFlashChipMode()) { + case FM_QIO: + return "QIO"; + case FM_QOUT: + return "QOUT"; + case FM_DIO: + return "DIO"; + case FM_DOUT: + return "DOUT"; + case FM_FAST_READ: + return "FAST_READ"; + case FM_SLOW_READ: + return "SLOW_READ"; + case FM_UNKNOWN: + return "UNKNOWN"; + default: + return "[???]"; + } +} diff --git a/lib/patrix/log.cpp b/lib/patrix/log.cpp index 6de4a63..fc4c563 100644 --- a/lib/patrix/log.cpp +++ b/lib/patrix/log.cpp @@ -1,17 +1,10 @@ #include #include "log.h" #include "mqtt.h" +#include "wifi.h" bool debugEnabled = false; -void getDateTime(char *buffer, size_t size) { - time_t now; - time(&now); - tm time{}; - localtime_r(&now, &time); - strftime(buffer, size, "%Y-%m-%d %H:%M:%S %z", &time); -} - void log(const char *level, const char *format, va_list vl) { char datetime[26]; getDateTime(datetime, sizeof datetime); diff --git a/lib/patrix/wifi.cpp b/lib/patrix/wifi.cpp index bed7cdb..da33a51 100644 --- a/lib/patrix/wifi.cpp +++ b/lib/patrix/wifi.cpp @@ -185,3 +185,22 @@ time_t correctTime(const time_t value) { bool isOlderThan(time_t time, time_t seconds) { return getTime() > correctTime(time) + seconds; } + +void getDateTime(char *buffer, size_t size) { + time_t now; + time(&now); + tm time{}; + localtime_r(&now, &time); + strftime(buffer, size, "%Y-%m-%d %H:%M:%S %z", &time); +} + +uint64_t uptimeMillis = 0; + +unsigned long uptimeLastMillis = 0; + +uint64_t getUptimeMillis() { + unsigned long now = millis(); + uptimeMillis += now - uptimeLastMillis; + uptimeLastMillis = now; + return uptimeMillis; +} diff --git a/lib/patrix/wifi.h b/lib/patrix/wifi.h index c06eae0..c31cb8a 100644 --- a/lib/patrix/wifi.h +++ b/lib/patrix/wifi.h @@ -19,4 +19,8 @@ time_t correctTime(time_t value); bool isOlderThan(time_t time, time_t seconds); +void getDateTime(char *buffer, size_t size); + +uint64_t getUptimeMillis(); + #endif