There are a few things in your code that are not correct.
I'll go through them one by one in order of appearance.
String htmlContent = "";
const int led = 2; // the builtin led on most ESP-01's is on pin 1, but that is also TX
// just make sure that also for GPIO 2 you need to make the LED active LOW
void handleRoot() {
digitalWrite(led, 1);
server.send(200, "text/html", htmlContent);
digitalWrite(led, 0);
}
To declare htmlContent as a global String is not a wise idea, although this not the cause of slow response times, it may eat up memory at some point, and that should be prevented. It is better to gather data and store that in variables, and then within the callback function create a 'String' with html header, body etc. and send that, and the String will be destroyed when it goes out of scope, more the way the handleNotFound() callback is setup.
if (Serial.available()) {
String inputString = Serial.readStringUntil('\n');
This is a problem, now if there are any characters in the Serial input buffer, the program is held up until it finds a '\r'
This is when your webserver is no longer responsive. You then do some form of parsing copying data into 2 separate c-strings, all fine, but the 'readStringUntil()' is blocking code.
It does depend a little on what you send of course, but if you would have sent something like
Serial.print("This is the message\n\r");
your sketch will be held up until the next time a message arrives, and the browser will not wait that long for a response.
server.on(buttonValues[1], [returnVal]() { server.send(200, "text/plain", returnVal); });
This just doesn't belong inside of loop() but in setup().
You should declare all callbacks in setup(), if you want the function to respond in a different way later, you can do that within the callback function itself.
There are many ways to receive Serial data, and Serial.readStringUntil() is probably the worst of them.
Serial Input Basics contains very reliable and 'non-blocking' methods of Serial communication
Fact is that i don't think you really need to receive Serial data at this end at all.
The ESP should be in charge, it will contain the UI and it has the faster processor and bigger memory (I think, i don't know the exact specs of the pico)
Probably not.
I suggest you simplify the webserver so the main page has 2 forms (or just 1) extracts the data from the request (either post or get) using the .hasArg() and arg() function and sends a message through the UART to either the pico or the Serial monitor (or though the pico to the monitor, whatever) To confirm that there is nothing wrong with your unit.
I was looking for a clear example, but somehow not only do all of my examples have a lot of not relevant code, but also the examples that come with the library do have a lot of code that only makes things more complicated.
Either way, the webserver responds to a request the moment it encounters a
server.handleClient();