Skip to content

Commit

Permalink
Portal page with hardcoded IP addresses (#69)
Browse files Browse the repository at this point in the history
  • Loading branch information
easytarget authored Oct 7, 2020
1 parent 5ced309 commit 6d5ae2e
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 39 deletions.
34 changes: 20 additions & 14 deletions app_httpd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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");
Expand Down Expand Up @@ -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("<APPURL>")) != std::string::npos)
s.replace(index, strlen("<APPURL>"), httpURL);
while ((index = s.find("<STREAMURL>")) != std::string::npos)
s.replace(index, strlen("<STREAMURL>"), streamURL);
while ((index = s.find("<CAMNAME>")) != std::string::npos)
s.replace(index, strlen("<CAMNAME>"), 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);
Expand Down
6 changes: 3 additions & 3 deletions esp32-cam-webserver.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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__;
Expand Down Expand Up @@ -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 {
Expand Down
47 changes: 25 additions & 22 deletions index_other.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* simpleviewer and streamviewer
*/

const uint8_t index_simple_html[] = R"=====(<!doctype html>
const uint8_t index_simple_html[] = R"=====(<!doctype html>
<html>
<head>
<meta charset="utf-8">
Expand Down Expand Up @@ -283,7 +283,7 @@ size_t index_simple_html_len = sizeof(index_simple_html)-1;

/* Stream Viewer */

const uint8_t streamviewer_html[] = R"=====(<!doctype html>
const uint8_t streamviewer_html[] = R"=====(<!doctype html>
<html>
<head>
<meta charset="utf-8">
Expand Down Expand Up @@ -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"=====(<!doctype html>
<html><head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
const std::string portal_html = R"=====(<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title id="title">ESP32-CAM portal</title>
<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png">
<link rel="stylesheet" type="text/css" href="/style.css">
</head>
<body>
<img src="/logo.svg" style="position: relative; float: right;">
<h1>ESP32 cam access portal</h1>
<div class="input-group">
<a href="/?view=simple" title="Click here for a simple view with minimum control" style="text-decoration: none;"><button>Simple Viewer</button></a>
<a href="/?view=full" title="Click here for the main camera page with full controls" style="text-decoration: none;"><button>Full Viewer</button></a>
<title id="title"><CAMNAME> - portal</title>
<link rel="icon" type="image/png" sizes="32x32" href="<APPURL>favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="<APPURL>favicon-16x16.png">
<link rel="stylesheet" type="text/css" href="<APPURL>style.css">
</head>
<body style="text-align: center;">
<img src="<APPURL>logo.svg" style="position: relative; float: right;">
<h1><CAMNAME> - access portal</h1>
<div class="input-group" style="margin: auto; width: max-content;">
<a href="<APPURL>?view=simple" title="Click here for a simple view with minimum control" style="text-decoration: none;" target="_blank">
<button>Simple Viewer</button></a>
<a href="<APPURL>?view=full" title="Click here for the main camera page with full controls" style="text-decoration: none;" target="_blank">
<button>Full Viewer</button></a>
<a href="<STREAMURL>view" title="Click here for the dedicated stream viewer" style="text-decoration: none;" target="_blank">
<button>Stream Viewer</button></a>
</div>
<hr>
<a href="/dump" title="Information dump page" target="_blank">Camera Details</a><br>
<a href="https://github.com/easytarget/esp32-cam-webserver" title="Code homepage on GitHub">ESP32 cam webserver on GitHub</a>
</body></html>)=====";

size_t portal_html_len = sizeof(portal_html)-1;
<a href="<APPURL>dump" title="Information dump page" target="_blank">Camera Details</a><br>
</body>
</html>)=====";

0 comments on commit 6d5ae2e

Please sign in to comment.