...so how to have a combined, yet efficient webpage response to a request, which has static and dynamic content as well.
So, the server webpages are created with the same logic as a PHP server would work.
It is based on the Arduino webserver, just modified the Webserver Example
A webserver static page (cropped) example from the SD card, example.htm
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=2">
<title>Content1</title>
<style type="text/css">
.....
....
</script>
</head>
<body>
<h1>Ram</h1>
<div id="responseWin"> </div><br/>
$$$MYFREERAM$$$
<br/>
<input id="clickMe" type="button" value="Test 7" onclick="ajaxCaller(7);" />
</body>
</html>
It has a special token part, starting and ending with $$$.
So when the webserver founds a "token" while serving a static page from the SD card, it simply calls the appropiate function and sends the dynamit part of the webpage. After that it sends the remaining static part from the SD card..
memset(&tBuf,0,sizeof(tBuf));
clientCount = myFile.read(tBuf,63);
//check for token content $$$TOKEN$$$.
char* pch = strstr_P(tBuf,PSTR("$$$")); //first occurence
if (pch)
{
//found one occurence
char* pch2 = strstr_P(pch+3,PSTR("$$$")); //closing occurence
if (pch2!=NULL)
{
#ifdef ServerDEBUG
Serial.print(F("WebToken found:"));
#endif
strncpy(commandCodeText, pch+3, pch2-pch-3);
#ifdef ServerDEBUG
Serial.println(commandCodeText);
#endif
char SecBuf[65];
char ThrBuf[65];
memset(&SecBuf,0,sizeof(SecBuf));
strncpy(SecBuf,tBuf,pch-tBuf);
memset(&ThrBuf,0,sizeof(ThrBuf));
strcpy(ThrBuf,pch2+3);
client.write(SecBuf);
//executing conditional command
webTokeniser(client, commandCodeText);
client.write(ThrBuf);
clientCount = 0;
}
................
bool webTokeniser(EthernetClient thisClient, char recvcommandCodeText[])
{
if (strstr_P(recvcommandCodeText,PSTR("MYFREERAM")))
{
strcpy_P(tBuf,PSTR("<!--FREERAM TOKEN-->RAM:"));
thisClient.write(tBuf);
#ifdef ServerDEBUG
Serial.println(F("FREERAM TOKEN MODE"));
#endif
int currRam=freeRam();
//writing uptime too.
char upTimeStr[7];//="33d,23h";//uptime:33d,23h
getUpTime(upTimeStr);
sprintf (tBuf, "%d(%d)/8192, uptime:", currRam, minRam);
thisClient.write(tBuf);
thisClient.print(upTimeStr);
return true;
}
.......................
}
This was sent to the browser (cropped) as a response - the token part was discarded of course.
...........
</style>
</head>
<body>
<h1>SMART HOME</h1>
13:42:20 (CEST) 03/04/2018. RAM:1539(970)/8192, uptime:25d,17h
<span name="responseWin" id="responseWin" style="color:green;font-weight:bold"></span>
<!--
.......................
and so on....have fun...