-->
Page 3 of 4

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"====(
<!DOCTYPE HTML>
<html>

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

<body>
    <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
    <br>
    <h2>Weather Observations</h2>
    <h3>%DTSTAMP%</h3>
    <br>
    <br>
    <a href=http://%PUBLICIP%:%LISTENPORT/SdBrowse>File Browser</a>
    <br>
    <br>
    <a href=http://%PUBLICIP:%LISTENPORT%/Graphs>Graphed Weather Observations</a>
    <br>
    <br>
    <a href=http://%PUBLICIP%:%LISTENPORT%/README.TXT download>Server:  README</a>
    <br>
    <br>
    <a href=https://forum.arduino.cc/index.php?topic=606947.0>Project Discussion</a>
    <br>
    <br> Client IP: %CLIENTIP%
</body>

</html>
)====";


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)
{

  Serial.println(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;
  %LISTENPORT% : LISTEN_PORT;
  %CLIENTIP% : client.remoteIP().toString().c_str());
 
  };

   return String();
}
   


William

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...

Pavel

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)
{
 
  getWeatherData();
 
  //Serial.println(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: "10.0.0.73" not "0.0.255.0." Trying to fix; no success; so far.

William