Я впервые пытаюсь это сделать.Я настроил HTML-файл, и он был обслужен.Я хочу придать стиль моей HTML-форме с помощью внутреннего или внешнего CSS, но я могу ».Тем не менее, я использовал разные уроки, которые мне не удавалось.У меня есть основной каталог и файлы index.h, style.css и main.ino.Вот мой кодКто-нибудь может показать мне, какой правильный код?
#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;
}