Refactor html serving
This commit is contained in:
parent
379dff1d22
commit
19e67cb678
@ -1025,32 +1025,9 @@ void WebServerHandler::webHandlePageNotFound() {
|
|||||||
_server->send(404, "text/plain", F("URL not found"));
|
_server->send(404, "text/plain", F("URL not found"));
|
||||||
}
|
}
|
||||||
|
|
||||||
int indexHtmLength = 0;
|
|
||||||
int configHtmLength = 0;
|
|
||||||
int calibrationHtmLength = 0;
|
|
||||||
int formatHtmLength = 0;
|
|
||||||
int testHtmLength = 0;
|
|
||||||
int aboutHtmLength = 0;
|
|
||||||
int firmwareHtmLength = 0;
|
|
||||||
|
|
||||||
bool WebServerHandler::setupWebServer() {
|
bool WebServerHandler::setupWebServer() {
|
||||||
Log.notice(F("WEB : Configuring web server." CR));
|
Log.notice(F("WEB : Configuring web server." CR));
|
||||||
|
|
||||||
_server = new ESP8266WebServer();
|
_server = new ESP8266WebServer();
|
||||||
indexHtmLength = strlen(reinterpret_cast<const char*>(&indexHtmStart[0]));
|
|
||||||
configHtmLength = strlen(reinterpret_cast<const char*>(&configHtmStart[0]));
|
|
||||||
calibrationHtmLength =
|
|
||||||
strlen(reinterpret_cast<const char*>(&calibrationHtmStart[0]));
|
|
||||||
formatHtmLength = strlen(reinterpret_cast<const char*>(&formatHtmStart[0]));
|
|
||||||
testHtmLength = strlen(reinterpret_cast<const char*>(&testHtmStart[0]));
|
|
||||||
aboutHtmLength = strlen(reinterpret_cast<const char*>(&aboutHtmStart[0]));
|
|
||||||
firmwareHtmLength =
|
|
||||||
strlen(reinterpret_cast<const char*>(&firmwareHtmStart[0]));
|
|
||||||
Log.notice(F("WEB : Embedded HTML size; index=%d, config=%d, calibration=%d, "
|
|
||||||
"format=%d, test=%d, about=%d, firmware=%d." CR),
|
|
||||||
indexHtmLength, configHtmLength, calibrationHtmLength,
|
|
||||||
formatHtmLength, testHtmLength, aboutHtmLength, firmwareHtmLength);
|
|
||||||
|
|
||||||
MDNS.begin(myConfig.getMDNS());
|
MDNS.begin(myConfig.getMDNS());
|
||||||
MDNS.addService("http", "tcp", 80);
|
MDNS.addService("http", "tcp", 80);
|
||||||
|
|
||||||
|
@ -46,7 +46,7 @@ INCBIN_EXTERN(FormatHtm);
|
|||||||
INCBIN_EXTERN(TestHtm);
|
INCBIN_EXTERN(TestHtm);
|
||||||
INCBIN_EXTERN(AboutHtm);
|
INCBIN_EXTERN(AboutHtm);
|
||||||
INCBIN_EXTERN(FirmwareHtm);
|
INCBIN_EXTERN(FirmwareHtm);
|
||||||
#else
|
#else // ESP32
|
||||||
extern const uint8_t indexHtmStart[] asm("_binary_html_index_min_htm_start");
|
extern const uint8_t indexHtmStart[] asm("_binary_html_index_min_htm_start");
|
||||||
extern const uint8_t indexHtmEnd[] asm("_binary_html_index_min_htm_end");
|
extern const uint8_t indexHtmEnd[] asm("_binary_html_index_min_htm_end");
|
||||||
extern const uint8_t configHtmStart[] asm("_binary_html_config_min_htm_start");
|
extern const uint8_t configHtmStart[] asm("_binary_html_config_min_htm_start");
|
||||||
@ -64,13 +64,6 @@ extern const uint8_t aboutHtmEnd[] asm("_binary_html_about_min_htm_end");
|
|||||||
extern const uint8_t firmwareHtmStart[] asm(
|
extern const uint8_t firmwareHtmStart[] asm(
|
||||||
"_binary_html_firmware_min_htm_start");
|
"_binary_html_firmware_min_htm_start");
|
||||||
extern const uint8_t firmwareHtmEnd[] asm("_binary_html_firmware_min_htm_end");
|
extern const uint8_t firmwareHtmEnd[] asm("_binary_html_firmware_min_htm_end");
|
||||||
extern int indexHtmLength;
|
|
||||||
extern int configHtmLength;
|
|
||||||
extern int calibrationHtmLength;
|
|
||||||
extern int formatHtmLength;
|
|
||||||
extern int testHtmLength;
|
|
||||||
extern int aboutHtmLength;
|
|
||||||
extern int firmwareHtmLength;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
class WebServerHandler {
|
class WebServerHandler {
|
||||||
@ -136,33 +129,36 @@ class WebServerHandler {
|
|||||||
_server->send_P(200, "text/html", (const char*)gFirmwareHtmData,
|
_server->send_P(200, "text/html", (const char*)gFirmwareHtmData,
|
||||||
gFirmwareHtmSize);
|
gFirmwareHtmSize);
|
||||||
}
|
}
|
||||||
#else
|
#else // ESP32
|
||||||
void webReturnIndexHtm() {
|
void webReturnIndexHtm() {
|
||||||
_server->send_P(200, "text/html", (const char*)indexHtmStart,
|
_server->send_P(200, "text/html", (const char*)indexHtmStart,
|
||||||
indexHtmLength);
|
strlen(reinterpret_cast<const char*>(&indexHtmStart[0])));
|
||||||
}
|
}
|
||||||
void webReturnConfigHtm() {
|
void webReturnConfigHtm() {
|
||||||
_server->send_P(200, "text/html", (const char*)configHtmStart,
|
_server->send_P(200, "text/html", (const char*)configHtmStart,
|
||||||
configHtmLength);
|
strlen(reinterpret_cast<const char*>(&configHtmStart[0])));
|
||||||
}
|
}
|
||||||
void webReturnCalibrationHtm() {
|
void webReturnCalibrationHtm() {
|
||||||
_server->send_P(200, "text/html", (const char*)calibrationHtmStart,
|
_server->send_P(
|
||||||
calibrationHtmLength);
|
200, "text/html", (const char*)calibrationHtmStart,
|
||||||
|
strlen(reinterpret_cast<const char*>(&calibrationHtmStart[0])));
|
||||||
}
|
}
|
||||||
void webReturnFormatHtm() {
|
void webReturnFormatHtm() {
|
||||||
_server->send_P(200, "text/html", (const char*)formatHtmStart,
|
_server->send_P(200, "text/html", (const char*)formatHtmStart,
|
||||||
formatHtmLength);
|
strlen(reinterpret_cast<const char*>(&formatHtmStart[0])));
|
||||||
}
|
}
|
||||||
void webReturnAboutHtm() {
|
void webReturnAboutHtm() {
|
||||||
_server->send_P(200, "text/html", (const char*)aboutHtmStart,
|
_server->send_P(200, "text/html", (const char*)aboutHtmStart,
|
||||||
aboutHtmLength);
|
strlen(reinterpret_cast<const char*>(&aboutHtmStart[0])));
|
||||||
}
|
}
|
||||||
void webReturnTestHtm() {
|
void webReturnTestHtm() {
|
||||||
_server->send_P(200, "text/html", (const char*)testHtmStart, testHtmLength);
|
_server->send_P(200, "text/html", (const char*)testHtmStart,
|
||||||
|
strlen(reinterpret_cast<const char*>(&testHtmStart[0])));
|
||||||
}
|
}
|
||||||
void webReturnFirmwareHtm() {
|
void webReturnFirmwareHtm() {
|
||||||
_server->send_P(200, "text/html", (const char*)firmwareHtmStart,
|
_server->send_P(
|
||||||
firmwareHtmLength);
|
200, "text/html", (const char*)firmwareHtmStart,
|
||||||
|
strlen(reinterpret_cast<const char*>(&firmwareHtmStart[0])));
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user