Esp8266 - handleRoot() - multiple requests?

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

Please follow this link: BEGINNERS and LEARNERS read this... - Using Arduino / Project Guidance - Arduino Forum

and complete Your post. Know that all helpers are complete newbies to Your project.

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?

regards

Hi -
Here's a bit more info:
it's based on: simple_server

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.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.