web portal and basic authentication guidance
Posted: Sun Dec 17, 2017 12:13 pm
I'm still the newbie so apologies upfront!
I have my first project on the go and I'm trying to build it so there is no need to modify the base sketch just flash it and then configure thru a web portal. I think many of you are doing the same. I made use of WiFiManager, ESP8266WebServer, ESP8266HTTPUpdateServer, FS, PubSubClient as well as any other relevant libraries. Configuration (JSON file) is stored in SPIFFS. I also added a basic HTML page in SPIFFS for the Portal. No problem so far but I have a question on my approach.
Q1) What is preferred method for storing simple HTML, SPIFFS or Sketch? The HTML on SPIFFS looks updateable thru OTA but I haven't tried it yet. I also haven't figured out how to set initial values in the web page or to get them back. But I do like the idea of keeping the HTML outside of the sketch.
Q2) I have this basic authentication from the examples in ESP8266WebServer. It works fine but if I enter <ip>/index.html then no authentication takes place. I can see why as only "/" is picked up and I did add httpServer.on("/index.hml",.... only to end up getting more confused. I have no HTML background but I'm learning slowly badly! Any pointers for forcing authentication on "/" and "/index.hml"?
httpServer.on("/", [](){
if(!httpServer.authenticate(www_username, www_password))
return httpServer.requestAuthentication();
httpServer.sendHeader("Location","/index.html");
httpServer.send(303);
});
I have my first project on the go and I'm trying to build it so there is no need to modify the base sketch just flash it and then configure thru a web portal. I think many of you are doing the same. I made use of WiFiManager, ESP8266WebServer, ESP8266HTTPUpdateServer, FS, PubSubClient as well as any other relevant libraries. Configuration (JSON file) is stored in SPIFFS. I also added a basic HTML page in SPIFFS for the Portal. No problem so far but I have a question on my approach.
Q1) What is preferred method for storing simple HTML, SPIFFS or Sketch? The HTML on SPIFFS looks updateable thru OTA but I haven't tried it yet. I also haven't figured out how to set initial values in the web page or to get them back. But I do like the idea of keeping the HTML outside of the sketch.
Q2) I have this basic authentication from the examples in ESP8266WebServer. It works fine but if I enter <ip>/index.html then no authentication takes place. I can see why as only "/" is picked up and I did add httpServer.on("/index.hml",.... only to end up getting more confused. I have no HTML background but I'm learning slowly badly! Any pointers for forcing authentication on "/" and "/index.hml"?
httpServer.on("/", [](){
if(!httpServer.authenticate(www_username, www_password))
return httpServer.requestAuthentication();
httpServer.sendHeader("Location","/index.html");
httpServer.send(303);
});