Hi - I am using a D1 - esp8266 to do a simple led on/off and am experimenting with sending text and html to a webpage.
In the handleRoot() function:
I have:
void handleRoot() {
server.send(200, "text/plain", "hello from esp8266! (blinking LED!)"); // first line
server.send(200, "text/plain", "Further text..."); //second line
}
But I only see the first line in the browser when handleRoot gets called.
If I comment out the first line then the second line gets sent.
What am I not understanding?
thanks
Russell
When the browser sees the first send response it processes it and is done. It is not expecting anything else so the second send is ignored. You need to build all your text and send it as one response.
Thanks for reply.
Do you mean handleRoot() only opens the connection for a single send per server.send within the handleRoot() function?
Since, If I call another URL then call handleRoot(), it obviously calls the root URL again.
So is that not the same as multiple calls in the same handleRoot function?
Basically server.send(0 sends the headers and the content. If you want to send composite content you can first collect it all in a String and then send it in one go. Esp has quite a lot of memory and as long as the String is local to the callback function there is almost no chance of memory fragmentation. If memory does become short, you can send chunked content to send the content in parts. Usually you won't need to.