WiFiManager icon indicating copy to clipboard operation
WiFiManager copied to clipboard

WM with ESPAsyncWebserver

Open dronecz opened this issue 4 years ago • 19 comments

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 did few years back. I did some work on this in my fork, but so far I can not compile sketch with this define.

dronecz avatar Sep 06 '20 00:09 dronecz

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

tablatronix avatar Sep 06 '20 00:09 tablatronix

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.

ortegafernando avatar Sep 07 '20 17:09 ortegafernando

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

tablatronix avatar Sep 07 '20 17:09 tablatronix

BUMP!

bigFin avatar Dec 09 '20 01:12 bigFin

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

tablatronix avatar Dec 09 '20 02:12 tablatronix

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!

fkoteam avatar Dec 10 '20 09:12 fkoteam

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.

tablatronix avatar Dec 11 '20 21:12 tablatronix

Awesome, can we help somehow?

dronecz avatar Dec 11 '20 21:12 dronecz

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

tablatronix avatar Dec 11 '20 22:12 tablatronix

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

tablatronix avatar Dec 14 '20 22:12 tablatronix

Have you tried this yet?

tablatronix avatar Dec 18 '20 16:12 tablatronix

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?

dronecz avatar Dec 21 '20 14:12 dronecz

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.

tablatronix avatar Dec 21 '20 15:12 tablatronix

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.

dronecz avatar May 12 '21 20:05 dronecz

@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.

dronecz avatar Aug 16 '21 14:08 dronecz

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

tablatronix avatar Feb 23 '22 22:02 tablatronix

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

tablatronix avatar May 11 '23 17:05 tablatronix

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.

lucaoliano avatar Mar 08 '24 13:03 lucaoliano

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

tablatronix avatar Mar 08 '24 23:03 tablatronix