Adding SPIFFS to this project to store webpages
This commit is contained in:
parent
e97d9b98b5
commit
fe49e16934
@ -14,6 +14,7 @@
|
||||
#include <ArduinoOTA.h>
|
||||
#include "OTAsetup.h"
|
||||
#include "d_helper.h"
|
||||
#include "FS.h"
|
||||
|
||||
|
||||
//################# DISPLAY CONNECTIONS ################
|
||||
@ -55,6 +56,7 @@ void setup() {
|
||||
matrix.fillScreen(LOW); //clr screen
|
||||
|
||||
initOTA();
|
||||
SPIFFS.begin();
|
||||
|
||||
for (int i=0; i<numberOfHorizontalDisplays; i++){
|
||||
DEBUG_PRINT(F("Changing orientation of display #"));
|
||||
@ -189,32 +191,43 @@ void GetMessage() {
|
||||
if (Argument_Name == "brightness") brightness = client_response.toInt();
|
||||
}
|
||||
}
|
||||
String webpage = fileRead("/index.html");
|
||||
String ipaddress = WiFi.localIP().toString();
|
||||
webpage.replace("ipaddress", ipaddress);
|
||||
server.send(200, "text/html", webpage); // Send a response to the client to enter their inputs, if needed, Enter=defaults
|
||||
}
|
||||
|
||||
void append_page_header() {
|
||||
webpage = F("<!DOCTYPE HTML><html lang='fr'><head>");
|
||||
webpage += "<META HTTP-EQUIV='Content-Type' CONTENT='text/html; charset=utf-8'>";
|
||||
webpage += F("<title>Envoi de messages - LibreMetric</title><style>");
|
||||
webpage += F("body {width:");
|
||||
webpage += SITE_WIDTH;
|
||||
webpage += F("px;margin:0 auto;font-family:arial;font-size:14px;text-align:center;color:#776688;background-color:#F7F2Fd;}");
|
||||
webpage += F("ul{list-style-type:circle; margin:0;padding:0;overflow:hidden;background-color:#d8d8d8;font-size:14px;}");
|
||||
webpage += F("li{float:left;border-right:1px solid #bbb;}last-child {border-right:none;}");
|
||||
webpage += F("li a{display: block;padding:2px 12px;text-decoration:none;}");
|
||||
webpage += F("li a:hover{background-color:#FFFFFF;}");
|
||||
webpage += F("section {font-size:16px;}");
|
||||
webpage += F("p {background-color:#D1DBE3;font-size:16px;}");
|
||||
webpage += F("div.header,div.footer{padding:0.5em;color:white;background-color:gray;clear:left;}");
|
||||
webpage += F("h1{background-color:#d8d8d8;font-size:26px;}");
|
||||
webpage += F("h2{color:#9370DB;font-size:22px;line-height:65%;}");
|
||||
webpage += F("h3{color:#9370DB;font-size:16px;line-height:55%;}");
|
||||
webpage += F("</style></head><body><h1>LibreMetric ");
|
||||
webpage += version+"</h1>";
|
||||
}
|
||||
|
||||
void append_page_footer(){ // Saves repeating many lines of code for HTML page footers
|
||||
webpage += F("<ul><li><a href='/'>Recharger la page</a></li></ul>");
|
||||
webpage += F("</body></html>");
|
||||
String fileRead(String name){
|
||||
//read file from SPIFFS and store it as a String variable
|
||||
String contents;
|
||||
File file = SPIFFS.open(name.c_str(), "r");
|
||||
if (!file) {
|
||||
String errorMessage = "Can't open '" + name + "' !\r\n";
|
||||
DEBUG_PRINTLN(errorMessage);
|
||||
return "FILE ERROR";
|
||||
}
|
||||
else {
|
||||
|
||||
// this is going to get the number of bytes in the file and give us the value in an integer
|
||||
int fileSize = file.size();
|
||||
int chunkSize=1024;
|
||||
//This is a character array to store a chunk of the file.
|
||||
//We'll store 1024 characters at a time
|
||||
char buf[chunkSize];
|
||||
int numberOfChunks=(fileSize/chunkSize)+1;
|
||||
|
||||
int count=0;
|
||||
int remainingChunks=fileSize;
|
||||
for (int i=1; i <= numberOfChunks; i++){
|
||||
if (remainingChunks-chunkSize < 0){
|
||||
chunkSize=remainingChunks;
|
||||
}
|
||||
file.read((uint8_t *)buf, chunkSize-1);
|
||||
remainingChunks=remainingChunks-chunkSize;
|
||||
contents+=String(buf);
|
||||
}
|
||||
file.close();
|
||||
return contents;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user