I am working on a project that requires sending large files, .png, css, javascript, etc. from an ESP32 server to a client browser.
I extract the file content as bytes, store it as constant arrays in flash, and simply use the constant array as the data source in the server's send command, no RAM requirement. I wondered if a similar mechanism would work for you.
I created a char array as a variable, not constant.
Code: Select all
#define NUMVALUES 3600
#define CHARSPERVALUE 36
static char tabvals_csv[NUMVALUES * CHARSPERVALUE] = "";
and filled it with values created using sprintf.
Code: Select all
void fillTabMesures(){
int n;
char tabvalue[CHARSPERVALUE] = "";
for (int i=0;i<(NUMVALUES);i++){
float value = float(i)/100.0;
unsigned long tnow = millis();
n = sprintf(tabvalue,"%7.2f,%22lu,\n", value, tnow);
strcat(tabvals_csv,tabvalue);
}
}
I set up a callback with:
Code: Select all
server.on("/tabvals.csv",handletabvals);
and used the send command with the array as a parameter to send the file
Code: Select all
void handletabvals(){
server.send(200, "text/csv", tabvals_csv);
}
Now, if I request
http://buttons.local/tabvals.csv from my server using firefox on my PC I get a file save dialog asking where to save the file. The file loads to my spreadsheet program and gives output of the form:
Code: Select all
0.00, 793,
0.01, 793,
0.02, 793,
0.03, 793,
0.04, 793,
The disadvantage is that the array is larger than the raw values.
The advantages are:
- that the data don't have to be processed on the fly, they are sent directly by the server.
- no additional buffering/storage is needed to process the raw data to csv strings.
I am using ESP32-S3-DevKitC-1, and I don't have a problem with sprintf.
Andy