Display 'GET' date/time request on browser webpage

I want to send a 'GET' request to an ESP8266 that will retrieve the
current procesor date & time and display it on my browser webpage.
Can someone point me to a link/site/tutorial that explains how to setup the "getParam(PARAM_MESSAGE)" to let the ESP know I am requesting the system time & date?
..thanks...

 // Send a GET request to <IP>/get?message=<message>
  server.on("/get", HTTP_GET, [](AsyncWebServerRequest *request) {
    String message;
    if (request->hasParam(PARAM_MESSAGE)) {
      message = request->getParam(PARAM_MESSAGE)->value();
    } else {
      message = "What's up?";
    }
    request->send(200, "text/plain", "Hello, GET: " + message);
  });

      //get host date and time
      document.getElementById("time").innerHTML = dt.toLocaleTimeString();
      document.getElementById("date").innerHTML = dt.toLocaleDateString();

Larry,

I am assuming I substitute "date" and "time" into the Param_Message
field.
I got compile errors regarding "document" and ""dt" not being
declared in this scope. Is there a particular library file needing to be
included to link those declarations?

thanks...

Mister Ed

Here is a WEB page I use.


/*
  OK, ya ready for some fun? HTML + CSS styling + javascript all in and undebuggable environment
 
  one trick I've learned to how to debug HTML and CSS code.
 
  get all your HTML code (from html to /html) and past it into this test site
  muck with the HTML and CSS code until it's what you want
  https://www.w3schools.com/html/tryit.asp?filename=tryhtml_intro
 
  No clue how to debug javascrip other that write, compile, upload, refresh, guess, repeat
 
  I'm using class designators to set styles and id's for data updating
  for example:
  the CSS class .tabledata defines with the cell will look like
  <td><div class="tabledata" id = "switch"></div></td>
 
  the XML code will update the data where id = "switch"
  java script then uses getElementById
  document.getElementById("switch").innerHTML="Switch is OFF";
 
 
  .. now you can have the class define the look AND the class update the content, but you will then need
  a class for every data field that must be updated, here's what that will look like
 <td><div class="switch"></div></td>
 
  the XML code will update the data where class = "switch"
  java script then uses getElementsByClassName
  document.getElementsByClassName("switch")[0].style.color=text_color;
 
 
  the main general sections of a web page are the following and used here
 
  <html>
    <style>
    // dump CSS style stuff in here
    </style>
    <body>
      <header>
      // put header code for cute banners here
      </header>
      <main>
      // the buld of your web page contents
      </main>
      <footer>
      // put cute footer (c) 2021 xyz inc type thing
      </footer>
    </body>
    <script>
    // you java code between these tags
    </script>
  </html>
 
 
*/
 
//note R"KEYWORD( html page code )KEYWORD";
//again I hate strings, so char is it and this method let's us write naturally
 
//********************************************^************************************************
const char PAGE_MAIN[] PROGMEM = R"=====(
 
<!-- HTML Start of code -->
 
<!DOCTYPE html>
<html lang="en" class="js-focus-visible">
 
<title>Freezer Temperatutre</title>
 
  <style>
    table {
      position: relative;
      width:100%;
      border-spacing: 0px;
       }
    tr {
      border: 1px solid white;
      font-family: "Verdana", "Arial", sans-serif;
      font-size: 20px;
    }
    th {
      height: 20px;
      padding: 3px 15px;
      background-color: #343a40;
      color: #FFFFFF !important;
      }
    td {
      height: 20px;
       padding: 3px 15px;
    }
    .tabledata {
      font-size: 24px;
      position: relative;
      padding-left: 5px;
      padding-top: 5px;
      height:   25px;
      border-radius: 5px;
      color: #FFFFFF;
      line-height: 20px;
      transition: all 200ms ease-in-out;
      background-color: #00AA00;
    }
    .fanrpmslider {
      width: 30%;
      height: 55px;
      outline: none;
      height: 25px;
    }
    .bodytext {
      font-family: "Verdana", "Arial", sans-serif;
      font-size: 24px;
      text-align: left;
      font-weight: light;
      border-radius: 5px;
      display:inline;
    }
    .navbar {
      width: 100%;
      height: 50px;
      margin: 0;
      padding: 10px 0px;
      background-color: #FFF;
      color: #000000;
      border-bottom: 5px solid #293578;
    }
    .fixed-top {
      position: fixed;
      top: 0;
      right: 0;
      left: 0;
      z-index: 1030;
    }
    .navtitle {
      float: left;
      height: 50px;
      font-family: "Verdana", "Arial", sans-serif;
      font-size: 50px;
      font-weight: bold;
      line-height: 50px;
      padding-left: 20px;
    }
   .navheading {
     position: fixed;
     left: 60%;
     height: 50px;
     font-family: "Verdana", "Arial", sans-serif;
     font-size: 20px;
     font-weight: bold;
     line-height: 20px;
     padding-right: 20px;
   }
   .navdata {
      justify-content: flex-end;
      position: fixed;
      left: 70%;
      height: 50px;
      font-family: "Verdana", "Arial", sans-serif;
      font-size: 20px;
      font-weight: bold;
      line-height: 20px;
      padding-right: 20px;
   }
    .category {
      font-family: "Verdana", "Arial", sans-serif;
      font-weight: bold;
      font-size: 32px;
      line-height: 50px;
      padding: 20px 10px 0px 10px;
      color: #000000;
    }
    .heading {
      font-family: "Verdana", "Arial", sans-serif;
      font-weight: normal;
      font-size: 28px;
      text-align: left;
    }
    .btn {
      background-color: #444444;
      border: none;
      color: white;
      padding: 10px 20px;
      text-align: center;
      text-decoration: none;
      display: inline-block;
      font-size: 16px;
      margin: 4px 2px;
      cursor: pointer;
    }
    .foot {
      font-family: "Verdana", "Arial", sans-serif;
      font-size: 20px;
      position: relative;
      height:   30px;
      text-align: center;  
      color: #AAAAAA;
      line-height: 20px;
    }
    .container {
      max-width: 1800px;
      margin: 0 auto;
    }
    table tr:first-child th:first-child {
      border-top-left-radius: 5px;
    }
    table tr:first-child th:last-child {
      border-top-right-radius: 5px;
    }
    table tr:last-child td:first-child {
      border-bottom-left-radius: 5px;
    }
    table tr:last-child td:last-child {
      border-bottom-right-radius: 5px;
    }
 
  </style>
 
  <body style="background-color: #efefef" onload="process()">
    <header>
            <div class="navbar fixed-top">
            <div class="container">
            <div class="navtitle">Sensor Monitor</div>
            <div class="navdata" id = "date">mm/dd/yyyy</div>
            <div class="navheading">DATE</div><br>
            <div class="navdata" id = "time">00:00:00</div>
            <div class="navheading">TIME</div>
           
          </div>
          </div>
    </header>
 
    <main class="container" style="margin-top:70px">
      <div class="category">Sensor Readings</div>
      <div style="border-radius: 10px !important;">
      <table style="width:50%">
      <colgroup>
        <col span="1" style="background-color:rgb(230,230,230); width: 20%; color:#000000 ;">
        <col span="1" style="background-color:rgb(200,200,200); width: 15%; color:#000000 ;">
        <col span="1" style="background-color:rgb(180,180,180); width: 15%; color:#000000 ;">
      </colgroup>
      <col span="2"style="background-color:rgb(0,0,0); color:#FFFFFF">
      <col span="2"style="background-color:rgb(0,0,0); color:#FFFFFF">
      <col span="2"style="background-color:rgb(0,0,0); color:#FFFFFF">
 
      <tr>
        <th colspan="1"><div class="heading">Temperature</div></th>
        <th colspan="1"><div class="heading">Fahrenheit </div></th>
        <th colspan="1"><div class="heading">Celsius</div></th>
      </tr>
     
      <tr>
        <td><div class="bodytext">Freezer</div></td>
        <td><div class="tabledata" id = "b0"></div></td>
        <td><div class="tabledata" id = "v0"></div></td>
      </tr>
 
      <tr>
        <td><div class="bodytext">Outside</div></td>
        <td><div class="tabledata" id = "b1"></div></td>
        <td><div class="tabledata" id = "v1"></div></td>
      </tr>
     
      <tr>
        <td><div class="bodytext">Digital switch</div></td>
        <td><div class="tabledata" id = "switch"></div></td>
      </tr>
      </table>
    </div>
   
    <br>
    <div class="category">Sensor Controls</div>
    <br>
    <div class="bodytext">LED GPIO 4</div>
    <button type="button" class = "btn" id = "btn0" onclick="ButtonPress0()">Toggle</button>
    </div>
    <br>
    <div class="bodytext">Switch</div>
    <button type="button" class = "btn" id = "btn1" onclick="ButtonPress1()">Toggle</button>
    </div>
    <br>
    <br>
    <div class="bodytext">Fan Speed Control (RPM: <span id="fanrpm"></span>)</div>
    <br>
    <input type="range" class="fanrpmslider" min="0" max="255" value = "0" width = "0%" oninput="UpdateSlider(this.value)"/>
    <br>
    <br>
  </main>
  <footer div class="foot" id = "temp" >ESP32 Freezer WEB Page</div></footer>
 
  </body>
 
  <script type = "text/javascript">
 
    //********************************************^************************************************
    //global variable visible to all java functions
    var xmlHttp=createXmlHttpObject();
 
    //************************************************
    //function to create XML object
    function createXmlHttpObject(){
      if(window.XMLHttpRequest){
        xmlHttp=new XMLHttpRequest();
      }
      else{
        xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
      return xmlHttp;
    }
 
    //************************************************
    //function to handle button press from HTML code above
    //and send a processing string back to server
    //this processing string is use in the .on method
    function ButtonPress0() {
      var xhttp = new XMLHttpRequest();
      var message;
      //if you want to handle an immediate reply (like status from the ESP
      //handling of the button press use this code
      //since this button status from the ESP is in the main XML code
      //we don't need this
      //remember that if you want immediate processing feedbac you must send it
      //in the ESP handling function and here
      /*
      xhttp.onreadystatechange = function() {
        if (this.readyState == 4 && this.status == 200) {
          message = this.responseText;
          // update some HTML data
        }
      }
      */
      
      xhttp.open("PUT", "BUTTON_0", false);
      xhttp.send();
    }
 
 
    //************************************************
    //function to handle button press from HTML code above
    //and send a processing string back to server
    //this processing string is use in the .on method
    function ButtonPress1() {
      var xhttp = new XMLHttpRequest();
      /*
      xhttp.onreadystatechange = function() {
        if (this.readyState == 4 && this.status == 200) {
          document.getElementById("button1").innerHTML = this.responseText;
        }
      }
      */
      xhttp.open("PUT", "BUTTON_1", false);
      xhttp.send();
    }
   
    //************************************************
    function UpdateSlider(value) {
      var xhttp = new XMLHttpRequest();
      //this time i want immediate feedback to the fan speed
      //yea yea yea i realize i'm computing fan speed but the point
      //is how to give immediate feedback
      xhttp.onreadystatechange = function() {
        if (this.readyState == 4 && this.status == 200) {
          //update the web based on reply from  ESP
          document.getElementById("fanrpm").innerHTML=this.responseText;
        }
      }
      //this syntax is really weird the ? is a delimiter
      //first arg UPDATE_SLIDER is use in the .on method
      //server.on("/UPDATE_SLIDER", UpdateSlider);
      //then the second arg VALUE is use in the processing function
      //String t_state = server.arg("VALUE");
      //then + the controls value property
      xhttp.open("PUT", "UPDATE_SLIDER?VALUE="+value, true);
      xhttp.send();
    }
 
    //************************************************
    //function to handle the response from the ESP
    function response(){
      var message;
      var barwidth;
      var currentsensor;
      var xmlResponse;
      var xmldoc;
      var dt = new Date();
      var color = "#e8e8e8";
    
      //get the xml stream
      xmlResponse=xmlHttp.responseXML;
 
      //get host date and time
      document.getElementById("time").innerHTML = dt.toLocaleTimeString();
      document.getElementById("date").innerHTML = dt.toLocaleDateString();
 
      //A0
      xmldoc = xmlResponse.getElementsByTagName("B0"); //bits for A0
      message = xmldoc[0].firstChild.nodeValue;
     
      if (message > 2048){
      color = "#aa0000";
      }
      else {
        color = "#0000aa";
      }
     
      barwidth = message / 40.95;
      document.getElementById("b0").innerHTML=message;
      document.getElementById("b0").style.width=(barwidth+"%");
      //if you want to use global color set above in <style> section
      //other wise uncomment and let the value dictate the color
      //document.getElementById("b0").style.backgroundColor=color;
      //document.getElementById("b0").style.borderRadius="5px";
     
      xmldoc = xmlResponse.getElementsByTagName("V0"); //volts for A0
      message = xmldoc[0].firstChild.nodeValue;
      document.getElementById("v0").innerHTML=message;
      document.getElementById("v0").style.width=(barwidth+"%");
      //you can set color dynamically, maybe blue below a value, red above
      document.getElementById("v0").style.backgroundColor=color;
      //document.getElementById("v0").style.borderRadius="5px";
 
      //A1
      xmldoc = xmlResponse.getElementsByTagName("B1");
      message = xmldoc[0].firstChild.nodeValue;
      if (message > 2048){
      color = "#aa0000";
      }
      else {
        color = "#0000aa";
      }
      document.getElementById("b1").innerHTML=message;
      width = message / 40.95;
      document.getElementById("b1").style.width=(width+"%");
      document.getElementById("b1").style.backgroundColor=color;
      //document.getElementById("b1").style.borderRadius="5px";
     
      xmldoc = xmlResponse.getElementsByTagName("V1");
      message = xmldoc[0].firstChild.nodeValue;
      document.getElementById("v1").innerHTML=message;
      document.getElementById("v1").style.width=(width+"%");
      document.getElementById("v1").style.backgroundColor=color;
      //document.getElementById("v1").style.borderRadius="5px";
 
      xmldoc = xmlResponse.getElementsByTagName("LED");
      message = xmldoc[0].firstChild.nodeValue;
 
      if (message == 0){
        document.getElementById("btn0").innerHTML="Turn ON";
      }
      else{
        document.getElementById("btn0").innerHTML="Turn OFF";
      }
        
      xmldoc = xmlResponse.getElementsByTagName("SWITCH");
      message = xmldoc[0].firstChild.nodeValue;
      document.getElementById("switch").style.backgroundColor="rgb(200,200,200)";
      //update the text in the table
      if (message == 0){
        document.getElementById("switch").innerHTML="Switch is OFF";
        document.getElementById("btn1").innerHTML="Turn ON";
        document.getElementById("switch").style.color="#0000AA";
      }
      else {
        document.getElementById("switch").innerHTML="Switch is ON";
        document.getElementById("btn1").innerHTML="Turn OFF";
        document.getElementById("switch").style.color="#00AA00";
      }
     }
 
    //************************************************
    //general processing code for the web page to ask for an XML steam
    //this is actually why you need to keep sending data to the page to
    //force this call with stuff like this
    //server.on("/xml", SendXML);
    //otherwise the page will not request XML from the ESP, and updates will not happen
    function process(){
    
     if(xmlHttp.readyState==0 || xmlHttp.readyState==4) {
        xmlHttp.open("PUT","xml",true);
        xmlHttp.onreadystatechange=response;
        xmlHttp.send(null);
      }      
        //you may have to play with this value, big pages need more porcessing time, and hence
        //a longer timeout
        setTimeout("process()",100);
    }
 
  </script>
 
</html>
 
<!-- HTML End of code -->
 
)=====";


That looks like you are making the request with HTML code resident on your computer. I would need several liferafts to avoid drowning in that HTML endeavor.

The search continues but thanks anyway....

For completeness, here is the Arduino sketch that goes with the SuperMon.h file above.

#include "SuperMon.h" //.h file that stores your html page code


//********************************************^************************************************
// Version   YY/MM/DD    Description
// =======   ========    ===========
// 1.00      22/12/05    Running code
// 1.10      23/06/15    Added DS18B20 code
//
//********************************************^************************************************
 
/*
  - Youtube where this can be viewed:
  https://www.youtube.com/watch?v=pL3dhGtmcMY&t=1183s
 
  - This sketch came from here:
  https://github.com/KrisKasprzak/ESP32_WebPage
 
  - Web site to test the HTML code:
  https://www.w3schools.com/html/tryit.asp?filename=tryhtml_intro
 
  this example will show
  1. how to use and ESP 32 for reading pins
  2. building a web page for a client (web browser, smartphone, smartTV) to connect to
  3. sending data from the ESP to the client to update JUST changed data
  4. sending data from the web page (like a slider or button press) to the ESP to tell the ESP to do something
 
  If you are not familiar with HTML, CSS page styling, and javascript, be patient, these code platforms are
  not intuitive and syntax is very inconsitent between platforms
 
  I know of 4 ways to update a web page
  1. send the whole page--very slow updates, causes ugly page redraws and is what you see in most examples
  2. send XML data to the web page that will update just the changed data--fast updates but older method
  3. JSON strings which are similar to XML but newer method
  4. web sockets very very fast updates, but not sure all the library support is available for ESP's
 
  I use XML here...
 
  compile options
  1. esp32 dev module
  2. upload speed 921600
  3. cpu speed 240 mhz
  flash speed 80 mhz
  flash mode qio
  flash size 4mb
  partition scheme default
 
  NOTE if your ESP fails to program press the BOOT button during programm when the IDE is "looking for the ESP"
*/
 
//********************************************^************************************************
#include <OneWire.h>
#include <DallasTemperature.h>
#include <WiFi.h>           //standard library
#include <WebServer.h>      //standard library
#include "SuperMon.h"       //.h file that stores your html page code
 
//********************************************^************************************************
//GPIO where the DS18B20 is connected
const int oneWireBus = 5;
 
//Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(oneWireBus);
 
// Pass our oneWire reference to Dallas Temperature sensor
DallasTemperature sensors(&oneWire);
 
float temperatureFreezerC;
float temperatureFreezerF;
 
float temperatureOutsideC;
float temperatureOutsideF;
 
//*******************************************
//Addresses of the DS18B20s
//
//Freezer = 0x1035B58A0208009B  <-----<<<<   change to the appropriate address
uint8_t freezerAddress[8] = {0x10, 0x35, 0xB5, 0x8A, 0x02, 0x08, 0x00, 0x9B};
 
//Outside = change to the appropriate address
uint8_t outsideAddress[8] = {0x10, 0x35, 0xB5, 0x8A, 0x02, 0x08, 0x00, 0x9B};
 
//********************************************^************************************************
//here you post web pages to your homes intranet which will make page debugging easier
//as you just need to refresh the browser as opposed to reconnection to the web server
 
#define                     USE_INTRANET
 
//replace this with your homes intranet connect parameters
#define LOCAL_SSID         "abcdefg"
#define LOCAL_PASS         "xxxxxxx"
 
//once you are read to go live these settings are what you client will connect to
#define AP_SSID            "TestWebSite"
#define AP_PASS            "023456789"
 
//start your defines for pins for sensors, outputs etc.
#define PIN_OUTPUT          26 //connected to nothing but an example of a digital write from the web page
#define PIN_FAN             12 //pin 12 and is a PWM signal to control a fan speed
#define PIN_LED              4 //On board LED
#define PIN_A0              34 //some analog input sensor
#define PIN_A1              35 //some analog input sensor
 
//variables to store measure data and sensor states
bool LED0                 = false;
bool SomeOutput           = false;
 
int BitsA0                = 0;
int BitsA1                = 0;
int FanSpeed              = 0;
int FanRPM                = 0;
 
uint32_t SensorUpdate     = 0;
 
float VoltsA0             = 0;
float VoltsA1             = 0;
 
//the XML array size needs to be bigger that your maximum expected size. 2048 is way too big for this example
char XML[2048];
 
//just some buffer holder for char operations
char buf[32];
 
//********************************************^************************************************
//variable for the IP reported when you connect to your homes intranet (during debug mode)
IPAddress Actual_IP;
 
//definitions of your desired intranet created by the ESP32
IPAddress PageIP(192, 168, 1, 1);
IPAddress gateway(192, 168, 1, 1);
IPAddress subnet(255, 255, 255, 0);
IPAddress ip;
 
//*******************************************
//Set a Static IP address
//192.168.1.180
IPAddress local_IP(192, 168, 1, 180);
IPAddress primaryDNS(8, 8, 8, 8);   //optional
IPAddress secondaryDNS(8, 8, 4, 4); //optional
//*******************************************
 
// gotta create a server
WebServer server(80);
 
 
//TIMER stuff
unsigned long temperatureMillis;
 
//                                       s e t u p ( )
//********************************************^************************************************
void setup()
{
  //standard stuff here
  Serial.begin(115200);
 
  pinMode(PIN_FAN, OUTPUT);
  pinMode(PIN_LED, OUTPUT);
 
  //turn off led
  LED0 = false;
  digitalWrite(PIN_LED, LED0);
 
  //configure LED PWM functionalitites
  ledcSetup(0, 10000, 8);
  ledcAttachPin(PIN_FAN, 0);
  ledcWrite(0, FanSpeed);
 
  //if your web page or XML are large, you may not get a call back from the web page
  //and the ESP will think something has locked up and reboot the ESP
  //not sure I like this feature, actually I kinda hate it
  //disable watch dog timer 0
  disableCore0WDT();
 
  //maybe disable watch dog timer 1 if needed
  //disableCore1WDT();
 
  //just an update to progress
  Serial.println("starting server");
 
  //if you have this #define USE_INTRANET,  you will connect to your home intranet, again makes debugging easier
#ifdef USE_INTRANET
 
  //*******************************************
  //Configures to a static IP address
  if (!WiFi.config(local_IP, gateway, subnet, primaryDNS, secondaryDNS))
  {
    Serial.println("STA Failed to configure");
  }
  //*******************************************
 
  //log into the router
  WiFi.begin(LOCAL_SSID, LOCAL_PASS);
  while (WiFi.status() != WL_CONNECTED)
  {
    delay(500);
    Serial.print(".");
  }
 
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());
 
  Actual_IP = WiFi.localIP();
 
#endif
 
  //if you don't have #define USE_INTRANET, here's where you will creat and access point
  //an intranet with no internet connection. But Clients can connect to your intranet and see
  //the web page you are about to serve up
#ifndef USE_INTRANET
  WiFi.softAP(AP_SSID, AP_PASS);
  delay(100);
  WiFi.softAPConfig(PageIP, gateway, subnet);
  delay(100);
  Actual_IP = WiFi.softAPIP();
  Serial.print("IP address: "); Serial.println(Actual_IP);
 
#endif
 
  printWifiStatus();
 
  //*********************************
  //these calls will handle data coming back from your web page
  //this one is a page request, upon ESP getting / string the web page will be sent
  server.on("/", SendWebsite);
 
  //upon esp getting /XML string, ESP will build and send the XML, this is how we refresh
  //just parts of the web page
  server.on("/xml", SendXML);
 
  //upon ESP getting /UPDATE_SLIDER string, ESP will execute the UpdateSlider function
  //same notion for the following .on calls
  //add as many as you need to process incoming strings from your web page
  //as you can imagine you will need to code some javascript in your web page to send such strings
  //this process will be documented in the SuperMon.h web page code
  server.on("/UPDATE_SLIDER", UpdateSlider);
  server.on("/BUTTON_0", ProcessButton_0);
  server.on("/BUTTON_1", ProcessButton_1);
 
  //finally begin the server
  server.begin();
 
  //Start the DS18B20 sensor
  sensors.begin();
 
} //END of   setup()
 
 
//                                        l o o p ( )
//********************************************^************************************************
void loop()
{
  //************************************************
  //is it time to check the freezer temperature ?
  if (millis() - temperatureMillis >= 2000ul)
  {
    //restart this TIMER
    temperatureMillis = millis();
 
    sensors.requestTemperatures();
 
    //Freezer temperature
    temperatureFreezerC = sensors.getTempC(freezerAddress);
    //Serial.print(temperatureFreezerC);
    //Serial.println("ºC");
 
    temperatureFreezerF = sensors.getTempF(freezerAddress);
    //Serial.print(temperatureFreezerF);
    //Serial.println("ºF");
 
    //Outside temperature
    temperatureOutsideC = sensors.getTempC(outsideAddress);
    //Serial.print(temperatureOutsideC);
    //Serial.println("ºC");
 
    temperatureOutsideF = sensors.getTempF(outsideAddress);
    //Serial.print(temperatureOutsideF);
    //Serial.println("ºF");
  }
 
  //************************************************
  //you main loop that measures, processes, runs code, etc.
  //note that handling the "on" strings from the web page are NOT in the loop
  //that processing is in individual functions all managed by the wifi lib
 
  //in my example here every 50 ms, i measure some analog sensor data (my finger dragging over the pins
  //and process accordingly
  //analog input can be from temperature sensors, light sensors, digital pin sensors, etc.
  if ((millis() - SensorUpdate) >= 50)
  {
    //Serial.println("Reading Sensors");
    SensorUpdate = millis();
    BitsA0 = analogRead(PIN_A0);
    BitsA1 = analogRead(PIN_A1);
 
    //standard converion to go from 12 bit resolution reads to volts on an ESP
    VoltsA0 = BitsA0 * 3.3 / 4096;
    VoltsA1 = BitsA1 * 3.3 / 4096;
 
  }
 
  //no matter what you must call this handleClient repeatidly--otherwise the web page
  //will not get instructions to do something
  server.handleClient();
 
} //END of   loop()
 
 
//                                 U p d a t e S l i d e r ( )
//********************************************^************************************************
//function managed by an .on method to handle slider actions on the web page
//this example will get the passed string called VALUE and conver to a pwm value
//and control the fan speed
void UpdateSlider()
{
  //many I hate strings, but wifi lib uses them...
  String t_state = server.arg("VALUE");
 
  //conver the string sent from the web page to an int
  FanSpeed = t_state.toInt();
  Serial.print("UpdateSlider"); Serial.println(FanSpeed);
  //now set the PWM duty cycle
  ledcWrite(0, FanSpeed);
 
 
  //YOU MUST SEND SOMETHING BACK TO THE WEB PAGE--BASICALLY TO KEEP IT LIVE
 
  //option 1: send no information back, but at least keep the page live
  //just send nothing back
  //server.send(200, "text/plain", ""); //Send web page
 
  //option 2: send something back immediately, maybe a pass/fail indication, maybe a measured value
  //here is how you send data back immediately and NOT through the general XML page update code
  //my simple example guesses at fan speed--ideally measure it and send back real data
  //i avoid strings at all caost, hence all the code to start with "" in the buffer and build a
  //simple piece of data
  FanRPM = map(FanSpeed, 0, 255, 0, 2400);
  strcpy(buf, "");
  sprintf(buf, "%d", FanRPM);
  sprintf(buf, buf);
 
  //now send it back
  server.send(200, "text/plain", buf); //Send web page
 
} //END of   UpdateSlider()
 
 
//                               P r o c e s s B u t t o n _ 0 ( )
//********************************************^************************************************
//now process button_0 press from the web site. Typical applications are the used on the web client can
//turn on / off a light, a fan, disable something etc
void ProcessButton_0()
{
  //
  LED0 = !LED0;
  digitalWrite(PIN_LED, LED0);
 Serial.print("Button 0 "); Serial.println(LED0);
  //regardless if you want to send stuff back to client or not
  //you must have the send line--as it keeps the page running
  //if you don't want feedback from the MCU--or let the XML manage
  //sending feeback
 
  //option 1 -- keep page live but dont send any thing
  //here i don't need to send and immediate status, any status
  //like the illumination status will be send in the main XML page update
  //code
  server.send(200, "text/plain", ""); //Send web page
 
  //option 2 -- keep page live AND send a status
  //if you want to send feed back immediataly
  //note you must have reading code in the java script
  /*
    if (LED0) {
    server.send(200, "text/plain", "1"); //Send web page
    }
    else {
    server.send(200, "text/plain", "0"); //Send web page
    }
  */
 
} //END of   ProcessButton_0()
 
 
//                               P r o c e s s B u t t o n _ 1 ( )
//********************************************^************************************************
//same notion for processing button_1
void ProcessButton_1()
{
  //just a simple way to toggle a LED on/off. Much better ways to do this
  Serial.println("Button 1 press");
  SomeOutput = !SomeOutput;
 
  digitalWrite(PIN_OUTPUT, SomeOutput);
  Serial.print("Button 1 "); Serial.println(LED0);
  //regardless if you want to send stuff back to client or not
  //you must have the send line--as it keeps the page running
  //if you don't want feedback from the MCU--or send all data via XML use this method
  //sending feeback
  server.send(200, "text/plain", ""); //Send web page
 
  //if you want to send feed back immediataly
  //note you must have proper code in the java script to read this data stream
  /*
    if (some_process) {
    server.send(200, "text/plain", "SUCCESS"); //Send web page
    }
    else {
    server.send(200, "text/plain", "FAIL"); //Send web page
    }
  */
 
} //END of   ProcessButton_1()
 
 
//                                  S e n d W e b s i t e ( )
//********************************************^************************************************
//code to send the main web page
//PAGE_MAIN is a large char defined in SuperMon.h
void SendWebsite()
{
  Serial.println("sending web page");
  //you may have to play with this value, big pages need more porcessing time, and hence
  //a longer timeout that 200 ms
  server.send(200, "text/html", PAGE_MAIN);
 
} //END of   SendWebsite()
 
 
//                                      S e n d X M L ( )
//********************************************^************************************************
//code to send the main web page
//I avoid string data types at all cost hence all the char mainipulation code
void SendXML()
{
  //Serial.println("sending xml");
 
  strcpy(XML, "<?xml version = '1.0'?>\n<Data>\n");
 
  //send Freezer Temperature F'
  //one decimal place
  sprintf(buf, "<B0>%d.%d</B0>\n", (int) (temperatureFreezerF), abs((int) (temperatureFreezerF * 10)  - ((int) (temperatureFreezerF) * 10)));
  strcat(XML, buf);
  //send Freezer Temperature C'
  //one decimal place
  sprintf(buf, "<V0>%d.%d</V0>\n", (int) (temperatureFreezerC), abs((int) (temperatureFreezerC * 10)  - ((int) (temperatureFreezerC) * 10)));
  strcat(XML, buf);
 
  //send Outside Temperature F'
  //one decimal place
  sprintf(buf, "<B1>%d.%d</B1>\n", (int) (temperatureOutsideF), abs((int) (temperatureOutsideF * 10)  - ((int) (temperatureOutsideF) * 10)));
  strcat(XML, buf);
  //send Outside Temperature F'
  //one decimal place
  sprintf(buf, "<V1>%d.%d</V1>\n", (int) (temperatureOutsideC), abs((int) (temperatureOutsideC * 10)  - ((int) (temperatureOutsideC) * 10)));
  strcat(XML, buf);
 
  //show led0 status
  if (LED0)
  {
    strcat(XML, "<LED>1</LED>\n");
  }
  else
  {
    strcat(XML, "<LED>0</LED>\n");
  }
 
  if (SomeOutput)
  {
    strcat(XML, "<SWITCH>1</SWITCH>\n");
  }
  else
  {
    strcat(XML, "<SWITCH>0</SWITCH>\n");
  }
 
  strcat(XML, "</Data>\n");
  //wanna see what the XML code looks like?
  //actually print it to the serial monitor and use some text editor to get the size
  //then pad and adjust char XML[2048]; above
  Serial.println(XML);
 
  //you may have to play with this value, big pages need more porcessing time, and hence
  //a longer timeout that 200 ms
  server.send(200, "text/xml", XML);
 
} //END of  SendXML()
 
 
//                              p r i n t W i f i S t a t u s ( )
//********************************************^************************************************
//I think I got this code from the wifi example
void printWifiStatus()
{
  //print the SSID of the network you're attached to:
  Serial.print("SSID: ");
  Serial.println(WiFi.SSID());
 
  //print your WiFi shield's IP address:
  ip = WiFi.localIP();
  Serial.print("IP Address: ");
  Serial.println(ip);
 
  //print the received signal strength:
  long rssi = WiFi.RSSI();
  Serial.print("signal strength (RSSI):");
  Serial.print(rssi);
  Serial.println(" dBm");
  //print where to go in a browser:
  Serial.print("Open http://");
  Serial.println(ip);
 
} //END of   printWifiStatus()
 
 
//********************************************^************************************************
//                                       END OF CODE
//********************************************^************************************************


The WEB page (first attached above), is a char array that is easily sent from the ESP (where it resides) to the client.

const char PAGE_MAIN[] PROGMEM = R"=====( . . . )=====";

i.e. the WEB page is on the ESP.

I use a static URL so it doesn’t change.

If you are interested and you have a few beer, this is the origin of my stuff:

Larry,

Just looking at your "advertisement" makes me green with envy. All the "bells & whistles" you employ makes for an impressive presentation. I currently have several microprocessors on my homestead LAN that I actively interrogate. But my webpages are all white with the ubiquotous black lettering that just displays the descriptor and corresponding field value.

Someday I would like to embellish my webpages and yours is to be admired and considered a model to reference. Instead of the beer, I prefer Guinness Extra stout, I will imbibe the wine from my small vineyard as I peruse your HTML. LOL

:+1: :+1:

Mister Ed

OK, now you piqued my interest to anothe level! I must check out how you have done this HTML with it embedded at the ESP. :+1: :+1:

Mister Ed

The html code (post# 4) for the WEB page is in an array found between the ( and ) brackets.

This html code is sent to the client.

const char PAGE_MAIN[] PROGMEM = R"=====( . . . )=====";

The . . . represents the HTML lines of code.

I maybe should have said:

const char PAGE_MAIN[] PROGMEM = R"=====( HTML lines of code are between these brackets )=====";

This array resides in the ESP PROGMEM (program memory).


The Java script code section is at the bottom of this array.


The above linked YouTube video does an excellent job of explaining the interaction of the three sections of code
i.e.

  • Arduino code section
  • HTML code section
  • Java code section

I make it easy on myself and follow this format.


To test any WEB site changes in the code, I copy and paste it to this WEB page viewer:

Great stuff Larry! You are making me want to become a wannabee HTML student. I need to
make incorprating HTML into the ESP program memory a bucket list item. :+1:

I am very far from being a HTML expert.

However, it’s just syntax and rules that one needs to become familiar with.

Highly highly recommend you (get a bit more beer and) go thru these tutorials on learning HTML.


First thing to learn is everything is Text / String :face_with_spiral_eyes:


I’m sure you know about this site, if not, now you do ;) .

...good thing I am retired....lol

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.