using esp_http_server using arduino framework

noweare
Posts: 79
Joined: Tue Jul 02, 2019 11:35 am

using esp_http_server using arduino framework

Postby noweare » Mon Jun 03, 2024 6:45 pm

Hello,
I want to use esp_http_server in my project since it also supports websockets.
I have my html, css and js files in spiffs as 3 separate files.
Looking at the "file_serving" example in the esp-idf, the example makes use of the cmakelists.txt file

I am using the arduino framework with platformio which AFAIK do not use cmakelist.txt file.
Is there anyway to get this functionality in my project ?

Thanks

lbernstone
Posts: 829
Joined: Mon Jul 22, 2019 3:20 pm

Re: using esp_http_server using arduino framework

Postby lbernstone » Mon Jun 03, 2024 8:41 pm

arduino-esp32 is a pre-built set of ESP-IDF libraries. So, all that cmake stuff is already handled for you. The relevant pieces you need are all in the file_server.c file- #includes needed, initializing the daemon, setting up handlers, and handlers to do basic responses. Past that, use the idf doco for details on the functions. Once you get into it, you'll see it is essentially the same process as what you are doing with WebServer.h.

noweare
Posts: 79
Joined: Tue Jul 02, 2019 11:35 am

Re: using esp_http_server using arduino framework

Postby noweare » Tue Jun 04, 2024 5:55 pm

In the file_serving example I do not understand the "extern ..." lines shown below.

/* Get handle to embedded file upload script */
extern const unsigned char upload_script_start[] asm("_binary_upload_script_html_start");
extern const unsigned char upload_script_end[] asm("_binary_upload_script_html_end");
const size_t upload_script_size = (upload_script_end - upload_script_start);
httpd_resp_send_chunk(req, (const char *)upload_script_start, upload_script_size);


I ended up putting my index.html file in spiffs and when i need to send it to the client I open the file, count number of bytes then
save the file to a buffer to send it using httpd_resp_send(req, (char *)buf, fileLength);
Don't know if that is best way to do it but it works.
Thanks for replying. I will mark this as solved.

lbernstone
Posts: 829
Joined: Mon Jul 22, 2019 3:20 pm

Re: using esp_http_server using arduino framework

Postby lbernstone » Wed Jun 05, 2024 4:58 pm

Those extern lines are including an external file to be added to ro_data during compile. In Arduino, you can accomplish the same thing with constant strings. You can see an example of how I typically do this in the OTAWebUpdater example. I prefer to only have user data in a file system. Slipstreaming the files into your code means they get replaced along with the rest of the firmware.

Who is online

Users browsing this forum: No registered users and 68 guests