Im starting a project for using a web browser to send simple text string to an esp i2c lcd and googled it to see if i can save any time as i kept getting errors on compiling
I found this post
it looks good, it does what i need, however I don't wish to use any sd card for a simple project, i want to store what the sd card file would normally hold in a variable called text_display
I also want this to work as an access point and have the ability to be accessed through a routers AP, so by commenting out a line it can hide its stand alone AP and use the routers AP (iv done this before couple years ago)
so to sum up however I connect to the esp as a client i would be greeted with a simple form to input 2 lines of text and that value stored into a var for outputting to an i2c lcd, Im stuck on compiling, here is just 1 example that failed...
// (c) J~NET
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x38, 16, 2);
// #define OLED_RESET 4
const char* ssid = "RouterAP";
const char* password = "SECRETPASS";
ESP8266WebServer server(80);
const int output1 = 14;
const int output2 = 12;
const int output3 = 13;
const int output4 = 15;
boolean device1 = false;
boolean device2 = false;
boolean device3 = false;
boolean device4 = false;
void handleRoot() {
//digitalWrite(led, 1);
//server.send(200, "text/plain", "hello from esp8266!");
//digitalWrite(led, 0);
String cmd;
cmd += "\r\n";
cmd += "\r\n";
//cmd += "ESP8266 Webserver
"ESP8266 Web Server Control"
";cmd += "";
cmd += "<form action="/submit">Text To Display:
<input type="text" name="text_display"> "; cmd += "";
if(device1){
cmd +=("
Device1 : ON");
}
else{
cmd +=("
Device1 : OFF");
}
if(device2){
cmd +=("
Device2 : ON");
}
else{
cmd +=("
Device2 : OFF");
}
if(device3){
cmd +=("
Device3 : ON");
}
else{
cmd +=("
Device3 : OFF");
}
if(device4){
cmd +=("
Device4 : ON");
}
else{
cmd +=("
Device4 : OFF");
}
cmd += "\r\n";
server.send(200, "text/html", cmd);
}
void handleNotFound(){
//digitalWrite(led, 1);
String message = "File Not Found\n\n";
message += "URI: ";
message += server.uri();
message += "\nMethod: ";
message += (server.method() == HTTP_GET)?"GET":"POST";
message += "\nArguments: ";
message += server.args();
message += "\n";
for (uint8_t i=0; i<server.args(); i++){
message += " " + server.argName(i) + ": " + server.arg(i) + "\n";
}
server.send(404, "text/plain", message);
//digitalWrite(led, 0);
}
void setup(void){
lcd.begin();
lcd.backlight();
lcd.print("Please Wait...");
pinMode(output1, OUTPUT);
pinMode(output2, OUTPUT);
pinMode(output3, OUTPUT);
pinMode(output4, OUTPUT);
digitalWrite(output1, LOW);
digitalWrite(output2, LOW);
digitalWrite(output3, LOW);
digitalWrite(output4, LOW);
Serial.begin(115200);
WiFi.mode(WIFI_STA); // comment out this line to use a router as an AP
WiFi.begin(ssid, password);
Serial.println("");
// by default, we'll generate the high voltage from the 3.3v line internally! (neat!)
//display.begin(SSD1306_SWITCHCAPVCC, 0x3D); // initialize with the I2C addr 0x3D (for the 128x64)
delay(2000);
// Wait for connection
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.print("Connected to ");
Serial.println(ssid);
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
if (MDNS.begin("esp8266")) {
Serial.println("MDNS responder started");
}
server.on("/", handleRoot);
server.on("/submit", handle Submit);
if (server.args() > 0 ) {
for ( uint8_t i = 0; i < server.args(); i++ ) {
if (server.argName(i) == "text_display") {
// do something here with value from server.arg(i);
// output text to serial console & lcd
Serial.println(text_display);
lcd.print("text_display");
}
}
}
server.onNotFound(handleNotFound);
server.begin();
Serial.println("HTTP server started");
}
void loop(void){
server.handleClient();
}
please ignore the outputs as that is for the previous project i mentioned from years ago that i plan to use at a later date and did not want to strip out just yet, any ideas as to a good way to do this any help would be appreciated?