From f3d760bc8f03a58994834820a623721a23c8f7a8 Mon Sep 17 00:00:00 2001 From: Scott Baker Date: Fri, 10 Mar 2023 16:00:25 -0800 Subject: [PATCH] Add get_mac_addr --- src/WebOTA.cpp | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/src/WebOTA.cpp b/src/WebOTA.cpp index 98f7d76..c62b25d 100644 --- a/src/WebOTA.cpp +++ b/src/WebOTA.cpp @@ -215,10 +215,24 @@ String WebOTA::get_board_type() { #else String BOARD_NAME = "Unknown"; #endif - return BOARD_NAME; } +String get_mac_address() { + uint8_t mac[6]; + + // Put the addr in mac + WiFi.macAddress(mac); + + // Build a string and return it + char buf[20] = ""; + snprintf(buf, sizeof(buf), "%X:%X:%X:%X:%X:%X", mac[0],mac[1],mac[2],mac[3],mac[4],mac[5]); + + String ret = buf; + + return ret; +} + #ifdef ESP8266 int WebOTA::add_http_routes(ESP8266WebServer *server, const char *path) { #endif @@ -246,12 +260,12 @@ int WebOTA::add_http_routes(WebServer *server, const char *path) { const char* BOARD_NAME = "Unknown"; #endif - String uptime_str = human_time(millis() / 1000); - String board_type = webota.get_board_type(); - const char* mac_addr = WiFi.macAddress().c_str(); + String uptime_str = human_time(millis() / 1000); + String board_type = webota.get_board_type(); + String mac_addr = get_mac_address(); char buf[1024]; - snprintf_P(buf, sizeof(buf), INDEX_HTML, WEBOTA_VERSION, board_type, mac_addr, uptime_str.c_str()); + snprintf_P(buf, sizeof(buf), INDEX_HTML, WEBOTA_VERSION, board_type, mac_addr.c_str(), uptime_str.c_str()); html = buf; }