Last active
August 30, 2023 10:13
-
-
Save Tech500/e907b3a83cc5e91a9c77db4f134da279 to your computer and use it in GitHub Desktop.
ESPAsyncWebServer --send data to web page
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Complete project code: https://github.com/Tech500/CameraRainGauge | |
#include "index1.h" //Weather HTML; do not remove | |
//index1.h --keep with your sketch file | |
const char HTML1[] PROGMEM = R"====( | |
<!DOCTYPE HTML> | |
<html> | |
<head> | |
<title>Weather Observations</title> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
</head> | |
<body> | |
<h2>Rain Gauge<br>Indianapolis, Indiana</h2> | |
<br> LastUpdate: %LASTUPDATE% | |
<br> Latitude: %GPSLAT% | |
<br> Longitude : %GPSLNG% | |
<br> Elevation: 843 Feet. | |
<br> Temperature: %TEMP% F. | |
<br> Dewpoint: %DEWPOINT% F. | |
<br> Heat Idex: %HEATINDEX% F. | |
<br> Humidity: %HUM% %% | |
<br> Barometric Pressure: %SEALEVEL% inHg. | |
<br> Difference: %DIF% inHg --Past 15 Minutes | |
<br> Rain Day : %RAINDAY% Day/mm | |
<br> Rain Hour: %RAINHOUR% Hour/mm | |
<br> Rain 5 Min : %RAINFALL% Five Min/mm | |
<br> | |
<h2>Weather Observations</h2> | |
<h3>%DTSTAMP%</h3> | |
<br> | |
<a href=http://%LINK%/SdBrowse >File Browser</a> | |
<br> | |
<a href=http://%LINK%/Graphs>Graphed Weather Observations</a> | |
<br> | |
<a href=http://%LINK%/WIFI.TXT >WiFi</a> | |
<br> | |
<a href=http://%LINK%/RTSP >Camera View</a> | |
<br> | |
<a href=http://%LINK%/README.TXT >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> | |
)===="; | |
//---------------------------------------- | |
String processor1(const String& var) | |
{ | |
//Place holders and data variables for "index1.h" | |
//Upper case are place holders in index1.h for Lower case data variables | |
if (var == F("LASTUPDATE")) | |
return lastUpdate; | |
if (var == F("GPSLAT")) | |
return String(gpslat, 5); | |
if (var == F("GPSLNG")) | |
return String(gpslng, 5); | |
if (var == F("TEMP")) | |
return String(temperature, 1); | |
if (var == F("HEATINDEX")) | |
return String(heat, 1); | |
if (var == F("DEWPOINT")) | |
return String(dew, 1); | |
if (var == F("HUM")) | |
return String(hum); | |
if (var == F("SEALEVEL")) | |
return String(currentPressure, 2); | |
if (var == F("DIF")) | |
return String(difference, 3); | |
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("LINK")) | |
return linkAddress; | |
if (var == F("CLIENTIP")) | |
return ipREMOTE.toString().c_str(); | |
return String(); | |
} | |
//------------------------------------------ | |
//ESPAsybcWebServer --send on request "/Weather" | |
serverAsync.on("/Weather", HTTP_GET, [](AsyncWebServerRequest * request) | |
{ | |
PATH = "/Weather"; | |
accessLog(); | |
if (! flag == 1) | |
{ | |
request->send_P(200, PSTR("text/html"), HTML1, processor1); //Send "indes1.h" web page with data from String "Processor1" | |
ipREMOTE = request->client()->remoteIP(); | |
} | |
end(); | |
//switchRelay = 0; //turn off camera | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment