Add MAC/Uptime to HTML

This commit is contained in:
Scott Baker 2023-03-10 10:17:01 -08:00
parent 22c0406896
commit 940d7bd48d
2 changed files with 30 additions and 3 deletions

View File

@ -106,7 +106,8 @@ const char INDEX_HTML[] PROGMEM = R"!^!(
<p>
<b>Board:</b> %s<br />
<b>Flash:</b> %0.1f KB
<b>MAC:</b> %s<br />
<b>Uptime:</b> %s<br />
</p>
<div>
@ -220,7 +221,7 @@ int WebOTA::add_http_routes(WebServer *server, const char *path) {
if (this->custom_html != NULL) {
html = this->custom_html;
} else {
uint32_t maxSketchSpace = this->max_sketch_size();
//uint32_t maxSketchSpace = this->max_sketch_size();
#if defined(ESP8266)
const char* BOARD_NAME = "ESP8266";
@ -230,8 +231,11 @@ int WebOTA::add_http_routes(WebServer *server, const char *path) {
const char* BOARD_NAME = "Unknown";
#endif
String uptime_str = human_time(millis() / 1000);
const char* mac_addr = WiFi.macAddress().c_str();
char buf[1024];
snprintf_P(buf, sizeof(buf), INDEX_HTML, WEBOTA_VERSION, BOARD_NAME, maxSketchSpace / float(1024));
snprintf_P(buf, sizeof(buf), INDEX_HTML, WEBOTA_VERSION, BOARD_NAME, mac_addr, uptime_str.c_str());
html = buf;
}
@ -339,6 +343,28 @@ String ip2string(IPAddress ip) {
return ret;
}
String WebOTA::human_time(uint32_t sec) {
int days = (sec / 86400);
sec = sec % 86400;
int hours = (sec / 3600);
sec = sec % 3600;
int mins = (sec / 60);
sec = sec % 60;
char buf[20] = "";
if (days) {
snprintf(buf, sizeof(buf), "%d days %d hours\n", days, hours);
} else if (hours) {
snprintf(buf, sizeof(buf), "%d hours %d minutes\n", hours, mins);
} else {
snprintf(buf, sizeof(buf), "%d minutes %d seconds\n", mins, sec);
}
String ret = buf;
return ret;
}
int init_wifi(const char *ssid, const char *password, const char *mdns_hostname) {
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);

View File

@ -33,6 +33,7 @@ class WebOTA {
bool init_has_run;
char const * custom_html = NULL;
String get_ota_html();
String human_time(uint32_t sec);
long max_sketch_size();
};