Fix update server jquery

This commit is contained in:
Just Call Me Koko
2020-02-22 18:32:41 -05:00
parent eb492c4cb7
commit bace9ecf06
6 changed files with 59 additions and 3 deletions

File diff suppressed because one or more lines are too long

View File

@@ -54,7 +54,7 @@ class Display
TFT_eSPI tft = TFT_eSPI();
TFT_eSprite img = TFT_eSprite(&tft);
TFT_eSPI_Button key[BUTTON_ARRAY_LEN];
String version_number = "v0.4.4";
String version_number = "v0.4.5";
bool printing = false;
bool loading = false;

View File

@@ -30,6 +30,14 @@ void Web::main()
delay(1);
}
// Callback for the embedded jquery.min.js page
void Web::onJavaScript(void) {
Serial.println("onJavaScript(void)");
server.setContentLength(jquery_min_js_v3_2_1_gz_len);
server.sendHeader(F("Content-Encoding"), F("gzip"));
server.send_P(200, "text/javascript", jquery_min_js_v3_2_1_gz, jquery_min_js_v3_2_1_gz_len);
}
void Web::setupOTAupdate()
{
display_obj.tft.setTextWrap(false);
@@ -65,7 +73,9 @@ void Web::setupOTAupdate()
}
Serial.println("mDNS responder started");
*/
// return javascript jquery
server.on("/jquery.min.js", HTTP_GET, onJavaScript);
/*return index page which is stored in serverIndex */
server.on("/", HTTP_GET, [this]() {
server.sendHeader("Connection", "close");

View File

@@ -11,6 +11,7 @@ Code taken from espressif ESP32 OTA Update example
#include <ESPmDNS.h>
#include <Update.h>
#include "Assets.h"
#include "Display.h"
extern Display display_obj;
@@ -72,7 +73,14 @@ class Web
*/
const char* serverIndex =
"<script src='https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js'></script>"
"<script src='/jquery.min.js'></script>"
"Because the lack of an asynchronous webserver in this Arduino sketch like 'ESPAsyncWebServer', <br/>"
"both file 'serverIndex' and 'jquery.min.js' can't be read from the webserver at the same time. <br/><br/>"
"Your web browser probably requests those two files simultaneously and therefore <br/>"
"the javascript file failed to load. By a refresh of this page, the browser cash has already <br/>"
"load 'serverIndex' file, the web browser will do a second attempt to only read the javascript file. <br/>"
"This second attempt, with an idle webserver, will be processed.<br/><br/>"
"Long story short, press F5 (refresh web browser) before uploading your firmware. <br/><br/>"
"<form method='POST' action='#' enctype='multipart/form-data' id='upload_form'>"
"<input type='file' name='update'>"
"<input type='submit' value='Update'>"
@@ -113,6 +121,7 @@ class Web
Web();
void main();
static void onJavaScript();
void setupOTAupdate();
};

Binary file not shown.