Dynamic Webpages Served From Flash
Posted: Sat Jan 16, 2016 8:27 pm
Hey
Is there a way to serve dynamic webpages using (or not using) the Arduino library functions?
So far I can load static content from Flash using the file system library (FS.h):
Or serve dynamic content by creating a String variable and formatting it:
But is there a way of combining the two methods and having so called "dynamic" webpages, where variables can be substituted/formatted into static HTML templates stored in flash? The only way that I can think of is to somehow manually read the HTML file stored in flash into a char array or String variable and do all the string formatting/substitution before sending it off to the server as "text/html" file.
Is there a way to serve dynamic webpages using (or not using) the Arduino library functions?
So far I can load static content from Flash using the file system library (FS.h):
Code: Select all
String path = "/index.html";
File file = SPIFFS.open(path, "r");
size_t sent = server.streamFile(file, contentType);
file.close();
Or serve dynamic content by creating a String variable and formatting it:
Code: Select all
String html = "<p>Uptime: %02d:%02d:%02d</p>;
char buff[40];
snprintf (buff, 40, html, varHours, varMinutes, varSeconds);
server.send (200, "text/html", buff);
But is there a way of combining the two methods and having so called "dynamic" webpages, where variables can be substituted/formatted into static HTML templates stored in flash? The only way that I can think of is to somehow manually read the HTML file stored in flash into a char array or String variable and do all the string formatting/substitution before sending it off to the server as "text/html" file.