Skip to content

esp-fs-webserver 2.0.0

Choose a tag to compare

@cotestatnt cotestatnt released this 16 Jan 13:34
· 202 commits to master since this release

Please read carefully: this is a breaking release!

With version 2.x the FSWebServer class is directly inherited from the parent WebServerClass.

Due to this important change, the class constructor has been completely revisited.
If you want to update a project to this version, it is therefore necessary to make some changes.

Class constructor

OLD

#ifdef ESP8266
  ESP8266WebServer server(80);
#elif defined(ESP32)
  WebServer server(80);
#endif
FSWebServer myWebServer(LittleFS, server);

NEW

FSWebServer myWebServer(LittleFS, 80);

Updated and removed methods

The begin() method of the parent class returns a void then the statement if (myWebServer.begin()) is not valid and you need to call only myWebServer.begin(); (without if statement).

The method addHandler() was removed, the you need to use directly the parent class method on()

ACE web editor

If you want to use the included page /edit, now it must be explicitly enabled during setup() or where you need.
Since the information relating to the filesystem (label, maximum size and free space) is strictly related to the type of filesystem you want to use, it is necessary to pass a callback function that will provide this information

Callback function

#ifdef ESP32
void getFsInfo(fsInfo_t* fsInfo) {
	fsInfo->fsName = "LittleFS";
	fsInfo->totalBytes = LittleFS.totalBytes();
	fsInfo->usedBytes = LittleFS.usedBytes();
}
#else
void getFsInfo(fsInfo_t* fsInfo) {
	fsInfo->fsName = "LittleFS";
}   
#endif
.....
// Enable ACE FS file web editor and add FS info callback function
myWebServer.enableFsCodeEditor(getFsInfo);

Page authentication

/setup and /edit built-in web pages can be restricted with user and password authentication

// set /setup and /edit page authentication
myWebServer.setAuthentication("admin", "admin");

ArduinoJson 7.x

The use of the ArduinoJson library has been adapted to the new 7.x version while maintaining compatibility with previous versions