0

It is the first time I try do this. I configured HTML file and it was served.

I want to give style to my HTML form with internal or external CSS, but I can't. However, I used different tutorials I didn't manage to understand how to make it use the CSS.

I have a main directory and index.h, style.css and main.ino files in it. Here is my code. Can anybody show me what is the correct code?

#include <WiFiClient.h>
#include <ESP8266WebServer.h>

#include "index.h"
//#include "style.h"

//SSID and Password to your ESP Access Point
const char* cssfile = "style.css";
const char* ssid = "ESPWebServer";
const char* password = "12345678";

ESP8266WebServer server(80); //Server on port 80

//==============================================================
//     This rutine is exicuted when you open its IP in browser
//==============================================================
String s = MAIN_page;
//String sx = MAIN_STYLE;
void handleRoot() {
  server.send(200, "text/html", s);
  server.send(800, "text/css", "");
}

//===============================================================
//                  SETUP
//===============================================================
void setup(void){
  Serial.begin(9600);
  Serial.println("");
  WiFi.mode(WIFI_AP);           //Only Access point
  WiFi.softAP(ssid);  //Start HOTspot removing password will disable security
  //delay(4000);
  IPAddress myIP = WiFi.softAPIP(); //Get IP address
Serial.print("HotSpt IP:");
  Serial.println(myIP);

  server.on("/", handleRoot);      //Which routine to handle at root location

  server.begin();                  //Start server
  Serial.println("HTTP server started");
}
//===============================================================
//                     LOOP
//===============================================================
void loop(void){
  server.handleClient();          //Handle client requests
}


bool loadFromSpiffs(String path){
  String dataType = "text/plain";
  if(path.endsWith("/")) path += "index.htm";

  if(path.endsWith(".src")) path = path.substring(0, path.lastIndexOf("."));
  else if(path.endsWith(".html")) dataType = "text/html";
  else if(path.endsWith(".css")) dataType = "text/css";

  return true;
} 
  • see the AdvancedWebServer example – Juraj Feb 11 at 10:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.