ESPAsyncWebServer icon indicating copy to clipboard operation
ESPAsyncWebServer copied to clipboard

Problems with task scheduller

Open sebosfato opened this issue 2 years ago • 3 comments

Hello,

Im trying to implement your library to substitute an old app i have made

it kind of gave a very nice result but there are some exceptions occuring and appear to me because it run in parallel with the task scheduller …

i was going to ask if any of you had this problem? know the solution?

and if you know if is also possible to make http requests async with it too?

currently using this libs :

#include <FS.h> #include <ArduinoJson.h> #include <ESP8266WiFi.h> #include <WiFiClient.h> #include <ESP8266HTTPClient.h> #include <ESP_EEPROM.h> #include <WiFiUdp.h> //ota #include <WiFiManager.h> #include <ESPAsyncTCP.h> #include <ESP8266mDNS.h> #include <ESPAsyncWebServer.h> #include <ESPAsyncDNSServer.h> #include <ESP8266WiFiMulti.h> ESP8266WiFiMulti wifiMulti; #include <NTPClient.h> #define _TASK_SCHEDULING_OPTIONS #include <TaskScheduler.h> #include <RTCVars.h> RTCVars state; #include "SAVE.h" #include "SERVERON.h" #include <ESP8266httpUpdate.h> #include "TinyUPnP.h"

sebosfato avatar Aug 19 '23 18:08 sebosfato

It turns the problem seem to be that i want to make some http requests from the server but after installing this lib it dont seem to work anymore…

i was doing it like this:

void getDataFromPHP() { WiFiClient client; HTTPClient http;

http.begin(client, "http://xxx.php"); http.addHeader("Content-Type", "application/x-www-form-urlencoded"); String postData = "user=" + userid; int httpCode = http.POST(postData); if (httpCode == HTTP_CODE_OK) { String response = http.getString(); //Serial.println(response); PORT = getValue(response, "port").toInt();

But now it just dont work anymore… an give exception even without the task scheduler on…

it gives an exception when i try to load the captive portal for example too

server.on("/", handleRoot); server.on("/generate_204", handleRoot); server.on("/fwlink", handleRoot); //Microsoft captive portal. Maybe not needed. Might be handled by notFound handler. server.onNotFound(handleNotFound); // server.on("/wifi", handleWifi); //server.on("/wifisave", handleWifiSave); //server.addHandler(new CaptiveRequestHandler()).setFilter(ON_AP_FILTER);//only when requested from AP server.begin();

##############

void handleNotFound(AsyncWebServerRequest *request) { if (!handleFileRead(request)) { if (captivePortal(request)) { // If captive portal, redirect instead of displaying the error page. return; //Serial.println("handle not found"); }

String message = F("File Not Found\n\n");
message += F("URI: ");
message += request->url();
message += F("\nMethod: ");
message += (request->method() == HTTP_GET) ? "GET" : "POST";
message += F("\nArguments: ");
message += request->args();
message += F("\n");

for (uint8_t i = 0; i < request->args(); i++) {
  message += String(F(" ")) + request->argName(i) + F(": ") + request->arg(i) + F("\n");
}

AsyncWebServerResponse *response = request->beginResponse(404, "text/plain", message);
response->addHeader("Cache-Control", "no-cache, no-store, must-revalidate");
response->addHeader("Pragma", "no-cache");
response->addHeader("Expires", "-1");
//Serial.println("handle not found sent headers");
request->send(response);

} }

void handleRoot(AsyncWebServerRequest request) { if (captivePortal(request)) { // If caprive portal redirect instead of displaying the page. return; } AsyncWebServerResponse response = request->beginResponse(SPIFFS, "/index.html", "text/html"); response->addHeader("Cache-Control", "no-cache, no-store, must-revalidate"); response->addHeader("Pragma", "no-cache"); response->addHeader("Expires", "-1"); request->send(response); } / Is this an IP? */ boolean isIp(String str) { for (size_t i = 0; i < str.length(); i++) { int c = str.charAt(i); if (c != '.' && (c < '0' || c > '9')) { return false; } } return true; }

/** IP to String? */ String toStringIp(IPAddress ip) { String res = ""; for (int i = 0; i < 3; i++) { res += String((ip >> (8 * i)) & 0xFF) + "."; } res += String(((ip >> 8 * 3)) & 0xFF); return res; }

boolean captivePortal(AsyncWebServerRequest *request) { if (!isIp(request->host()) && request->host() != (String(host) + ".local")) { Serial.println("Request redirected to captive portal"); AsyncWebServerResponse *response = request->beginResponse(302); response->addHeader("Location", String("http://") + toStringIp(request->client()->localIP())); request->send(response); // Send the response request->client()->close(); // Close the connection return true; } return false; }

sebosfato avatar Aug 20 '23 21:08 sebosfato

its also not allowing me to access the callback of the wifimanager and web update is also not working

(when you update from a server for example) sketch or spiffs

I really like how fast it works however with this exceptions im not able to put in my project yet… would be a very nice improvement on speed.

sebosfato avatar Aug 20 '23 21:08 sebosfato

It reduced the problem getting back to the older DNS library… although i couldnt still make the wifimanager call back work still

now the problem seems to be only when trying to make the web update or making the get and post requests from the server

anyone please have an idea of how can i get it?

sebosfato avatar Aug 21 '23 14:08 sebosfato