diff --git a/app_httpd.cpp b/app_httpd.cpp index 3da1553..b092322 100644 --- a/app_httpd.cpp +++ b/app_httpd.cpp @@ -35,20 +35,21 @@ extern void setLamp(int newVal); // External variables declared in main .ino extern char myName[]; extern char myVer[]; +extern IPAddress ip; +extern IPAddress net; +extern IPAddress gw; +extern bool accesspoint; +extern char apName[]; +extern bool captivePortal; +extern int httpPort; +extern int streamPort; +extern char httpURL[]; +extern char streamURL[]; extern int myRotation; extern int lampVal; -extern char streamURL[]; extern int8_t detection_enabled; extern int8_t recognition_enabled; extern bool filesystem; -extern bool accesspoint; -extern bool captivePortal; -extern char apName[]; -extern int httpPort; -extern int streamPort; -extern IPAddress ip; -extern IPAddress net; -extern IPAddress gw; extern int sketchSize; extern int sketchSpace; extern String sketchMD5; @@ -826,7 +827,7 @@ static esp_err_t index_handler(httpd_req_t *req){ char view[32] = {0,}; flashLED(75); - // See if we have a specific target (full/simple/?portal) and serve as appropriate + // See if we have a specific target (full/simple/portal) and serve as appropriate buf_len = httpd_req_get_url_query_len(req) + 1; if (buf_len > 1) { buf = (char*)malloc(buf_len); @@ -848,9 +849,6 @@ static esp_err_t index_handler(httpd_req_t *req){ } free(buf); } else { - if (captivePortal) { - strcpy(view,"simple"); - } // no target specified; default. #if defined(DEFAULT_INDEX_FULL) strcpy(view,"full"); @@ -880,9 +878,17 @@ static esp_err_t index_handler(httpd_req_t *req){ } else if(strncmp(view,"portal", sizeof(view)) == 0) { //Prototype captive portal landing page. Serial.println("Portal page requested"); + std::string s(portal_html); + size_t index; + while ((index = s.find("")) != std::string::npos) + s.replace(index, strlen(""), httpURL); + while ((index = s.find("")) != std::string::npos) + s.replace(index, strlen(""), streamURL); + while ((index = s.find("")) != std::string::npos) + s.replace(index, strlen(""), myName); httpd_resp_set_type(req, "text/html"); httpd_resp_set_hdr(req, "Content-Encoding", "identity"); - return httpd_resp_send(req, (const char *)portal_html, portal_html_len); + return httpd_resp_send(req, (const char *)s.c_str(), s.length()); } else { Serial.print("Unknown page requested: "); Serial.println(view); diff --git a/esp32-cam-webserver.ino b/esp32-cam-webserver.ino index b0a0582..012e86f 100644 --- a/esp32-cam-webserver.ino +++ b/esp32-cam-webserver.ino @@ -103,8 +103,9 @@ DNSServer dnsServer; bool captivePortal = false; char apName[64] = "Undefined"; -// The stream URL -char streamURL[64] = {"Undefined"}; // Stream URL to pass to the app. +// The app and stream URLs +char httpURL[64] = {"Undefined"}; +char streamURL[64] = {"Undefined"}; // This will be displayed to identify the firmware char myVer[] PROGMEM = __DATE__ " @ " __TIME__; @@ -505,7 +506,6 @@ void setup() { startCameraServer(httpPort, streamPort); // Construct the app and stream URLs - char httpURL[64] = {"Unknown"}; if (httpPort != 80) { sprintf(httpURL, "http://%d.%d.%d.%d:%d/", ip[0], ip[1], ip[2], ip[3], httpPort); } else { diff --git a/index_other.h b/index_other.h index 5e307e8..c948231 100644 --- a/index_other.h +++ b/index_other.h @@ -2,7 +2,7 @@ * simpleviewer and streamviewer */ - const uint8_t index_simple_html[] = R"=====( +const uint8_t index_simple_html[] = R"=====( @@ -283,7 +283,7 @@ size_t index_simple_html_len = sizeof(index_simple_html)-1; /* Stream Viewer */ - const uint8_t streamviewer_html[] = R"=====( +const uint8_t streamviewer_html[] = R"=====( @@ -433,28 +433,31 @@ size_t index_simple_html_len = sizeof(index_simple_html)-1; size_t streamviewer_html_len = sizeof(streamviewer_html)-1; -/* Prototype Captive Portal page */ +/* Prototype Captive Portal page + we replace the <> delimited strings with correct values as it is served */ - const uint8_t portal_html[] = R"=====( - - +const std::string portal_html = R"=====( + + - ESP32-CAM portal - - - - - - -

ESP32 cam access portal

-
- - + <CAMNAME> - portal + + + + + + +

- access portal

+
- Camera Details
- ESP32 cam webserver on GitHub -)====="; - -size_t portal_html_len = sizeof(portal_html)-1; + Camera Details
+ +)=====";