Serving a large file chunked on a esp32

xDarcadexDarcade Germany

Hey!

I am using the moongoose library in my project. I have some problems serving the jquery.js file.

When I load the page it does only load about 1/4 of the whole file and the code inside loaded part of the file has some random chars that repeat every few characters.
I think that I have to push the send_mbuf to the socket every time in the loop.

void handlejQuery(struct mg_connection nc, int ev, void *ev_data){
ESP_LOGD(tag, "jQuery wird gesendet");
mg_send_head(nc, 200, jquery_js_len, "Content-Type: application/javascript \r\nTransfer-Encoding: chunked");
unsigned int BufferLength = 100;
char buffer[BufferLength];
unsigned int currentChar = 0, currentBufferChar = 0;
while(currentChar <= jquery_js_len){
if(currentBufferChar == BufferLength){
mg_printf_http_chunk(nc, buffer, BufferLength);
currentBufferChar = 0;
}
buffer[currentBufferChar] = jquery_js[currentChar];
currentBufferChar++;
currentChar++;
}
if(currentBufferChar <= BufferLength){
while(currentBufferChar <= BufferLength){
buffer[currentBufferChar] = 0;
currentBufferChar++;
}
mg_printf_http_chunk(nc, "%.
s", BufferLength, buffer);
}

mg_send_http_chunk(nc, "", 0);
}

This function gets called when you open up the url.
This software is running on my ESP32 Thing in Access Point mode and I am using esp-idf for programming.

And this is what the page loads when I try to load up jquery in my browser.
http://pastebin.com/eqbrYTFg

I would be really happy if you could help me because I am trying to solve that problem since some days.

Thank you for every hint!

Comments

Sign In or Register to comment.