need help on esp32 server hosting an application consisting of several html files

Alexandre2001
Posts: 5
Joined: Sun Jan 01, 2023 10:33 pm

need help on esp32 server hosting an application consisting of several html files

Postby Alexandre2001 » Sun Jan 01, 2023 11:23 pm

I am working on a remote control project for an electrical installation with the ESP32 card (Espressif). But here I have trouble understanding and determining how the component files of my web application can be sent to the client when the latter connects.
In almost all the tutorials that I had to follow, the application is made up of three files, one for the html, one for the CSS style and another for the script.
For my case, I have three html files (one page for home window, one for sensor data and another for electrical equipment management), one CSS file and another JS script file; so I would like to offer the client the ability to navigate between these pages.
From there, the questions I ask myself are those of knowing how will be the flow of files between the client and the ESP32 server?
How to send these files to the client when it requests the connection?

I tried to answer myself, so I said to myself this:

in the first case, you just have to send the home page, the CSS file and the script file first. But again I wonder how the server will then know how to send another file when you click on a link in the menu?

in the second case, I said to myself that it is necessary to send all three html files at the same time, as well as the CSS and Script JS files. Again I wonder how the client will display the correct file?

please answer me please

User avatar
mbratch
Posts: 303
Joined: Fri Jun 11, 2021 1:51 pm

Re: need help on esp32 server hosting an application consisting of several html files

Postby mbratch » Tue Jan 03, 2023 2:42 am

You're probably overthinking this. Your server just needs to respond to http requests for files. The client decides when to request the files. An html file and a css file are requested using the same mechanism. There are several examples online of serving files via http.

khushi_bharti_
Posts: 1
Joined: Tue Jan 03, 2023 8:17 am

Re: need help on esp32 server hosting an application consisting of several html files

Postby khushi_bharti_ » Tue Jan 03, 2023 8:37 am

You can us ethe following fucnction to handle the request and send the required file to it,

server.on("style.css", HTTP_GET, [](AsyncWebServerRequest *request){
request->send(SPIFFS, "style.css", "text/css");
});

I am also working on ESP32- WROOM -32D , for WIFI+ BLE , both working at the same time . There are 2 different freertos task for wifi and ble to work together , Wifi is accessed in AP mode to host a webserver storing the filesystem in SPIFFS , some of the parameters displayed on webserver gets update continously . On the other hand I also want BLE to show the same updated parameters . Both the freertos task runs properly , BLE works as required but the webpages does not get load on the webserver though we can connect to the esp network . As soon as I remove the BLE init part from the code the webserver works as required. IDE used is platformio using Arduino framework. Please help me find what I am doing wrong .

Who is online

Users browsing this forum: Google [Bot] and 60 guests