Skip to content

Commit

Permalink
New Fields 2
Browse files Browse the repository at this point in the history
  • Loading branch information
omersiar committed Feb 28, 2018
1 parent 98b0a37 commit 883a3b4
Show file tree
Hide file tree
Showing 13 changed files with 452 additions and 390 deletions.
Binary file modified bin/firmware.bin
Binary file not shown.
2 changes: 1 addition & 1 deletion src/glyphicons-halflings-regular.woff.gz.h

Large diffs are not rendered by default.

7 changes: 3 additions & 4 deletions src/index.html.gz.h

Large diffs are not rendered by default.

96 changes: 93 additions & 3 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,13 @@

// Include the header file we create with gulp
#include "glyphicons-halflings-regular.woff.gz.h"
#include "index.html.gz.h"
#include "required.css.gz.h"
#include "required.js.gz.h"
#include "esprfid.js.gz.h"

#include "index.html.gz.h"
#include "login.html.gz.h"
#include "status.htm.gz.h"

#ifdef ESP8266
extern "C" {
Expand All @@ -70,6 +74,8 @@ bool activateRelay = false;
bool inAPMode = false;
bool isWifiConnected = false;
int autoRestartIntervalSeconds = 0;
// Variable to hold the last modification datetime
char last_modified[50];

bool wifiDisabled = true;
bool doDisableWifi = false;
Expand Down Expand Up @@ -902,52 +908,136 @@ void setupWebServer() {
// Inspect impact on memory, firmware size.

server.on("/fonts/glyphicons-halflings-regular.woff", HTTP_GET, [](AsyncWebServerRequest * request) {
// Check if the client already has the same version and respond with a 304 (Not modified)
if (request->header("If-Modified-Since").equals(last_modified)) {
request->send(304);

} else {
// Dump the byte array in PROGMEM with a 200 HTTP code (OK)
AsyncWebServerResponse * response = request->beginResponse_P(200, "font/woff", glyphicons_halflings_regular_woff_gz, glyphicons_halflings_regular_woff_gz_len);
// Tell the browswer the contemnt is Gzipped
response->addHeader("Content-Encoding", "gzip");
// And set the last-modified datetime so we can check if we need to send it again next time or not
response->addHeader("Last-Modified", last_modified);
request->send(response);
}
});

server.on("/css/required.css", HTTP_GET, [](AsyncWebServerRequest * request) {
// Check if the client already has the same version and respond with a 304 (Not modified)
if (request->header("If-Modified-Since").equals(last_modified)) {
request->send(304);

} else {
// Dump the byte array in PROGMEM with a 200 HTTP code (OK)
AsyncWebServerResponse * response = request->beginResponse_P(200, "text/css", required_css_gz, required_css_gz_len);
// Tell the browswer the contemnt is Gzipped
response->addHeader("Content-Encoding", "gzip");
// And set the last-modified datetime so we can check if we need to send it again next time or not
response->addHeader("Last-Modified", last_modified);
request->send(response);
}
});

server.on("/js/required.js", HTTP_GET, [](AsyncWebServerRequest * request) {
// Check if the client already has the same version and respond with a 304 (Not modified)
if (request->header("If-Modified-Since").equals(last_modified)) {
request->send(304);

} else {
// Dump the byte array in PROGMEM with a 200 HTTP code (OK)
AsyncWebServerResponse * response = request->beginResponse_P(200, "text/javascript", required_js_gz, required_js_gz_len);
// Tell the browswer the contemnt is Gzipped
response->addHeader("Content-Encoding", "gzip");
// And set the last-modified datetime so we can check if we need to send it again next time or not
response->addHeader("Last-Modified", last_modified);
request-> send(response);
}
});

server.on("/js/esprfid.js", HTTP_GET, [](AsyncWebServerRequest * request) {
// Check if the client already has the same version and respond with a 304 (Not modified)
if (request->header("If-Modified-Since").equals(last_modified)) {
request->send(304);

} else {
// Dump the byte array in PROGMEM with a 200 HTTP code (OK)
AsyncWebServerResponse * response = request->beginResponse_P(200, "text/javascript", esprfid_js_gz, esprfid_js_gz_len);
// Tell the browswer the contemnt is Gzipped
response->addHeader("Content-Encoding", "gzip");
// And set the last-modified datetime so we can check if we need to send it again next time or not
response->addHeader("Last-Modified", last_modified);
request-> send(response);
}
});

server.on("/index.html", HTTP_GET, [](AsyncWebServerRequest * request) {
// Check if the client already has the same version and respond with a 304 (Not modified)
if (request->header("If-Modified-Since").equals(last_modified)) {
request->send(304);

} else {
// Dump the byte array in PROGMEM with a 200 HTTP code (OK)
AsyncWebServerResponse * response = request->beginResponse_P(200, "text/html", index_html_gz, index_html_gz_len);
// Tell the browswer the contemnt is Gzipped
response->addHeader("Content-Encoding", "gzip");
// And set the last-modified datetime so we can check if we need to send it again next time or not
response->addHeader("Last-Modified", last_modified);
request->send(response);
}
});

server.on("/status.htm", HTTP_GET, [](AsyncWebServerRequest * request) {
// Check if the client already has the same version and respond with a 304 (Not modified)
if (request->header("If-Modified-Since").equals(last_modified)) {
request->send(304);

} else {
// Dump the byte array in PROGMEM with a 200 HTTP code (OK)
AsyncWebServerResponse * response = request->beginResponse_P(200, "text/html", status_htm_gz, status_htm_gz_len);
// Tell the browswer the contemnt is Gzipped
response->addHeader("Content-Encoding", "gzip");
// And set the last-modified datetime so we can check if we need to send it again next time or not
response->addHeader("Last-Modified", last_modified);
request->send(response);
}
});

server.on("/login.html", HTTP_GET, [](AsyncWebServerRequest * request) {
// Check if the client already has the same version and respond with a 304 (Not modified)
if (request->header("If-Modified-Since").equals(last_modified)) {
request->send(304);

} else {
// Dump the byte array in PROGMEM with a 200 HTTP code (OK)
AsyncWebServerResponse * response = request->beginResponse_P(200, "text/html", login_html_gz, login_html_gz_len);
// Tell the browswer the contemnt is Gzipped
response->addHeader("Content-Encoding", "gzip");
// And set the last-modified datetime so we can check if we need to send it again next time or not
response->addHeader("Last-Modified", last_modified);
request->send(response);
}
});


// HTTP basic authentication
server.on("/login", HTTP_GET, [](AsyncWebServerRequest *request){
if(!request->authenticate(http_username, http_pass))
return request->requestAuthentication();
request->send(200, "text/plain", "Login Success!");
request->send(200, "text/plain", "Success");
});

server.rewrite("/", "/index.html");
server.rewrite("/", "/login.html");

// Start Web Server
server.begin();
}

// Set things up
void setup() {
// Populate the last modification date based on build datetime
sprintf(last_modified, "%s %s GMT", __DATE__, __TIME__);

Serial.begin(115200);
Serial.println();
Serial.println(F("[ INFO ] ESP RFID v0.5"));
Expand Down
Loading

0 comments on commit 883a3b4

Please sign in to comment.