[GH-ISSUE #1121] WM with ESPAsyncWebserver #959

Open
opened 2026-02-28 01:27:51 +03:00 by kerem · 19 comments
Owner

Originally created by @dronecz on GitHub (Sep 6, 2020).
Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/1121

Basic Infos

Hardware

WiFimanager Branch/Release:

  • Master
  • Development

Esp8266/Esp32:

  • ESP8266
  • ESP32

Hardware: ESP-12e, esp01, esp25

  • ESP01
  • ESP12 E/F/S (nodemcu, wemos, feather)
  • Other

ESP Core Version: 2.4.0, staging

  • 2.3.0
  • 2.4.0
  • staging (master/dev)

Description

I´m looking for someone, who is willing to help me with adding ESPAsyncWebserver via #define in sketch like btomer did few years back. I did some work on this in my fork, but so far I can not compile sketch with this define.

Originally created by @dronecz on GitHub (Sep 6, 2020). Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/1121 ### Basic Infos #### Hardware **WiFimanager Branch/Release:** - [ ] Master - [x] Development **Esp8266/Esp32:** - [ ] ESP8266 - [x] ESP32 **Hardware: ESP-12e, esp01, esp25** - [ ] ESP01 - [ ] ESP12 E/F/S (nodemcu, wemos, feather) - [x] Other **ESP Core Version: 2.4.0, staging** - [ ] 2.3.0 - [ ] 2.4.0 - [ ] staging (master/dev) ### Description I´m looking for someone, who is willing to help me with adding ESPAsyncWebserver via `#define` in sketch like [btomer](https://github.com/btomer/WiFiManager) did few years back. I did some work on [this](https://github.com/dronecz/WiFiManager/commit/f197f9d2776fbb09af980c753d5efffb396685cd) in my fork, but so far I can not compile sketch with this define.
Author
Owner

@tablatronix commented on GitHub (Sep 6, 2020):

Ill take a look and add a branch, might be a few days

<!-- gh-comment-id:687680186 --> @tablatronix commented on GitHub (Sep 6, 2020): Ill take a look and add a branch, might be a few days
Author
Owner

@ortegafernando commented on GitHub (Sep 7, 2020):

Hi, may be this is a good start point or a good excuse to "join" both projects:

https://github.com/khoih-prog/ESP_WiFiManager

May be all collaborators of both projects could collaborate like a team in only one project, not to have to roads for the same finish.

<!-- gh-comment-id:688453917 --> @ortegafernando commented on GitHub (Sep 7, 2020): Hi, may be this is a good start point or a good excuse to "join" both projects: [https://github.com/khoih-prog/ESP_WiFiManager](https://github.com/khoih-prog/ESP_WiFiManager) May be all collaborators of both projects could collaborate like a team in only one project, not to have to roads for the same finish.
Author
Owner

@tablatronix commented on GitHub (Sep 7, 2020):

The async library is mostly compatible with the regualar one, so there is not much to do to add it, just some testing

<!-- gh-comment-id:688456968 --> @tablatronix commented on GitHub (Sep 7, 2020): The async library is mostly compatible with the regualar one, so there is not much to do to add it, just some testing
Author
Owner

@bigFin commented on GitHub (Dec 9, 2020):

BUMP!

<!-- gh-comment-id:741437808 --> @bigFin commented on GitHub (Dec 9, 2020): BUMP!
Author
Owner

@tablatronix commented on GitHub (Dec 9, 2020):

I am actually using it right now to see what we need to do

<!-- gh-comment-id:741473576 --> @tablatronix commented on GitHub (Dec 9, 2020): I am actually using it right now to see what we need to do
Author
Owner

@fkoteam commented on GitHub (Dec 10, 2020):

I am actually using it right now to see what we need to do

is it uploaded? what version should I use?

Thank you very much for your work!

<!-- gh-comment-id:742408554 --> @fkoteam commented on GitHub (Dec 10, 2020): > > > I am actually using it right now to see what we need to do is it uploaded? what version should I use? Thank you very much for your work!
Author
Owner

@tablatronix commented on GitHub (Dec 11, 2020):

Good news, it should work and be doable
Bad news, its alot of work, lots of refactoring, almost everything that uses the server needs to be changed.
I will start working on it a little bit and see , the problem is most of the arg and header stuff doe not work the same and has to be rewritten, even stopping the server is different syntax.

<!-- gh-comment-id:743436763 --> @tablatronix commented on GitHub (Dec 11, 2020): Good news, it should work and be doable Bad news, its alot of work, lots of refactoring, almost everything that uses the server needs to be changed. I will start working on it a little bit and see , the problem is most of the arg and header stuff doe not work the same and has to be rewritten, even stopping the server is different syntax.
Author
Owner

@dronecz commented on GitHub (Dec 11, 2020):

Awesome, can we help somehow?

<!-- gh-comment-id:743438067 --> @dronecz commented on GitHub (Dec 11, 2020): Awesome, can we help somehow?
Author
Owner

@tablatronix commented on GitHub (Dec 11, 2020):

I need to figure out what needs to change for the new ota upload, and to find the new syntax to get args.
I pushed a new branch, it is in progress, as far as I got atm. But its a start and you can see the changes in handleroot for sending headers now, I was going to make it the same codebase and swappable, but it is too much work atmm easier to just change it all, another 4-5 hours plus testing and it should be done

<!-- gh-comment-id:743456251 --> @tablatronix commented on GitHub (Dec 11, 2020): I need to figure out what needs to change for the new ota upload, and to find the new syntax to get args. I pushed a new branch, it is in progress, as far as I got atm. But its a start and you can see the changes in handleroot for sending headers now, I was going to make it the same codebase and swappable, but it is too much work atmm easier to just change it all, another 4-5 hours plus testing and it should be done
Author
Owner

@tablatronix commented on GitHub (Dec 14, 2020):

Its done, ready to test, there are a few things that might be broken, ota uploading has to be rewritten , esp32 not worked on yet, and url params not added back in for no scan and refresh

<!-- gh-comment-id:744747393 --> @tablatronix commented on GitHub (Dec 14, 2020): Its done, ready to test, there are a few things that might be broken, ota uploading has to be rewritten , esp32 not worked on yet, and url params not added back in for no scan and refresh
Author
Owner

@tablatronix commented on GitHub (Dec 18, 2020):

Have you tried this yet?

<!-- gh-comment-id:748188688 --> @tablatronix commented on GitHub (Dec 18, 2020): Have you tried this yet?
Author
Owner

@dronecz commented on GitHub (Dec 21, 2020):

Hi, sorry for delay, I had no time to try it until now. I implemented in my code and it works. I was able to connect to my AP via WM without problem.

Many thanks for this.

Is there something specific which you want me to test?

<!-- gh-comment-id:749002370 --> @dronecz commented on GitHub (Dec 21, 2020): Hi, sorry for delay, I had no time to try it until now. I implemented in my code and it works. I was able to connect to my AP via WM without problem. Many thanks for this. Is there something specific which you want me to test?
Author
Owner

@tablatronix commented on GitHub (Dec 21, 2020):

There are some gotchas that I need to continue to work on, but It should work ok. Just that it works, you can save, change reset, use params whatever you were doing before.

<!-- gh-comment-id:749022641 --> @tablatronix commented on GitHub (Dec 21, 2020): There are some gotchas that I need to continue to work on, but It should work ok. Just that it works, you can save, change reset, use params whatever you were doing before.
Author
Owner

@dronecz commented on GitHub (May 12, 2021):

Hi, sorry for long delay but I finally have time to make more work on my project with WM using ESPAsyncWebserver.

I tried OnDemandConfigPortal sketch and with async library does not scan and show networks. To confirm this I tried same sketch with latest alpha release and that one is working as it should.

Here is log:


[D][WiFiGeneric.cpp:374] _eventCallback(): Event: 0 - WIFI_READY
[D][WiFiGeneric.cpp:374] _eventCallback(): Event: 2 - STA_START

 Starting
*WM: [2] Starting Config Portal 
*WM: [3] WiFi station disconnect 
*WM: [3] WiFi_enableSTA enable
*WM: [2] Disabling STA 
*WM: [2] Enabling AP 
[D][WiFiGeneric.cpp:374] _eventCallback(): Event: 3 - STA_STOP
*WM: [1] StartAP with SSID:  OnDemandAP
*WM: [2] AP has anonymous access! 
[D][WiFiGeneric.cpp:374] _eventCallback(): Event: 0 - WIFI_READY
*WM: [1] SoftAP Configuration 
*WM: [1] -------------------- 
[D][WiFiGeneric.cpp:374] _eventCallback(): Event: 14 - AP_START
OnDemandAP
*WM: [1] password:         
*WM: [1] ssid_len:         10
*WM: [1] channel:          1
*WM: [1] authmode:        
*WM: [1] ssid_hidden:     
*WM: [1] max_connection:   4
*WM: [1] country:          CN 

*WM: [1] beacon_interval:  100(ms)
*WM: [1] -------------------- 
*WM: [1] AP IP address: 192.168.4.1
*WM: [3] setupConfigPortal 
*WM: [1] Starting Web Portal 
*WM: [3] dns server started with ip:  192.168.4.1
*WM: [2] WiFi Scan ASYNC started 
*WM: [2] Config Portal Running, blocking, waiting for clients...[D][WiFiGeneric.cpp:374] _eventCallback(): Event: 2 - STA_START

[D][WiFiGeneric.cpp:374] _eventCallback(): Event: 1 - SCAN_DONE
[D][WiFiGeneric.cpp:374] _eventCallback(): Event: 16 - AP_STACONNECTED
[D][WiFiGeneric.cpp:374] _eventCallback(): Event: 18 - AP_STAIPASSIGNED
*WM: [2] Portal Timeout In 103 seconds
*WM: [2] <- HTTP Root 
*WM: [3] lastconxresulttmp: WL_IDLE_STATUS
*WM: [3] lastconxresult: WL_DISCONNECTED
*WM: [2] WiFi Scan ASYNC started 
[D][WiFiGeneric.cpp:374] _eventCallback(): Event: 1 - SCAN_DONE
[W][AsyncTCP.cpp:969] _poll(): rx timeout 4
*WM: [2] <- HTTP Wifi 
*WM: [2] WiFi Scan ASYNC started 
*WM: [2] WiFi Scan ASYNC started 
*WM: [1] No networks found 
*WM: [3] lastconxresulttmp: WL_IDLE_STATUS
*WM: [3] lastconxresult: WL_DISCONNECTED
*WM: [3] Sent config page 
[D][WiFiGeneric.cpp:374] _eventCallback(): Event: 1 - SCAN_DONE
[W][AsyncTCP.cpp:969] _poll(): rx timeout 4
*WM: [2] <- HTTP Wifi 
*WM: [2] WiFi Scan ASYNC started 
*WM: [2] WiFi Scan ASYNC started 
*WM: [1] No networks found 
*WM: [3] lastconxresulttmp: WL_IDLE_STATUS
*WM: [3] lastconxresult: WL_DISCONNECTED
*WM: [3] Sent config page 
[D][WiFiGeneric.cpp:374] _eventCallback(): Event: 1 - SCAN_DONE
[W][AsyncTCP.cpp:969] _poll(): rx timeout 4
*WM: [2] Portal Timeout In 111 seconds
[W][AsyncTCP.cpp:969] _poll(): rx timeout 4
[W][AsyncTCP.cpp:969] _poll(): rx timeout 4
*WM: [2] <- HTTP Root 
*WM: [3] lastconxresulttmp: WL_IDLE_STATUS
*WM: [3] lastconxresult: WL_DISCONNECTED
*WM: [2] WiFi Scan ASYNC started 
[D][WiFiGeneric.cpp:374] _eventCallback(): Event: 1 - SCAN_DONE
*WM: [2] <- HTTP Info 
*WM: [3] lastconxresulttmp: WL_IDLE_STATUS
*WM: [3] lastconxresult: WL_DISCONNECTED
*WM: [3] Sent info page 
[W][AsyncTCP.cpp:969] _poll(): rx timeout 4
*WM: [2] <- HTTP Exit 
*WM: [3] configportal abort 
*WM: [2] disconnect configportal 
*WM: [0] [ERROR] disconnect configportal - softAPdisconnect FAILED 
*WM: [2] restoring usermode STA
*WM: [2] wifi status: WL_DISCONNECTED
*WM: [D][WiFiGeneric.cpp:374] _eventCallback(): Event: 15 - AP_STOP
[2] wifi mode: STA
*WM: [D][WiFiGeneric.cpp:374] _eventCallback(): Event: 15 - AP_STOP
failed to connect and hit timeout

Thanks for help.

<!-- gh-comment-id:840089847 --> @dronecz commented on GitHub (May 12, 2021): Hi, sorry for long delay but I finally have time to make more work on my project with WM using ESPAsyncWebserver. I tried [OnDemandConfigPortal](https://github.com/tzapu/WiFiManager/blob/master/examples/OnDemand/OnDemandConfigPortal/OnDemandConfigPortal.ino) sketch and with async library does not scan and show networks. To confirm this I tried same sketch with latest alpha release and that one is working as it should. Here is log: ``` [D][WiFiGeneric.cpp:374] _eventCallback(): Event: 0 - WIFI_READY [D][WiFiGeneric.cpp:374] _eventCallback(): Event: 2 - STA_START Starting *WM: [2] Starting Config Portal *WM: [3] WiFi station disconnect *WM: [3] WiFi_enableSTA enable *WM: [2] Disabling STA *WM: [2] Enabling AP [D][WiFiGeneric.cpp:374] _eventCallback(): Event: 3 - STA_STOP *WM: [1] StartAP with SSID: OnDemandAP *WM: [2] AP has anonymous access! [D][WiFiGeneric.cpp:374] _eventCallback(): Event: 0 - WIFI_READY *WM: [1] SoftAP Configuration *WM: [1] -------------------- [D][WiFiGeneric.cpp:374] _eventCallback(): Event: 14 - AP_START OnDemandAP *WM: [1] password: *WM: [1] ssid_len: 10 *WM: [1] channel: 1 *WM: [1] authmode: *WM: [1] ssid_hidden: *WM: [1] max_connection: 4 *WM: [1] country: CN  *WM: [1] beacon_interval: 100(ms) *WM: [1] -------------------- *WM: [1] AP IP address: 192.168.4.1 *WM: [3] setupConfigPortal *WM: [1] Starting Web Portal *WM: [3] dns server started with ip: 192.168.4.1 *WM: [2] WiFi Scan ASYNC started *WM: [2] Config Portal Running, blocking, waiting for clients...[D][WiFiGeneric.cpp:374] _eventCallback(): Event: 2 - STA_START [D][WiFiGeneric.cpp:374] _eventCallback(): Event: 1 - SCAN_DONE [D][WiFiGeneric.cpp:374] _eventCallback(): Event: 16 - AP_STACONNECTED [D][WiFiGeneric.cpp:374] _eventCallback(): Event: 18 - AP_STAIPASSIGNED *WM: [2] Portal Timeout In 103 seconds *WM: [2] <- HTTP Root *WM: [3] lastconxresulttmp: WL_IDLE_STATUS *WM: [3] lastconxresult: WL_DISCONNECTED *WM: [2] WiFi Scan ASYNC started [D][WiFiGeneric.cpp:374] _eventCallback(): Event: 1 - SCAN_DONE [W][AsyncTCP.cpp:969] _poll(): rx timeout 4 *WM: [2] <- HTTP Wifi *WM: [2] WiFi Scan ASYNC started *WM: [2] WiFi Scan ASYNC started *WM: [1] No networks found *WM: [3] lastconxresulttmp: WL_IDLE_STATUS *WM: [3] lastconxresult: WL_DISCONNECTED *WM: [3] Sent config page [D][WiFiGeneric.cpp:374] _eventCallback(): Event: 1 - SCAN_DONE [W][AsyncTCP.cpp:969] _poll(): rx timeout 4 *WM: [2] <- HTTP Wifi *WM: [2] WiFi Scan ASYNC started *WM: [2] WiFi Scan ASYNC started *WM: [1] No networks found *WM: [3] lastconxresulttmp: WL_IDLE_STATUS *WM: [3] lastconxresult: WL_DISCONNECTED *WM: [3] Sent config page [D][WiFiGeneric.cpp:374] _eventCallback(): Event: 1 - SCAN_DONE [W][AsyncTCP.cpp:969] _poll(): rx timeout 4 *WM: [2] Portal Timeout In 111 seconds [W][AsyncTCP.cpp:969] _poll(): rx timeout 4 [W][AsyncTCP.cpp:969] _poll(): rx timeout 4 *WM: [2] <- HTTP Root *WM: [3] lastconxresulttmp: WL_IDLE_STATUS *WM: [3] lastconxresult: WL_DISCONNECTED *WM: [2] WiFi Scan ASYNC started [D][WiFiGeneric.cpp:374] _eventCallback(): Event: 1 - SCAN_DONE *WM: [2] <- HTTP Info *WM: [3] lastconxresulttmp: WL_IDLE_STATUS *WM: [3] lastconxresult: WL_DISCONNECTED *WM: [3] Sent info page [W][AsyncTCP.cpp:969] _poll(): rx timeout 4 *WM: [2] <- HTTP Exit *WM: [3] configportal abort *WM: [2] disconnect configportal *WM: [0] [ERROR] disconnect configportal - softAPdisconnect FAILED *WM: [2] restoring usermode STA *WM: [2] wifi status: WL_DISCONNECTED *WM: [D][WiFiGeneric.cpp:374] _eventCallback(): Event: 15 - AP_STOP [2] wifi mode: STA *WM: [D][WiFiGeneric.cpp:374] _eventCallback(): Event: 15 - AP_STOP failed to connect and hit timeout ``` Thanks for help.
Author
Owner

@dronecz commented on GitHub (Aug 16, 2021):

@tablatronix any hint on this one? I looked on this again and difference is somewhere in autoConnect() function. If I comment out call to this function and start configportal manually by pressing button, I do not see any networks. Also value of _lastscan variable is not reset when reach 60 seconds.

<!-- gh-comment-id:899564874 --> @dronecz commented on GitHub (Aug 16, 2021): @tablatronix any hint on this one? I looked on this again and difference is somewhere in `autoConnect()` function. If I comment out call to this function and start configportal manually by pressing button, I do not see any networks. Also value of `_lastscan` variable is not reset when reach 60 seconds.
Author
Owner

@tablatronix commented on GitHub (Feb 23, 2022):

I merged master back into this and resolved conflicts, ota seems all jacked up, code needs to be updated.

Backport the following methods to abstact master to prepare for cross compile..

  • setupHTTPServer

  • teardownHTTPServer

  • setupDNSD

  • HTTPSend

  • template all web handlers with arguments to allow both or other webservers objects or globals

  • fix ota code

<!-- gh-comment-id:1049271834 --> @tablatronix commented on GitHub (Feb 23, 2022): I merged master back into this and resolved conflicts, ota seems all jacked up, code needs to be updated. Backport the following methods to abstact master to prepare for cross compile.. - [ ] setupHTTPServer - [ ] teardownHTTPServer - [ ] setupDNSD - [ ] HTTPSend - [ ] template all web handlers with arguments to allow both or other webservers objects or globals - [ ] fix ota code
Author
Owner

@tablatronix commented on GitHub (May 11, 2023):

My idea was to make WM compatible with both or any webserver, but I have no idea how to get this working ideally.

I want to keep route callbacks as seperate methods, which means lots of functions to deal with.
therefore I want to avoid having to have overloads for these callbacks..

My idea was to use a template to have either local server pointer or async resp obj as the first argument. Now i dont want to pass the local pointer all the way through the webserver binds thats just asking for problems, and the syntax structures might be different. so instead i want to pass an empty arg for this, I want to also avoid adding variadic args to avoid the overhead etc as we do not really need it.

I also do not want to refactor the entire web handling into some abstract class or something more complex.

Idea is like

template <typename T>
void          callbacknofmany(T *obj, bool argx);



std::unique_ptr<choiceserver> server;

server->on("", HTTP_ANY, std::bind(&myclass::callbacknofmany, this, null , true)); // sync - global or server pointer
server->on("", HTTP_ANY, std::bind(&myclass::callbacknofmany, this, std::placeholders::_1, true)); // async  - local response obj


template <typename T>
void myClass::callbacknofmany(T *serverobj, bool argx) {
    if(serverobj) serverobj->sendresponse();
    else server->sendresponse()
}

I just am not sure if this is the best route, or how to properly do the templates, nullptr has issues, so just going with something empty and adding a check in the callbacks seems easier

<!-- gh-comment-id:1544431840 --> @tablatronix commented on GitHub (May 11, 2023): My idea was to make WM compatible with both or any webserver, but I have no idea how to get this working ideally. I want to keep route callbacks as seperate methods, which means lots of functions to deal with. therefore I want to avoid having to have overloads for these callbacks.. My idea was to use a template to have either local server pointer or async resp obj as the first argument. Now i dont want to pass the local pointer all the way through the webserver binds thats just asking for problems, and the syntax structures might be different. so instead i want to pass an empty arg for this, I want to also avoid adding variadic args to avoid the overhead etc as we do not really need it. I also do not want to refactor the entire web handling into some abstract class or something more complex. Idea is like ```c++ template <typename T> void callbacknofmany(T *obj, bool argx); std::unique_ptr<choiceserver> server; server->on("", HTTP_ANY, std::bind(&myclass::callbacknofmany, this, null , true)); // sync - global or server pointer server->on("", HTTP_ANY, std::bind(&myclass::callbacknofmany, this, std::placeholders::_1, true)); // async - local response obj template <typename T> void myClass::callbacknofmany(T *serverobj, bool argx) { if(serverobj) serverobj->sendresponse(); else server->sendresponse() } ``` I just am not sure if this is the best route, or how to properly do the templates, nullptr has issues, so just going with something empty and adding a check in the callbacks seems easier
Author
Owner

@lucaoliano commented on GitHub (Mar 8, 2024):

Hi @tablatronix,
on my fork I have an implementation that supports both WebServer and AsyncWebServer. Can you take a look at it? If you think it would be good, I'm happy to contribute with a PR.

<!-- gh-comment-id:1985695065 --> @lucaoliano commented on GitHub (Mar 8, 2024): Hi @tablatronix, on my [fork](https://github.com/lucaoliano/WiFiManager/tree/async_webserver) I have an implementation that supports both WebServer and AsyncWebServer. Can you take a look at it? If you think it would be good, I'm happy to contribute with a PR.
Author
Owner

@tablatronix commented on GitHub (Mar 8, 2024):

Thanks, I was hoping to find a way to do it much cleaner than having all those blocks, makes maintenance a nightmare and code legibility is a mess

<!-- gh-comment-id:1986555544 --> @tablatronix commented on GitHub (Mar 8, 2024): Thanks, I was hoping to find a way to do it much cleaner than having all those blocks, makes maintenance a nightmare and code legibility is a mess
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/WiFiManager#959
No description provided.