SOLVED Webserver can't send large webpage to client.
Posted: Mon Jan 15, 2018 3:22 pm
New to the nodemcu and arduino. I'm having trouble with part of my code to send a string that is very long. I believe I'm runnng out of memory to send this web page. The webserver works great until the file size reachs 5.22kb and then it stops working. I know I need to buffer this date to get the full page sent but I haven't found an example that is easily explained. I know I have to break the page down into chunks and send each chunk but how. I am thinking the size of the chunks should fill one tcp packet at a time
Here's the page I'm trying to send.
This above would be the top of the page only. The code I have to fill the table in looks like the following
Any help would be greatly appreciated. Oh and the file size given is what is reported by SPIFFS
Thanks in advance.
Here's the page I'm trying to send.
Code: Select all
String page = "<!DOCTYPE html><link rel=\"icon\" type=\"image/ico\" href=\"/favicon\"><html>";
page += "<head><meta http-equiv=\"content-type\" content=\"text/html\" charset=\"UTF-8\">";
page += "<title>Fuel Acquisition System</title></head><body text=\"#000000\" vlink=\"#551A8B\" ";
page += "bgcolor=\"#99ffff\" alink=\"#EE0000\" link=\"#0000EE\"><div align=\"center\">";
page += "<font color=\"#000099\" size=\"+2\"><font size=\"+3\">Fuel Acquisition</font><br></font>";
page += "<div align=\"left\"><br></div><div align=\"left\"><p><p align =\"left\" style=\"color: ";
page += "darkblue\"><font size=\"5\"><u>System Information</u></font></p>";
page += "<div align=\"left\"><ul><ul><ul><li><div align=\"left\"><div align=\"left\"><pre>";
page += "<font color=\"#000099\" size=\"5\">Runtime:";
page += RunTime;
page += " Free Space: ";
page += T_Size;
page += " </font></pre></div></div></li></ul></ul></ul></div>";
page += "<hr color=\"#000099\" size=\"4\" width=\"100%\"><center><table border=\"3\" ";
page += "cellspacing=\"2\" cellpadding=\"2\" bgcolor= \"#ffff99\" width=\"80%\">";
page += "<br><caption><font color=\"#000099\" size=\"+1\"> ";
page += "Fuel Usage History<br></font></caption><tbody>";
///==Build dynamic grid table to be filled with historic data(FUELHISTORY)==///
page += "<tr><th>Date</th><th>Time</th><th>Gallons</th><th>Temperature</th></tr>";
This above would be the top of the page only. The code I have to fill the table in looks like the following
Code: Select all
if (spiffsActive)
{
if (SPIFFS.exists(FUELHISTORY))
{
File fuel = SPIFFS.open(FUELHISTORY, "r");
if (!fuel)
{
Serial.print("Unable To Open '");
}
else
{
String s;
Serial.println("Fuel Usage Report Viewed!");
yield();
while (fuel.position()<fuel.size())
{
s=fuel.readStringUntil('\n');
s.trim();
page += "<tr><td valign=\"Top\">";
page += s.substring(0,11);
page += "<br></td><td valign=\"Top\">";
page += s.substring(11,19);
page += "<br></td><td valign=\"Top\">";
page += s.substring(20,26);
page += "<br></td><td valign=\"Top\">";
page += s.substring(27,33);
page += "<br></td></tr>";
//PageLength = page.length();
//Serial.println(PageLength);
}
Serial.println(" ");
fuel.close();
page += "</tbody></table><br><div align=\"center\">";
page += "<form id=\"/\" action=\"/\" method=\"post\">";
page += "<input type=\"submit\" name = \"\" value=\"Back\"></form><br></div></div>";
page += "</div></body></html>";
Any help would be greatly appreciated. Oh and the file size given is what is reported by SPIFFS
Thanks in advance.