0

I am using ESP32 CAM module for a line follower robot. And, I am trying to create a webserver with 3 submit push buttons. But for now, I just observe the input on serial port and work with only one submit bar. These push buttons specifies the PWM value of motors and some constants. Here is my code:

#include "Arduino.h" #include "WiFi.h" #include "AsyncTCP.h" #include "ESPAsyncWebServer.h" AsyncWebServer server(80); // Internet ID and Password const char* ssid = "TURKSAT-KABLONET-BC75-2.4G"; const char* password = "d942d3db"; const char* PARAM_INPUT_1 = "input1"; const char* PARAM_INPUT_2 = "input2"; const char* PARAM_INPUT_3 = "input3"; // HTML web page to handle 3 input fields (input1, input2, input3) const char index_html[] PROGMEM = R"rawliteral( // Webserver design part <!DOCTYPE HTML><html><head> <title>ESP Input Form</title> <meta name="viewport" content="width=device-width, initial-scale=1"> </head><body> <form action="/get"> input1: <input type="text" name="input1"> <input type="submit" value="Submit"> // Submit bar 1 </form><br> <form action="/get"> input2: <input type="text" name="input2"> <input type="submit" value="Submit"> // Submit bar 2 </form><br> <form action="/get"> input3: <input type="text" name="input3"> <input type="submit" value="Submit"> // Submit bar 3 </form> </body></html>)rawliteral"; void notFound(AsyncWebServerRequest *request) { request->send(404, "text/plain", "Not found"); } String inputMessage; void Setup_to_Loop(String inputMessage); // Prototype of function void Setup_to_Loop(String inputMessage){ // Function to observe the variable while(1){ Serial.print(inputMessage); // Observe submit bar on serial port of Arduino delay(200); } } void setup() { Serial.begin(115200); WiFi.mode(WIFI_STA); WiFi.begin(ssid, password); if (WiFi.waitForConnectResult() != WL_CONNECTED) { Serial.println("WiFi Failed!"); return; } Serial.println(); Serial.print("IP Address: "); Serial.println(WiFi.localIP()); // Send web page with input fields to client server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){ request->send_P(200, "text/html", index_html); }); // Send a GET request to <ESP_IP>/get?input1=<inputMessage> server.on("/get", HTTP_GET, [] (AsyncWebServerRequest *request) { String inputMessage; String inputParam; // GET input1 value on <ESP_IP>/get?input1=<inputMessage> if (request->hasParam(PARAM_INPUT_1)) { // Check for which bar is filled ( bar 1 ) inputMessage = request->getParam(PARAM_INPUT_1)->value(); inputParam = PARAM_INPUT_1; } // GET input2 value on <ESP_IP>/get?input2=<inputMessage> else if (request->hasParam(PARAM_INPUT_2)) { // Check for which bar is filled ( bar 2 ) inputMessage = request->getParam(PARAM_INPUT_2)->value(); inputParam = PARAM_INPUT_2; } // GET input3 value on <ESP_IP>/get?input3=<inputMessage> else if (request->hasParam(PARAM_INPUT_3)) { // Check for which bar is filled ( bar 3 ) inputMessage = request->getParam(PARAM_INPUT_3)->value(); inputParam = PARAM_INPUT_3; } else { inputMessage = "No message sent"; inputParam = "none"; } Serial.println(inputMessage); request->send(200, "text/html", "HTTP GET request sent to your ESP on input field (" + inputParam + ") with value: " + inputMessage + "<br><a href=\"/\">Return to Home Page</a>"); // Send the values that were written on submit bars Setup_to_Loop(inputMessage); // Call of function }); server.onNotFound(notFound); server.begin(); } void loop() { } 

The recieved error is :

(20281) task_wdt: Task watchdog got triggered. The following tasks did not reset the watchdog in time: E (20281) task_wdt: - async_tcp (CPU 0/1) E (20281) task_wdt: Tasks currently running: E (20281) task_wdt: CPU 0: IDLE0 E (20281) task_wdt: CPU 1: loopTask E (20281) task_wdt: Aborting. abort() was called at PC 0x400e5def on core 0 Backtrace: 0x4008efe0:0x3ffbe160 0x4008f211:0x3ffbe180 0x400e5def:0x3ffbe1a0 0x40081a15:0x3ffbe1c0 0x40147e4f:0x3ffbc170 0x400e1c53:0x3ffbc190 0x4008ce7d:0x3ffbc1b0 0x4008af7d:0x3ffbc1d0 Rebooting... 
3
  • I don't recommend mixing C and C++, especially on embedded systems. The C++ language allows for function overloading which makes linking more difficult with the C language. Also, C++ has exception handling which makes blending with C difficult. I recommend picking one language and updating your language tags. Commented May 3, 2021 at 16:22
  • you block an execution of the thread by infinite loop in Setup_to_Loop(String inputMessage) Commented May 3, 2021 at 16:47
  • @ThomasMatthews this is an Arduino project; Arduino uses C++. The OP didn't mix languages, they just incorrectly tagged the question. Commented May 3, 2021 at 17:09

1 Answer 1

4

Your function Setup_to_Loop() calls delay(). It's called from the handler for the "/get" request.

The ESPAsyncWebServer documentation explicitly states that you must not do this:

You can not use yield or delay or any function that uses them inside the callbacks 

I'm not quite sure what you're trying to do with this function and why it's using an infinite loop, but you'll need to rewrite it. It should return promptly and not call delay().

Sign up to request clarification or add additional context in comments.

6 Comments

My aim is to take a value only once from the webserver . After that, function is going to start an infinite loop to follow lines and set this value as pwm value of the motors. I planned to write this code because there will be no need to programme the device with a programmer. The user can easily change the variables by writing on webserver. Is there a way to close the server after taking '' inputMessage ''? Or do you recommend me to stop watchdog timer ? What else you recommend ?
Set a flag in the handler, check for it in loop() and do your work, including closing the server or whatever you need to do, there.
When I delete the delay, program runs around 11500 ( 3-4 sec ) then it brings error again. Is there a way to transfer inputMessage from void setup() to void loop ?
If you just delete the delay() call then you're sitting there in an infinite loop and of course the watchdog timer is going to fire. That's what it's there for.
Sir, many days and even months are passed... I recently considered that I forgot to thank you for your command. By your advice, I have completed my project and it changed my life to be a programmer. Thank you, wish you good and healthy days...
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.