1

I'm working on a webserver on ESP32 in Arduino IDE and would like to load an html-file. Tried to use SPIFFS.open from the library FS.h from github. Errormessage says SPIFFS was not declared in this scope. (As far as I can see, there's no bracket in the wrong place.)

I did not find any example for ESP32 and FS.h and desperately hope for some help. Thanks in advance.

Here is my code:

    #include "FS.h"
    #include "WiFi.h"

/Wifi Access data/ const char* ssid_ap = "AccessPoint"; const char* password_ap = "12345678";

const char * ssid_sta = ""; const char * password_sta = "";

/* set global variables */ byte WiFiMode = 0; // WIFI_STA = 1 = Workstation WIFI_AP = 2 = Accesspoint int request_counter; String sHTML; String sHTMLRequest;

/* Create instance of server on Port 80 */ WiFiServer server(80); WiFiClient client;

/* * ******SETUP******************************************************* */ void setup() {

/initialize GPIO/

/*start serial communication */ Serial.begin(115200); SPIFFS.format(); Serial.println("Spiffs formatted");

/* start WiFi as workstation (STA), if not possible start as Acess Point initialize server */ WiFi_Start_STA(); if (WiFiMode == 0) WiFi_Start_AP(); }

/* * **LOOP************************************************************* */ void loop() {

/* Check if a client has connected */ client = server.available(); if (!client) { return; }

/*Wait for the client to send data */ Serial.println("neuer Client verbunden"); /*Count Aufruf der Seite: */ request_counter ++; unsigned long clTimeout = millis()+250; while(!client.available() && (millis()clTimeout) { Serial.println("time-out bei Client-Verbindung!"); return; }

/****** open html files *******/ SPIFFS.begin(); File f = SPIFFS.open("/home.txt", "r"); if (!f) { Serial.println("file open failed"); } f.close();

}

/********************************************************************** * **************** FUNCTIONS ******************************************** *


*/

/* * Fct tries to start WiFi in workstation mode, * if not possible sets WiFiMode=AP * starts server */ void WiFi_Start_STA() { unsigned long timeout;

WiFi.mode(WIFI_STA); // Try to start WiFi as Workstation

WiFi.begin(ssid_sta, password_sta); timeout = millis() + 12000L; while (WiFi.status() != WL_CONNECTED && millis() < timeout) { delay(10); }

if (WiFi.status() == WL_CONNECTED) { server.begin(); WiFiMode = WIFI_STA;

Serial.print("Verbunden mit IP - Addresse: "); for (int i = 0; i < 3; i++) { Serial.print( WiFi.localIP()[i]); Serial.print("."); } Serial.println(WiFi.localIP()[3]);

} else { WiFi.mode(WIFI_OFF);

Serial.println("WLAN-Verbindungsaufbau fehlgeschlagen");
}

}

/* *starts WiFi in AP-mode *starts server */ void WiFi_Start_AP() { WiFi.mode(WIFI_AP); // Access Point mode WiFi.softAP(ssid_ap, password_ap); server.begin(); // start server IPAddress ApIP = WiFi.softAPIP(); //read IP of Access Point WiFiMode = WIFI_AP;

Serial.print("ESP-Netzwerk: "); Serial.print(ssid_ap); Serial.print(" aufgebaut. "); Serial.print( " IP-Addresse: "); Serial.println(ApIP); }

<code>
  • github.com/copercini/arduino-esp32-SPIFFS This library should help you. – Hasina Jul 19 '17 at 9:05
  • I have this same problem after a new install and, Looks like the link is dead. Can anyone please take the time to explain how to fix this problem. – dvukovic Aug 5 '18 at 23:34

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.