Page 3 of 5

Re: Async Web Server --send multiline HTML?

PostPosted: Wed Oct 16, 2019 11:56 pm
by Pablo2048
So I've modified your index.h to show you what I mean (i did some html formatting and modification also):
Code: Select all//index.h
const char MAINPAGE[] PROGMEM = R"====(

    <title>Weather Observations</title>
    <meta http-equiv="refresh" content="15">

    <h2>Rain Gauge Two<br>Indianapolis, Indiana</h2>
    <br> Last Update: %LASTUPDATE%
    <br> Latitude : %GPSLAT%
    <br> Longitude : %GPSLNG%
    <br> Elevation %GPSALT% Feet.
    <br> Temperature: %TEMP% C.
    <br> Humidity: %HUM% %%
    <br> Barometric Pressure: %PRESSURE% hpa.
    <br> Rain Day : %RAINDAY% Day/mm
    <br> Rain Hour: %RAINHOUR% Hour/mm
    <br> Rain5min : %RAINFALL% Five min/mm
    <h2>Weather Observations</h2>
    <a href=http://%PUBLICIP%:%LISTENPORT/SdBrowse>File Browser</a>
    <a href=http://%PUBLICIP:%LISTENPORT%/Graphs>Graphed Weather Observations</a>
    <a href=http://%PUBLICIP%:%LISTENPORT%/README.TXT download>Server:  README</a>
    <a href=https://forum.arduino.cc/index.php?topic=606947.0>Project Discussion</a>
    <br> Client IP: %CLIENTIP%


Now you have to write your own template processor, which returns right values for all %xxx% variables inside this template. If you need more help, then let me know...

Re: Async Web Server --send multiline HTML?

PostPosted: Thu Oct 17, 2019 5:04 pm
by Sirquil
Thank you Pablo2048 for coding "index.h."

I am not having any success coding the template processor and what I have found using "Google" has not been very helpful; especially, for multiple placeholders in one html document.

Here is what I have tried probably way off...

Code: Select allString processor(const String& var)


  if(var == "Weather")

      return {
  %LASTUPDATE& : lastUpdate;
  %GPSLAT% : gps.location.lat();
  %GPSLNG% : gps.location.lng();
  %GPSALT% : gps.altitude.feet();
  %TEMP% : temp;
  %HUM% : hum;
  %PRESSURE% : pressure;
  %RAINDAY% : rainDay;
  %RAINHOUR% : rainHour;
  %RAINFALL% : rainFall;
  %DTSTAMP% : dtStamp;
  %PUBLICIP% : publicIP;
  %CLIENTIP% : client.remoteIP().toString().c_str());

   return String();


Re: Async Web Server --send multiline HTML?

PostPosted: Thu Oct 17, 2019 11:17 pm
by Pablo2048
You got it wrong. You can not return all the variables at once. Partial done example is:
Code: Select allString processor(const String& var)

  if (var == F("GPSLAT"))
    return String(gps.location.lat());
  else if (var == F("GPSLNG"))
    return String(gps.location.lng());
  else if (var == F("CLIENTIP"))
    return client.remoteIP().toString();
and so on, and so on...
  return String(F("Unknown"));

Please don't forget to use "F" macro to play nice with your RAM...


Re: Async Web Server --send multiline HTML?

PostPosted: Fri Oct 18, 2019 1:27 pm
by Sirquil
Thank you Pavel, works great!

New result.JPG
Result of new processor code.

Re-coded, String processor code:

Code: Select allString processor(const String& var)

  if(var == F("LASTUPDATE"))
      return lastUpdate;
  if(var == F("GPSLAT"))
      return String(gps.location.lat());
  if(var == F("GPSLNG"))
      return String(gps.location.lng());
  if(var == F("GPSALT"))
      return String(gps.altitude.feet());

  if(var == F("TEMP"))
      return String(temp);
  if(var == F("HUM"))
      return String(hum);
  if(var == F("PRESSURE"))
      return String(pressure);
  if(var == F("RAINDAY"))
      return String(rainDay);
  if(var == F("RAINHOUR"))
      return String(rainHour);
  if(var == F("RAINFALL"))
      return String(rainFall);
  if(var == F("DTSTAMP"))
      return dtStamp;
  if(var == F("PUBLICIP"))
      return publicIP;
  if(var == F("LISTENPORT"))
      return  String(LISTEN_PORT);
  if(var == F("CLIENTIP"))
      return client.remoteIP().toString().c_str();
  return String();

An issue remains: "return client.remoteIP().toString().c_str();" does not populate correctly..

Should return: "" not "" Trying to fix; no success; so far.