Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
cotestatnt committed Jan 10, 2024
2 parents 6de01bc + 3519cc5 commit 90244b9
Show file tree
Hide file tree
Showing 17 changed files with 69 additions and 64 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ If you like this work, please consider [sponsoring this project!](https://paypal
# async-esp-fs-webserver
ESP32/ESP8266 WebServer, WiFi manager and ACE web editor Arduino library. Based on [ESPAsyncWebServer](https://github.com/me-no-dev/ESPAsyncWebServer) from @me-no-dev

Thi is the equivalent to **esp-fs-webserver** Arduino library, but working with the very good **ESPAsyncWebServer** library instead default webserver library.
This is the equivalent to **esp-fs-webserver** Arduino library, but working with the very good **ESPAsyncWebServer** library instead default webserver library.
From some tests I have done, I have been able to observe that a webserver created with this library is much faster and more responsive, which is why I decided to develop this variant of the library.

**Note**:
Starting from version 2.0.0 ESP32 core for Aruino introduced the LittlsFS library like ESP8266. The examples in this library is written to work with this for both platform by default. Change according to your needs if you prefer other filesystems.
Starting from version 2.0.0 ESP32 core for Arduino introduced the LittlsFS library like ESP8266. The examples in this library is written to work with this for both platform by default. Change according to your needs if you prefer other filesystems.

## WiFi, OTA firmware update and Options manager
Thanks to the built-in page **/setup** (about 6.9Kb of program space) is possible scan and set the WiFi credentials and other freely configurable parameters.
Thanks to the built-in page **/setup** (about 6.9Kb of program space) it is possible to scan and set the WiFi credentials and other freely configurable parameters.

With **/setup** webpage is also possible perform remote firmware update.
With **/setup** webpage it is also possible to perform remote firmware update (OTA-update).

![image](https://github.com/cotestatnt/async-esp-fs-webserver/assets/27758688/e16cf5cb-252a-42bb-b111-305387f9d0cc)

Expand All @@ -25,8 +25,8 @@ In the image below, for example, the HTML and Javascript code to provision the d


## ACE web file editor/browser
Thanks to the built-in **/edit** page, is possible upload, delete and edit the HTML/CSS/JavaScript source files directly from browser and immediately displaying the changes introduced at runtime without having to recompile the device firmware.
The page can be enabled at runtime using the method `enableFsCodeEditor()` and it occupy about 6.7Kb of program space.
Thanks to the built-in **/edit** page, it is possible to upload, delete and edit the HTML/CSS/JavaScript source files directly from browser and immediately display the changes introduced at runtime without having to recompile the device firmware.
The page can be enabled at runtime using the method `enableFsCodeEditor()` and it occupies about 6.7Kb of program space.

![image](https://github.com/cotestatnt/async-esp-fs-webserver/assets/27758688/668c0899-a060-4aed-956b-51311bf3fe13)

4 changes: 2 additions & 2 deletions examples/customHTML/customElements.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

/*
* This HTML code will be injected in /setup webpage using a <div></div> element as parent
* The parent element will hhve the HTML id properties equal to 'raw-html-<id>'
* The parent element will have the HTML id properties equal to 'raw-html-<id>'
* where the id value will be equal to the id parameter passed to the function addHTML(html_code, id).
*/
static const char custom_html[] PROGMEM = R"EOF(
Expand All @@ -25,7 +25,7 @@ static const char custom_html[] PROGMEM = R"EOF(
* In this example, a style sections is added in order to render properly the new
* <select> and <pre> elements introduced. Since this section will be added at the end of the body,
* it is also possible to override the style of the elements already present:
* for example the background color of body will be ovverrided with a different color
* for example the background color of body will be overridden with a different color
*/
static const char custom_css[] PROGMEM = R"EOF(
pre{
Expand Down
29 changes: 16 additions & 13 deletions examples/customHTML/customHTML.ino
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ uint32_t longVar = 1234567890;
float floatVar = 15.5F;
String stringVar = "Test option String";

// ThingsBoard varaibles
// ThingsBoard variables
String tb_deviceName = "ESP Sensor";
double tb_deviceLatitude = 41.88505;
double tb_deviceLongitude = 12.50050;
Expand All @@ -49,16 +49,16 @@ uint16_t tb_port = 80;
#define TB_SECRET_KEY "Provisioning secret key"

// Timezone definition to get properly time from NTP server
#define MYTZ "CET-1CEST,M3.5.0,M10.5.0/3"
struct tm Time;
//n.u. #define MYTZ "CET-1CEST,M3.5.0,M10.5.0/3"
//n.u. struct tm Time;


/*
* Include the custom HTML, CSS and Javascript to be injected in /setup webpage.
* HTML code will be injected according to the order of options declaration.
* CSS and JavaScript will be appended to the end of body in order to work properly.
* In this manner, is also possible override the default element styles
* like for example background color, margins, paddings etc etc
* like for example background color, margins, padding etc etc
*/
#include "customElements.h"
#include "thingsboard.h"
Expand All @@ -70,7 +70,7 @@ bool startFilesystem() {
return true;
}
else {
Serial.println("ERROR on mounting filesystem. It will be formmatted!");
Serial.println("ERROR on mounting filesystem. It will be reformatted!");
FILESYSTEM.format();
ESP.restart();
}
Expand Down Expand Up @@ -145,6 +145,9 @@ void handleLoadOptions(AsyncWebServerRequest *request) {
}

void setup() {
#ifdef LED_BUILTIN
pinMode(LED_BUILTIN, OUTPUT);
#endif
Serial.begin(115200);

// Load configuration (if not present, default will be created when webserver will start)
Expand Down Expand Up @@ -189,7 +192,7 @@ void setup() {
// Add a new options box with custom code injected
server.addOptionBox("Custom HTML");
// How many times you need (for example one in different option box)
server.addHTML(custom_html, "fetch-test", /*overwite*/ false);
server.addHTML(custom_html, "fetch-test", /*overwrite*/ false);

// Add a new options box
server.addOptionBox("ThingsBoard");
Expand All @@ -201,20 +204,20 @@ void setup() {
server.addOption(TB_DEVICE_KEY, tb_device_key);
server.addOption(TB_SECRET_KEY, tb_secret_key);
server.addOption(TB_DEVICE_TOKEN, tb_deviceToken);
server.addHTML(thingsboard_htm, "ts", /*overwite file*/ false);
server.addHTML(thingsboard_htm, "ts", /*overwrite file*/ false);

// CSS will be appended to HTML head
server.addCSS(custom_css, "fetch", /*overwite file*/ false);
server.addCSS(custom_css, "fetch", /*overwrite file*/ false);
// Javascript will be appended to HTML body
server.addJavascript(custom_script, "fetch", /*overwite file*/ false);
server.addJavascript(thingsboard_script, "ts", /*overwite file*/ false);
server.addJavascript(custom_script, "fetch", /*overwrite file*/ false);
server.addJavascript(thingsboard_script, "ts", /*overwrite file*/ false);

// Add custom page title to /setup
server.setSetupPageTitle("Test setup page");
server.setSetupPageTitle("Custom HTML Web Server");
// Add custom logo to /setup page with custom size
server.setLogoBase64(base64_logo, "128", "128", /*overwite file*/ false);
server.setLogoBase64(base64_logo, "128", "128", /*overwrite file*/ false);

// Enable ACE FS file web editor and add FS info callback fucntion
// Enable ACE FS file web editor and add FS info callback function
server.enableFsCodeEditor();
#ifdef ESP32
server.setFsInfoCallback(getFsInfo);
Expand Down
2 changes: 1 addition & 1 deletion examples/customHTML/thingsboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ function createNewDevice() {
var token = $(TB_DEVICE_TOKEN);
token.focus();
token.value = obj.credentialsValue;
openModalMessage('Write device attributes', 'Device provisioned correctly.<br>Do you want set client attirbutes on ThingsBoard server?', setDeviceClientAttribute);
openModalMessage('Write device attributes', 'Device provisioned correctly.<br>Do you want to set client attributes on ThingsBoard server?', setDeviceClientAttribute);
});
}

Expand Down
10 changes: 5 additions & 5 deletions examples/customOptions/customOptions.ino
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ String stringVar = "Test option String";
// In order to show a dropdown list box in /setup page
// we need a list of values and a variable to store the selected option
#define LIST_SIZE 7
const char* dropdownList[LIST_SIZE] =
const char* dropdownList[LIST_SIZE] =
{"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"};
String dropdownSelected;

Expand Down Expand Up @@ -75,7 +75,7 @@ bool startFilesystem() {
return true;
}
else {
Serial.println("ERROR on mounting filesystem. It will be formmatted!");
Serial.println("ERROR on mounting filesystem. It will be reformatted!");
FILESYSTEM.format();
ESP.restart();
}
Expand Down Expand Up @@ -172,10 +172,10 @@ void setup() {
server.addOption(STRING_LABEL, stringVar);
server.addDropdownList(DROPDOWN_LABEL, dropdownList, LIST_SIZE);

server.addHTML(save_btn_htm, "buttons", /*overwite*/ false);
server.addJavascript(button_script, "js", /*overwite*/ false);
server.addHTML(save_btn_htm, "buttons", /*overwrite*/ false);
server.addJavascript(button_script, "js", /*overwrite*/ false);

// Enable ACE FS file web editor and add FS info callback fucntion
// Enable ACE FS file web editor and add FS info callback function
server.enableFsCodeEditor();
#ifdef ESP32
server.setFsInfoCallback(getFsInfo);
Expand Down
6 changes: 3 additions & 3 deletions examples/esp32-cam/esp32-cam.ino
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ void setup() {
/*
Init onboard SD filesystem (format if necessary)
SD_MMC.begin(const char * mountpoint, bool mode1bit, bool format_if_mount_failed, int sdmmc_frequency, uint8_t maxOpenFiles)
To avoid led glowindg, set mode1bit = true (SD HS_DATA1 is tied to GPIO4, the same of on-board flash led)
To avoid led glowing, set mode1bit = true (SD HS_DATA1 is tied to GPIO4, the same of on-board flash led)
*/
if (!SD_MMC.begin("/sdcard", true, true, SDMMC_FREQ_HIGHSPEED, 5)) {
Serial.println("\nSD Mount Failed.\n");
Expand All @@ -64,7 +64,7 @@ void setup() {
}
listDir(getFolder, 1);

// Enable ACE FS file web editor and add FS info callback fucntion
// Enable ACE FS file web editor and add FS info callback function
server.enableFsCodeEditor();
server.setFsInfoCallback([](fsInfo_t* fsInfo) {
fsInfo->totalBytes = SD_MMC.totalBytes();
Expand All @@ -85,7 +85,7 @@ void setup() {
"Open /edit page to view, edit or upload example or your custom webserver source files."
));

// Init the camera module (accordind the camera_config_t defined)
// Init the camera module (according the camera_config_t defined)
init_camera();
}

Expand Down
4 changes: 2 additions & 2 deletions examples/gpio_list/gpio_list.ino
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,9 @@ void setup() {
}

// Try to connect to flash stored SSID, start AP if fails after timeout
IPAddress myIP = server.startWiFi(15000, "ESP8266_AP", "123456789" );
IPAddress myIP = server.startWiFi(15000, "ESP_AP", "123456789" );

// Enable ACE FS file web editor and add FS info callback fucntion
// Enable ACE FS file web editor and add FS info callback function
server.enableFsCodeEditor();

/*
Expand Down
6 changes: 3 additions & 3 deletions examples/handleFormData/handleFormData.ino
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ bool startFilesystem() {
return true;
}
else {
Serial.println("ERROR on mounting filesystem. It will be formmatted!");
Serial.println("ERROR on mounting filesystem. It will be reformatted!");
FILESYSTEM.format();
ESP.restart();
}
Expand All @@ -87,7 +87,7 @@ void setup(){
Serial.begin(115200);

// Try to connect to stored SSID, start AP if fails after timeout
IPAddress myIP = server.startWiFi(15000, "ESP8266_AP", "123456789" );
IPAddress myIP = server.startWiFi(15000, "ESP_AP", "123456789" );

// FILESYSTEM INIT
startFilesystem();
Expand All @@ -97,7 +97,7 @@ void setup(){
server.on("/setForm1", HTTP_POST, handleForm1);
server.on("/setForm2", HTTP_POST, handleForm2);

// Enable ACE FS file web editor and add FS info callback fucntion
// Enable ACE FS file web editor and add FS info callback function
server.enableFsCodeEditor();
/*
* Getting FS info (total and free bytes) is strictly related to
Expand Down
6 changes: 3 additions & 3 deletions examples/highcharts/highcharts.ino
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ bool startFilesystem() {
return true;
}
else {
Serial.println("ERROR on mounting filesystem. It will be formmatted!");
Serial.println("ERROR on mounting filesystem. It will be reformatted!");
FILESYSTEM.format();
ESP.restart();
}
Expand All @@ -107,9 +107,9 @@ void setup() {
startFilesystem();

// Try to connect to flash stored SSID, start AP if fails after timeout
IPAddress myIP = server.startWiFi(15000, "ESP8266_AP", "123456789" );
IPAddress myIP = server.startWiFi(15000, "ESP_AP", "123456789" );

// Enable ACE FS file web editor and add FS info callback fucntion
// Enable ACE FS file web editor and add FS info callback function
server.enableFsCodeEditor();

/*
Expand Down
10 changes: 5 additions & 5 deletions examples/highcharts/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ This example is the most advanced since now.

With the help of WebSocket technology, we can send message from server-to-clients or from client-to-server in a **full-duplex communication channels over a single TCP connection.**

We use the **WebSocket client** to populate asynchronously an _"area chart"_ with real time datas from ESP regarding the **total size of heap memory** and size of **max contiguos block of memory**.
We use the **WebSocket client** to populate asynchronously an _"area chart"_ with real time datas from ESP regarding the **total size of heap memory** and size of **max contiguous block of memory**.

Off course, on the ESP MCU we will run also a WebSocket server togheter to the web server.
I've used this library [arduinoWebSockets](https://github.com/Links2004/arduinoWebSockets), so it is needed to compile, but you can choice wich you prefer.
Off course, on the ESP MCU we will run also a WebSocket server together to the web server.
I've used this library [arduinoWebSockets](https://github.com/Links2004/arduinoWebSockets), so it is needed to compile, but you can choose which you prefer.

>N.B.
This example will run only if an internet connection is avalaible because [Highcharts](https://www.highcharts.com/) Javascript resources is necessary
This example will run only if an internet connection is available because [Highcharts](https://www.highcharts.com/) Javascript resources is necessary
(to run offline in AP mode, you can download all the used js files, put it in the flash memory (better if gzipped to speed-up page loading) and edit the [index.htm](https://github.com/cotestatnt/esp-fs-webserver/blob/main/examples/highcharts/data/index.htm))

In this example, web page CSS and JavaScript source file is stored in a separeted file inside the folder **/app**
In this example, web page CSS and JavaScript source file is stored in a separated file inside the folder **/app**

![image](https://user-images.githubusercontent.com/27758688/123048782-135e4b00-d3ff-11eb-84d5-45e2f164e0f7.png)
4 changes: 2 additions & 2 deletions examples/remoteOTA/remoteOTA.ino
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ bool startFilesystem() {
return true;
}
else {
Serial.println("ERROR on mounting filesystem. It will be formmatted!");
Serial.println("ERROR on mounting filesystem. It will be reformatted!");
FILESYSTEM.format();
ESP.restart();
}
Expand Down Expand Up @@ -187,7 +187,7 @@ void setup(){
// FILESYSTEM INIT
startFilesystem();

// Enable ACE FS file web editor and add FS info callback fucntion
// Enable ACE FS file web editor and add FS info callback function
server.enableFsCodeEditor();

/*
Expand Down
6 changes: 3 additions & 3 deletions examples/simpleServer/simpleServer.ino
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ float testFloat = 123.456;
#ifndef LED_BUILTIN
#define LED_BUILTIN 2
#endif
uint8_t ledPin = LED_BUILTIN;
const uint8_t ledPin = LED_BUILTIN;


// FILESYSTEM INIT
Expand All @@ -24,7 +24,7 @@ bool startFilesystem(){
return true;
}
else {
Serial.println("ERROR on mounting filesystem. It will be formmatted!");
Serial.println("ERROR on mounting filesystem. It will be reformatted!");
LittleFS.format();
ESP.restart();
}
Expand Down Expand Up @@ -85,7 +85,7 @@ void setup() {
server.addOption("Test float variable", testFloat);
server.setSetupPageTitle("Simple Async ESP FS WebServer");

// Enable ACE FS file web editor and add FS info callback fucntion
// Enable ACE FS file web editor and add FS info callback function
server.enableFsCodeEditor();
#ifdef ESP32
server.setFsInfoCallback(getFsInfo);
Expand Down
8 changes: 5 additions & 3 deletions examples/simpleServerCaptive/simpleServerCaptive.ino
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ bool captiveRun = false;
#ifndef LED_BUILTIN
#define LED_BUILTIN 2
#endif
uint8_t ledPin = LED_BUILTIN;
const int ledPin = LED_BUILTIN;

//////////////////////////////// Filesystem /////////////////////////////////////////
bool startFilesystem() {
Expand All @@ -17,7 +17,7 @@ bool startFilesystem() {
return true;
}
else {
Serial.println("ERROR on mounting filesystem. It will be formmatted!");
Serial.println("ERROR on mounting filesystem. It will be formatted!");
LittleFS.format();
ESP.restart();
}
Expand Down Expand Up @@ -49,6 +49,8 @@ void handleLed(AsyncWebServerRequest *request) {
String reply = "LED is now ";
reply += value ? "ON" : "OFF";
request->send(200, "text/plain", reply);
Serial.print("handleLed:");
Serial.println(reply);
}


Expand Down Expand Up @@ -77,7 +79,7 @@ void setup() {
// Set a custom /setup page title
server.setSetupPageTitle("Simple Async FS Captive Web Server");

// Enable ACE FS file web editor and add FS info callback fucntion
// Enable ACE FS file web editor and add FS info callback function
server.enableFsCodeEditor();
#ifdef ESP32
server.setFsInfoCallback(getFsInfo);
Expand Down
6 changes: 3 additions & 3 deletions examples/withWebSocket/readme.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
## esp-fs-webserver
This example is a little bit more advanced respect to the [simpleServer](https://github.com/cotestatnt/esp-fs-webserver/tree/main/examples/simpleServer) example.

Basically is the same HTML code like simpleServer, but with the adddition of a **WebSocket client** inside the webpage.
Basically is the same HTML code like simpleServer, but with the addition of a **WebSocket client** inside the webpage.

Off course, on the ESP MCU we will run also a **WebSocket server** togheter to the web server.
I've used the library [arduinoWebSockets](https://github.com/Links2004/arduinoWebSockets), so it is needed to compile, but you can choice wich you prefer.
Off course, on the ESP MCU we will run also a **WebSocket server** together to the web server.
I've used the library [arduinoWebSockets](https://github.com/Links2004/arduinoWebSockets), so it is needed to compile, but you can choose which you prefer.

With the help of WebSocket technology, we can send message from server-to-clients or from client-to-server in a **full-duplex communication channels over a single TCP connection.**

Expand Down
Loading

0 comments on commit 90244b9

Please sign in to comment.