Chat here about code rewrites, mods, etc... with respect to the github project https://github.com/esp8266/Arduino

Moderator: igrr

User avatar
By thetimshow
#43069 I've been trying to send large dataset as xml images and I think I keep running out of heap space.

I went digging through the ESP8266WebServer.h and .cpp and found that even if I was passing a char * address, the library was promoting the data to a String class. Which I think is the reason I was trying to trouble shoot a intermittent problem.

To this end I wrote for my self the following routines at end. Which appropriate additions to the header.
(Unfortunately the formatting isn't preserved by this editor. So I've attached my edited source files.)

Timothy

void ESP8266WebServer::send(int code, const char* content_type, const char *content) {
String header;
_prepareHeader(header, code, content_type, strlen(content));
sendContent(header);

sendContent(content);
}

void ESP8266WebServer::sendContent(const char *content) {
const size_t unit_size = HTTP_DOWNLOAD_UNIT_SIZE;
size_t size_to_send = strlen(content);
const char* send_start = content;

while (size_to_send) {
size_t will_send = (size_to_send < unit_size) ? size_to_send : unit_size;
size_t sent = _currentClient.write(send_start, will_send);
if (sent == 0) {
break;
}
size_to_send -= sent;
send_start += sent;
}
}
You do not have the required permissions to view the files attached to this post.