This is the base snippets to allow incorporating into any sketch All declarations need to be made previously e.g. Strings......
If the Webpage files are KEPT below 2KB then there is no need to chop them up to send, just save the file in 2KB chunks...index1.htm, index2.htm etc.....then send each file consecutively......
Using lots of SPIFFS but virtually no memory or sketch space.....
The LCD is driven via Level shifters on GPIO 4 and 5, using the Standard Arduino Libraries and the ESP8266 Latest release, I have not included any of this to allow this to be used on even the -01 with limited I/O.....
The Webpage action....
// /ajax_inputs&L1=123456789&L2=&nocache=968337.7823963541 This is the returned data "123456789" on line 1 "" line 2
if (sPath.startsWith("/ajax_inputs&L1=")) // get request.....
{
tmtxt1="";
tmtxt2="";
got_text = true; // print the received text to the LCD if found
File temptext = SPIFFS.open("/temp.txt", "w");
if (temptext) {
temptext.print(sPath);
temptext.close();
delay(1);
}
else {
lcd.clear();
lcd.print("rOr Temp.TXT");
delay(10000);
}
File in = SPIFFS.open("/temp.txt", "r");
in.setTimeout(0);
Dtmtxt = in.readStringUntil('=');
tmtxt1 += in.readStringUntil('&');
Dtmtxt = in.readStringUntil('=');
tmtxt2 += in.readStringUntil('&');
in.close();
tmtxt1.replace("%20", " ");
tmtxt2.replace("%20", " ");
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(tmtxt1);
lcd.setCursor(0, 1);
lcd.print(tmtxt2);
delay(3000);
}
The LCD Webpage loader.....
if (sPath.startsWith("/lcd"))
{
// send rest of HTTP header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connection: keep-alive");
client.println();
// send web page
File webFile = SPIFFS.open("/index1.htm", "r"); // open web page file
if (webFile) {
while(webFile.available()) {
client.print(webFile.readString()); // send web page to client
}
webFile.close();
}
}
Finally the Webpage....Place this in the SPIFFS using FS Tool, name this index1.htm
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Environment Monitor Text to LCD</title>
<script>
strLine1 = "";
strLine2 = "";
function SendText()
{
nocache = "&nocache=" + Math.random() * 1000000;
var request = new XMLHttpRequest();
strLine1 = "&L1=" + document.getElementById("txt_form").line1LCD.value;
strLine2 = "&L2=" + document.getElementById("txt_form").line2LCD.value;
request.open("GET", "ajax_inputs" + strLine1 + strLine2 + nocache, true);
request.send(null);
}
</script>
<body>
<h1>Environment Monitor<BR>LCD Text Input</h1>
<BR><a href="/graph">Sensor Graph Page</a><BR><a href="/">Sensor Gauges Page</a><BR><a href="/table">Datalog Table Page</a><BR><a href="/diag">Diagnostics Information Page</a><BR>
<body onload="GetESP8266IO()">
<h1><FONT SIZE=-1>Enter text to send to ESP8266 LCD:</h1>
<form id="txt_form" name="frmText">
<label>Line 1: <input type="text" name="line1LCD" size="16" maxlength="16" /></label><br /><br />
<label>Line 2: <input type="text" name="line2LCD" size="16" maxlength="16" /></label>
</form>
<br />
<input type="submit" value="Send Text" onclick="SendText()" />
<font color="#000000"><body bgcolor="#d0d0f0"><meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes"><BR>LCD Text Input<BR>
<div style="clear:both;"><FONT SIZE=-1>environmental.monitor.log@gmail.com<BR><FONT SIZE=-2>ESP8266 With 1602 I2C LCD, DS1307, BMP180 and 2 DHT11 Peripherals Logging to SPIFFS<BR>Compiled using ver. 1.6.5-1160-gef26c5f, built on Sep 30, 2015<BR></body></html>
This is an Affenpinscher......can't be tooo serious.......
___/'¬_ /\
{_-_ ^ \_______//
/ \
\ _ _____ /
|| || |||
|| || |||
[youtube]
https://www.youtube.com/embed/j8aT7JDh2sU
[/youtube]