mirror of
https://github.com/tzapu/WiFiManager.git
synced 2026-04-27 17:15:53 +03:00
[GH-ISSUE #1530] Incompatibility with ESP32 ESPAsyncWebServer #1305
Labels
No labels
📶 WiFi
🕸️ HTTP
Branch
DEV Help Wanted
Discussion
Documentation
ESP32
Example
Good First Issue
Hotfix
In Progress
Incomplete
Needs Feeback
Priority
QA
Question
Task
Upstream/Dependancy
bug
duplicate
enhancement
invalid
pull-request
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/WiFiManager#1305
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @joba-1 on GitHub (Dec 13, 2022).
Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/1530
Basic Infos
Hardware
WiFimanager Branch/Release: Master
Esp8266/Esp32:
Hardware: ESP32 Wroom32
Core Version: tested latest stable and staging
Description
When migrating firmware from using standard WebServer to ESPAsyncWebserver there are conflicts and compile fails
Would be nice if I could still use WiFiManager to provision WLAN and not cook my own!
Settings in IDE
Module: mhetesp32minikit
[env:mhetesp32minikit]
platform = espressif32
; platform_packages = platformio/framework-arduinoespressif32 @ https://github.com/espressif/arduino-esp32.git
board = mhetesp32devkit
framework = arduino
Additional libraries:
lib_deps =
https://github.com/tzapu/WiFiManager.git
ESP Async WebServer
Sketch
Debug Messages
@joba-1 commented on GitHub (Dec 13, 2022):
I worked a bit on this myself and found the errors are "only" compile time errors.
If I split code of WiFiManager and ESPAsyncWebserver in two compilation units, so that #include <ESPAsyncWebServer.h> and #include <WiFiManager.h> are not in the same file, then it basically works.
Only gripe left: if the WiFiManager actually opens the portal webserver, it seems the listen port is not released:
After a reboot (without wifi setup) the async webserver binds and works fine
Not sure what -8 means. I suspected port in use, but SO_REUSEADDR is on by default...
@joba-1 commented on GitHub (Dec 13, 2022):
Found yet another "solution":
include WiFiManager first. ESPAsyncWebServer is already prepared to not redefine the conflicting symbols if the standard webserver is already included.
the bind error remains though...
@joba-1 commented on GitHub (Dec 14, 2022):
see https://github.com/tzapu/WiFiManager/tree/feature_asyncwebserver
I assume it is compatible ;)
@tablatronix commented on GitHub (Dec 14, 2022):
Yeah port issues are a problem no idea what the cause is. Never figured it out
@joba-1 commented on GitHub (Dec 15, 2022):
Well, I still would like to get rid of it.
Hope you don't mind if I note here what I found so far.
Feel free to comment, even if it is just "been there, done that" again :)
What I found out so far:
Sooo,
will try that later...
@tablatronix commented on GitHub (Dec 15, 2022):
It shouldn't have anything to do with it, the webserver obj is closed and deleted, the ESP lib is not allowing the port to rebind for some reason.
@tablatronix commented on GitHub (Dec 16, 2022):
As soon as I get 2.0 released I will work on reworking the async branch so it can be optional in main.
And maybe work on debugging this port issue one day
@joba-1 commented on GitHub (Dec 18, 2022):
I gave up on ESPAsyncWebServer restarts.
I reduced my test firmware to just serve a /restart page to initiate a delayed webserver restart (and added prints to all relevant constructors and destructors).
Still the port sometimes cannot be reallocated although all constructor/destructor pairs are visible before the actual restart. And sometimes it just works.
I'll just use ESP restarts if your WiFiManager portal was active. Fine for my usecases.
@tablatronix commented on GitHub (Dec 18, 2022):
Yeah its really an esp bug
@joba-1 commented on GitHub (Dec 24, 2022):
couldn't let it rest :D
so far I never got "port in use" when using this code (called in loop()):
don`t know if it matters, but I use ottowinter/ESPAsyncWebServer-esphome
@ear9mrn commented on GitHub (Jan 14, 2024):
I just came across the same issue. It sort of works if you call/run wifimanager first then espasyncwebserver second although I have found this still has issues. The way that the http call methods are defined as noted in above errors are different in their respective header files.
webserver.h
/* Request Methods */ #define HTTP_METHOD_MAP(XX) \ XX(0, DELETE, DELETE) \ XX(1, GET, GET) \ XX(2, HEAD, HEAD) \ XX(3, POST, POST) \ XX(4, PUT, PUT) \ESPAsyncWebServer.h
typedef enum { HTTP_GET = 0b00000001, HTTP_POST = 0b00000010, HTTP_DELETE = 0b00000100, HTTP_PUT = 0b00001000,GET is fine as both = 1, but any other method and the values do not correspond. As such, I was getting onNotFound for anything other than GET when using wifimanager followed by ESPAsyncWebServer. My solution was to manually enter the values that correspond to the ESPAsyncWebServer methods rather than use the defined values, like HTTP_POST. For example:
if (request->method() == 64) {} //for HTTP_OPTIONSdue to HTTP_OPTIONS = 64 as defined by ESPAsyncWebServer
HTTP_OPTIONS = 0b01000000,and it is 6 with Webserver.h:
(XX(6, OPTIONS, OPTIONS) \):Any suggested remedy for this dilemma other than manually defining my own method values?
Thanks,
Pete.
@ear9mrn commented on GitHub (Jan 14, 2024):
Just to be clear as to my solution:
//redefine HTTP methods as per ESPAsyncWebserver.h typedef enum { MY_HTTP_GET = 0b00000001, MY_HTTP_POST = 0b00000010, MY_HTTP_DELETE = 0b00000100, MY_HTTP_PUT = 0b00001000, MY_HTTP_PATCH = 0b00010000, MY_HTTP_HEAD = 0b00100000, MY_HTTP_OPTIONS = 0b01000000, MY_HTTP_ANY = 0b01111111, } my_http_methods;a POST response would look like this:
server.on("/getinfo", MY_HTTP_POST, [] (AsyncWebServerRequest *request){ request->send(200, "text/plain", "OK"); });and onNotFound:
//needed for CORS if (request->method() == MY_HTTP_OPTIONS ) { request->send(200, "plain/text", "OK"); } else { request->send(404, "plain/text", "not found"); }Hope this helps others.
@qinst64 commented on GitHub (Jan 21, 2024):
I also got the same errors, not so complete for above answers, there is my summary
Reason
ESPAsyncWebServerconflicts withESP8266WebServer(required byWiFiManager) onHTTP_XXXESPAsyncWebServerhandles by checks#ifndef WEBSERVER_H, howeverESP8266WebServerdoes#define ESP8266WEBSERVER_H. So simply changing the importing order will not work.Method 1
Just write like this
note: need to include
WiFiManager.hfirst, and defineWEBSERVER_Has anthing beforeESPAsyncWebServerMethod 2
Go to
arduino/libraries/ESPAsyncWebServer, replace allHTTP_withMY_HTTP_. There are more than 50+ occurrences. This can be easily done by IDE like VSCode.Then no conficts any more, however in your code should also use
MY_HTTP_XXXinstead ofHTTP_XXXConclusion
Method 1 is suggested
@tablatronix commented on GitHub (Jan 21, 2024):
You are trying to run these togather?
Have you tried the async branch ?
@qinst64 commented on GitHub (Jan 22, 2024):
nope.
ESPAsync_WiFiManageris archived,ESPAsyncWiFiManageris not actively maintained(2 yr ago).@tablatronix commented on GitHub (Jan 22, 2024):
Those are forks
@grantnorwood commented on GitHub (May 31, 2024):
Another solution folks may encounter is when using ESPAsyncWebServer and WiFiManager in separate class files, and those class files aren't ordered correctly. Especially if your IDE likes to re-order includes alphabetically on its own 🤦
In this case, just add
#include <WiFiManager.h>to yourmain.cppand ensure it's ordered before your class files. This works great for me using VS Code and PlatformIO!@gpena208777 commented on GitHub (Aug 31, 2024):
This worked!
Thanks so much