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

ESP32 - WebServer not reachable in AP STA mode in Win10 #658

Open Mirdox opened 6 years ago

Mirdox commented 6 years ago

Hardware

WiFimanager Branch/Release: Development

Esp32: WROOM32

Description

Hello there,

I'm facing really weird issue and I'm not sure what is it related to. When WiFi is not configured, everything is working as expected. After the WiFi is configured and the ESP32 goes to AP STA mode, the WebServer (OnDemand Portal) cannot be accessed by some devices. Computer with Windows 10 cannot access the web server, never, while the same computer with Ubuntu can access the web server. Computer with Windows 7 can always access the WebServer, Android phone can sometimes access the Webserver. All devices are for sure connected to ESP access point, but the web service isn't simple there. I've tried also with telnet.

Does anybody have this issue? Any Ideas?

Thank you

Sketch

Advanced Example Sketch

tablatronix commented 6 years ago

Are you sure the configportal is running ? Do you mean the captive portal doesn't work , what happens if you use ip address?

What does serial say?

Mirdox commented 6 years ago

Hello,

The configportal is running, because I'm able to access it from another clients, e.g. Win7 or Linux. It isn't problem of the captive portal, i'm only using ip address to access the configportal.

The serial says nothing, no debug messages when I'm trying to open configportal from Win10 computer or android phone. I've also tried to disable FW, so this should not be the issue. It looks like there is no service listening. I was trying telnet, nmap port scan, browser. The Win10 and Android is for sure connected to the AP, I've add debug messages for that.

When I disconnect the ESP32 from network, the configportal is accessible.

The on demand config portal is also accessible when I add wm.disconnect(); before wm.startConfigPortal("OnDemandAP"); but that's just a workarround.

Thanks for quick response.

tablatronix commented 6 years ago

Ok was just making sure you were not connecting to the esp softap that it runs on boot if persistent saved it. Then of course webserver is not available.

tablatronix commented 6 years ago

build_flags = -DESP32 -DCORE_DEBUG_LEVEL=5 might help

So what exactly is in the wm logs

tablatronix commented 6 years ago

There are some known issue with android security and captive portal, but if accessing via ip it has been known to work. I do not have windows 10 here, but I have used it fairly recently and do not recall any issues. I will try to fire up my vm

Mirdox commented 6 years ago

Hello,

I've tried core debug before with no success and I've reproduced it now. Maybe you will notice something. Maybe this issue is OS related, but the weird thing is, that I'm not able to connect to config portal only in AP STA mode, when STA is disconnected, it works as expected.

 Starting
*WM: Added Parameter: customfield
*WM: AutoConnect 
[D][WiFiGeneric.cpp:345] _eventCallback(): Event: 13 - AP_START
[D][WiFiGeneric.cpp:345] _eventCallback(): Event: 13 - AP_START
[D][WiFiGeneric.cpp:345] _eventCallback(): Event: 0 - WIFI_READY
*WM: ESP32 event handler enabled[D][WiFiGeneric.cpp:345] _eventCallback(): Event: 14 - AP_STOP

*WM: Connecting as wifi client... 
*WM: Connecting to saved AP: ROUTER_AP
*WM: connectTimeout not set, ESP waitForConnectResult... 
[D][WiFiGeneric.cpp:345] _eventCallback(): Event: 4 - STA_CONNECTED
[D][WiFiGeneric.cpp:345] _eventCallback(): Event: 7 - STA_GOT_IP
[D][WiFiGeneric.cpp:386] _eventCallback(): STA IP: 192.168.1.105, MASK: 255.255.255.0, GW: 192.168.1.1
*WM: Connection result: WL_CONNECTED
*WM: AutoConnect: SUCCESS 
*WM: STA IP Address: 192.168.1.105
connected...yeey :)

Here I've pressed the button

Starting config portal
*WM: Enabling AP 
*WM: StartAP with SSID:  OnDemandAP
*WM: AP has anonymous access! 
[D][WiFiGeneric.cpp:345] _eventCallback(): Event: 14 - AP_STOP
[D][WiFiGeneric.cpp:345] _eventCallback(): Event: 13 - AP_START
[D][WiFiGeneric.cpp:345] _eventCallback(): Event: 13 - AP_START
*WM: AP IP address: 192.168.4.1
*WM: Starting Web Portal 
*WM: HTTP server started 
[D][WiFiGeneric.cpp:345] _eventCallback(): Event: 1 - SCAN_DONE
*WM: WiFi Scan done 
*WM: Config Portal Running, blocking, waiting for clients...

Here I've connected Android phone and opened 192.168.4.1

[D][WiFiGeneric.cpp:345] _eventCallback(): Event: 15 - AP_STACONNECTED
*WM: Portal Timeout In 109 seconds
[D][WiFiGeneric.cpp:345] _eventCallback(): Event: 17 - AP_STAIPASSIGNED
*WM: <- HTTP Root 
[D][WiFiGeneric.cpp:345] _eventCallback(): Event: 1 - SCAN_DONE
*WM: WiFi Scan done 
[I][WiFiClient.cpp:443] connected(): Disconnected: RES: 0, ERR: 128
*WM: <- Request redirected to captive portal 
[I][WiFiClient.cpp:443] connected(): Disconnected: RES: 0, ERR: 128

Here I've connected Windows 10 computer and opened 192.168.4.1, no further logs

*WM: Portal Timeout In 110 seconds
[D][WiFiGeneric.cpp:345] _eventCallback(): Event: 15 - AP_STACONNECTED
[D][WiFiGeneric.cpp:345] _eventCallback(): Event: 17 - AP_STAIPASSIGNED
*WM: Portal Timeout In 80 seconds
*WM: Portal Timeout In 50 seconds

What you mean by:

Ok was just making sure you were not connecting to the esp softap that it runs on boot if persistent saved it. Then of course webserver is not available.

? Maybe I'm missing something.

Thank you

tablatronix commented 6 years ago

usually the opposite is true, when in sta ap mode and sta is failing it fails to work.

Are you saying the opposite when connected to your ap and running configportal ( sta+ap ) your connects fail sometimes?

It sounds like a channel issue. Have you pulled in the most recent commits for esp32?

tablatronix commented 6 years ago

The esp clearly shows your sta connecting to it, hmm it does seem like your client will not make the http request, maybe it is a firewall or security issue.

I will keep testing, but it does in fact seem like a client issue, maybe check wireshark?

Mirdox commented 6 years ago

Yes, connecting to AP fails sometimes. I'm using the most up-to-date version.

Wireshark was a good idea, but still no clue what is going on.

When STA is disconnected, the client (Win10) makes some initial handshake with ESP32: random client port -> esp port 80 - SYN esp port 80 -> random client port - SYN-ACK random client port -> esp port 80 - ACK HTTP GET REQUEST after this handshake Just like described here http://blog.catchpoint.com/2010/09/17/anatomyhttp/

When STA is connected, the client (Win10) fails to make this initial handshake while trying to connect to ESP32. Win10 sends the first SYN, but no SYN-ACK is received from ESP.

I believe the ESP32 doesn't send this SYN-ACK in some cases.

I will try to compare it with Win7 later.

Have you experienced this before?

Thank you

tablatronix commented 6 years ago

Ooh could it have something to do with the ip address? Different class when on the 2 networks.

Mirdox commented 6 years ago

IP address, mask, default gateway seem to be OK. Also ip routing is identical with computer on which it works without issues.

Thank you for help, don't waste time with it.

tablatronix commented 6 years ago

I don't mean there is something wrong I mean the computer is refusing to connect to that ip address for security reasons due the ip class itself.

what ip classes are on your 2 networks ?

Yeah this almost sounds like a esp bug, but to test you would need to use the webserver example and test in sta and ap mode, without wifimanager being involved.

Mirdox commented 6 years ago

On station I'm using 192.168.1.x

On AP, I've now tried some more ip configs. 10.0.1.1 192.168.2.1 192.168.4.1 Win10 didn't work, Win7 worked on all of them, Android worked only on 192.168.4.1.

Thanks, I'll try pure webserver.