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.
1 Answer 1
Small update, I used the same code for ESP8266 NodeMCU.
Sorry If I am posting this with wrong device number. But I tried that same code and uploaded it to ESP8266, it worked, and I am getting the AP webpage, that I am storing and sending the file. I will post it as an answer as I need to post an image.
The is the page that I get when using the HTML that I wrote:
So, this happened. I am confused as to why it didn't work with ESP01, plus I have to load the code every time I plug in the ESP01.
-
wrong spiffs size or spiffs not initialized on the first device?2018年07月19日 18:14:14 +00:00Commented Jul 19, 2018 at 18:14
-
initialization of spiffs meaning? like
spiffs.begin()
?Wan Street– Wan Street2018年07月19日 18:25:03 +00:00Commented Jul 19, 2018 at 18:25 -
upload or format() esp8266.github.io/Arduino/versions/2.0.0/doc/filesystem.html2018年07月20日 05:11:24 +00:00Commented Jul 20, 2018 at 5:11
-
ah ok.. I will have to check tomorrow..Wan Street– Wan Street2018年07月22日 17:43:31 +00:00Commented Jul 22, 2018 at 17:43
'EOF'
that you're reading until. That's looking for the letterE
not the end of the file.server.streamFile("text/html", f);