diff --git a/src/hasp.cpp b/src/hasp.cpp index 05b91116..1b71bff4 100644 --- a/src/hasp.cpp +++ b/src/hasp.cpp @@ -104,7 +104,7 @@ uint16_t current_page = 0; /********************** * GLOBAL FUNCTIONS **********************/ -void haspLoadPage(); +void haspLoadPage(String pages); //////////////////////////////////////////////////////////////////////////////////////////////////// /** @@ -658,6 +658,7 @@ void haspReconnect() void haspSetup(JsonObject settings) { char buffer[64]; + haspPagesPath = F("/pages.jsonl"); haspSetConfig(settings); @@ -766,7 +767,7 @@ void haspSetup(JsonObject settings) lv_obj_set_pos(obj, lv_disp_get_hor_res(NULL) / 2 - 40, lv_disp_get_ver_res(NULL) / 2 - 40 - 20); */ haspDisconnect(); - haspLoadPage(); + haspLoadPage(haspPagesPath); haspSetPage(haspStartPage); // // lv_page_set_style(page, LV_PAGE_STYLE_SB, &style_sb); /*Set the scrollbar style*/ @@ -1293,15 +1294,26 @@ void haspNewObject(const JsonObject & config) } } -void haspLoadPage() +void haspLoadPage(String pages) { + char msg[92]; + if(!SPIFFS.begin()) { - errorPrintln(F("HASP: %sFS not mounted. Failed to load /pages.jsonl")); + sprintf_P(msg, PSTR("HASP: \%sFS not mounted. Failed to load %s"), pages.c_str()); + errorPrintln(msg); return; } - debugPrintln(F("HASP: Loading /pages.jsonl")); - File file = SPIFFS.open(haspPagesPath, "r"); + if(!SPIFFS.exists(pages)) { + sprintf_P(msg, PSTR("HASP: \%sFile '%s' does not exist"), pages.c_str()); + errorPrintln(msg); + return; + } + + sprintf_P(msg, PSTR("HASP: Loading file %s"), pages.c_str()); + debugPrintln(msg); + + File file = SPIFFS.open(pages, "r"); // ReadBufferingStream bufferingStream(file, 256); DynamicJsonDocument config(256); @@ -1311,7 +1323,9 @@ void haspLoadPage() haspNewObject(config.as()); } - debugPrintln(F("HASP: /pages.jsonl loaded")); + sprintf_P(msg, PSTR("HASP: File %s loaded"), pages.c_str()); + debugPrintln(msg); + file.close(); } diff --git a/src/hasp_wifi.cpp b/src/hasp_wifi.cpp index 6677a8a9..18aab909 100644 --- a/src/hasp_wifi.cpp +++ b/src/hasp_wifi.cpp @@ -41,6 +41,20 @@ DNSServer dnsServer; // bool wifiWasConnected = false; // int8_t wifiReconnectAttempt = -20; +String wifiGetMacAddress(int start, const char * seperator) +{ + byte mac[6]; + WiFi.macAddress(mac); + String cMac = ""; + for(int i = start; i < 6; ++i) { + if(mac[i] < 0x10) cMac += "0"; + cMac += String(mac[i], HEX); + if(i < 5) cMac += seperator; + } + cMac.toUpperCase(); + return cMac; +} + void wifiConnected(IPAddress ipaddress) { char buffer[64]; @@ -115,15 +129,18 @@ void wifiSetup(JsonObject settings) wifiSetConfig(settings); if(wifiSsid == "") { + String apSsdid = F("HASP-"); + apSsdid += wifiGetMacAddress(3, ""); + WiFi.mode(WIFI_AP); - WiFi.softAP("HASP-test", "haspadmin"); + WiFi.softAP(apSsdid.c_str(), "haspadmin"); IPAddress IP = WiFi.softAPIP(); /* Setup the DNS server redirecting all the domains to the apIP */ dnsServer.setErrorReplyCode(DNSReplyCode::NoError); dnsServer.start(DNS_PORT, "*", IP); - sprintf_P(buffer, PSTR("WIFI: Setting up temporary Access Point")); + sprintf_P(buffer, PSTR("WIFI: Setting up temporary Access Point: %s"), apSsdid.c_str()); debugPrintln(buffer); sprintf_P(buffer, PSTR("WIFI: AP IP address : %s"), IP.toString().c_str()); debugPrintln(buffer); diff --git a/src/hasp_wifi.h b/src/hasp_wifi.h index 32ed79ad..725a47f0 100644 --- a/src/hasp_wifi.h +++ b/src/hasp_wifi.h @@ -10,4 +10,6 @@ void wifiStop(); bool wifiGetConfig(const JsonObject & settings); bool wifiSetConfig(const JsonObject & settings); +String wifiGetMacAddress(int start, const char * seperator); + #endif \ No newline at end of file