Now there are many ways to reply with a webpage content to a user who is accessing the web server, But Keeping in mind to use as less space as possible, I was trying something new, Since i didnt got compilation error, I am a little confused as to what might be the error,
in void data()
I am storing the html page and saving it in ROM,
void data()
{
if(SPIFFS.exists("/login.html"))
{
Serial.println();
}
else{
SPIFFS.begin();
File f=SPIFFS.open("/login.html","w");
String s="<html><head><title>AP</title><h1>Welcome to AP page</h1>\n";
s+="</head><body><form name=\"/myform\" action=\"/login\" method=\"POST\">\n";
s+="<input type=\"text\" name=\"username\" placeholder=\"username\"><br/>\n";
s+="<input type=\"password\" name=\"password\" placeholder=\"password\"><br/>\n";
s+="<input type=\"submit\" value=\"login\"></form></body></html>";
f.println(s);
f.close();
}
}
Please correct the above lines if I wrote it wrong,
After that,
I wrote some lines in void setup()
WiFi.mode(WIFI_AP_STA);//Only Access point
WiFi.softAP(ssid, password); //Start HOTspot removing password will disable security
IPAddress myIP = WiFi.softAPIP(); //Get IP address
Serial.print("HotSpt IP:");
Serial.println(myIP);
server.on("/", HTTP_GET, handleRoot); //Which routine to handle at root location
server.on("/",HTTP_POST,handlelogin);
server.onNotFound(handleerror);
server.begin();
Now I am calling void handleRoot()
I want to send the page that I wrote and saved in the /login.html
file.
so for that,
void handleRoot()
{
SPIFFS.begin();
File f=SPIFFS.open("/login.html","r");
server.send(200, "text/html",f.readStringUntil('EOF'));
}
Now once I do this and execute and load the program in ESP01, it shows me nothing,
I have also tried sending (String)f
, anything else I write is giving me an error,
This is compiling fine, but when I connect to the AP and open 192.168.4.1 in the browser i am not seeing anything,
But when I wrote server.send(200,"text/html",(String)f)
I was getting 0, Any idea on what mistake I am making.
'EOF'
that you're reading until. That's looking for the letterE
not the end of the file.server.streamFile("text/html", f);