diff --git a/LibreMetric.ino b/LibreMetric.ino index 5947b8a..2abfb97 100644 --- a/LibreMetric.ino +++ b/LibreMetric.ino @@ -14,6 +14,7 @@ #include #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"); - webpage += ""; - webpage += F("Envoi de messages - LibreMetric

LibreMetric "); - webpage += version+"

"; -} - -void append_page_footer(){ // Saves repeating many lines of code for HTML page footers - webpage += F(""); - webpage += F(""); +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; + } }