Skip to content

Commit

Permalink
Add MAC/Uptime to HTML
Browse files Browse the repository at this point in the history
  • Loading branch information
scottchiefbaker committed Mar 10, 2023
1 parent 22c0406 commit 940d7bd
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
32 changes: 29 additions & 3 deletions src/WebOTA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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";
Expand All @@ -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;
}
Expand Down Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/WebOTA.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
};

Expand Down

0 comments on commit 940d7bd

Please sign in to comment.