tzapu / WiFiManager

ESP8266 WiFi Connection manager with web captive portal
http://tzapu.com/esp8266-wifi-connection-manager-library-arduino-ide/
MIT License
6.63k stars 1.98k forks source link

WM with ESPAsyncWebserver #1121

Open dronecz opened 4 years ago

dronecz commented 4 years ago

Basic Infos

Hardware

WiFimanager Branch/Release:

Esp8266/Esp32:

Hardware: ESP-12e, esp01, esp25

ESP Core Version: 2.4.0, staging

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.

tablatronix commented 4 years ago

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

ortegafernando commented 4 years ago

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.

tablatronix commented 4 years ago

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

bigFin commented 3 years ago

BUMP!

tablatronix commented 3 years ago

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

fkoteam commented 3 years ago

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!

tablatronix commented 3 years ago

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.

dronecz commented 3 years ago

Awesome, can we help somehow?

tablatronix commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

Have you tried this yet?

dronecz commented 3 years ago

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?

tablatronix commented 3 years ago

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.

dronecz commented 3 years ago

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 commented 3 years ago

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

tablatronix commented 2 years ago

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

tablatronix commented 1 year ago

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

lucaoliano commented 8 months ago

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.

tablatronix commented 8 months ago

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