esp8266 AsyncWebServer form post ->Serial tx ->Serial rx -> request->redirect

Hi guys,

I am using the AsyncWebServer library and do the following:

  1. on /index.html display a form
  2. on submission with POST I read the parameters and prepare a command
  3. this command I send with Serial.println(txcommand);

I need to:

  1. read what the other device sends me from serial
    example <252235325><523532532><3523532532> or or OK
  2. format it to appropriate html format (list with links for every entity or just popup message)
  3. show it on the browser page (my plan was to make a redirect call with get parameters and use JS to read the parameters and parse them into a popup or list, but it does not work )

So my code is:

server.on("/", HTTP_POST, [](AsyncWebServerRequest * request) {

... form proccessing ...

Serial.println(txcommand);
delay(1000);

while (!Serial.available()) {}
serial_response = Serial.readString();

request->redirect("/?response=" + serial_response);
});

But the esp crashes.
My problem seems to be reading the serial response.
Could you help me with that or propose a better solution altogether.

Thank you

example <252235325><523532532><3523532532> or or OK

Can you post an example of what you expect the "html format (list with links for every entity or just popup message)" to be for input of "<252235325><523532532><3523532532>"? I can't begin to imagine what you want.

OK, found the reason, but still need help.

Reason is: AsyncWebServer library does not allow delay or yield, but Serial.readString(); uses yield();

So what do I need to do? Read char by char and convert to string?

@PaulS serial_response might be phone numbers in <> or shore text message like OK, or No data

If I send this to JavaScript I can easily format these to add a link with action for each phone number, or just show the text message

So what do I need to do? Read char by char and convert to string?

Yes. Do not make the mistake of assuming that all the data has already arrived, though. Read whatever data has arrived, and store it, adding data on every iteration of loop() until the end of record marker arrives.

Mhm, what is a good example of "end of record marker"?

kdobrev:
Mhm, what is a good example of "end of record marker"?

Typically, carriage return or linefeed (\r, \n, 10, 13).