espressif / arduino-esp32

Arduino core for the ESP32
GNU Lesser General Public License v2.1
13.33k stars 7.36k forks source link

DNS captive portal example works for android in release 2.0.17, but not in 3.x #10330

Open esptini opened 1 week ago

esptini commented 1 week ago

Board

esp32-s2 dev module

Device Description

generic, wifi issue, no hardware effected or needed to reproduce

Hardware Configuration

nothing

Version

v3.0.4

IDE Name

arduino 1.8.19

Operating System

win10

Flash frequency

80

PSRAM enabled

no

Upload speed

921600

Description

CaptivePortal.ino example sketch from the DNSServer library, no modifications to code.

working example works in v2.x, meaning a samsung s23 running android 14 will load the captive portal automatically when connecting to the SoftAP. ios also works.

https://github.com/espressif/arduino-esp32/blob/release/v2.x/libraries/DNSServer/examples/CaptivePortal/CaptivePortal.ino

Not Working example in v3.x, meaning a samsung s23 running android 14 will NOT load the captive portal automatically when connecting to the SoftAP. it can be accessed via the browser when forced to stay connected, but not reliable nor a good user experience. ios devices do not have the issue, they work.

https://github.com/espressif/arduino-esp32/blob/release/v3.1.x/libraries/DNSServer/examples/CaptivePortal/CaptivePortal.ino

Note: there have been many documented issues of esp32 captive portals not loading on newer android devices for over 4 years. some work around methods point blame at the use of certain private IPs used for the soft AP of the esp32, and other solutions mention the issue is related to the http responses 200 vs 302, etc.

i am still trying to figure out why this works in v2 and not in v3, but this may be over my head as I am out of ideas. I think having the official example working would benefit many people that may be searching for a solution also.

Sketch

working

https://github.com/espressif/arduino-esp32/blob/release/v2.x/libraries/DNSServer/examples/CaptivePortal/CaptivePortal.ino

not working (for android 14 devices)

https://github.com/espressif/arduino-esp32/blob/release/v3.1.x/libraries/DNSServer/examples/CaptivePortal/CaptivePortal.ino

Debug Message

none, both compile and run

Other Steps to Reproduce

No response

I have checked existing issues, online documentation and the Troubleshooting Guide

esptini commented 1 week ago

this issue also plagues many of the countless wifi manager libraries out there. i cannot find a definitive root cause amongst the misinformation.

lbernstone commented 1 week ago

Please set core debug logging to verbose, upload the code, and post a log of the whole transaction (wifi/dhcp/dns/http). I don't have an android 14 device to test.

esptini commented 6 days ago

note: i have reason to believe this is a samsung specific issue based on my own testing and what i have read, and does not effect all android deviecs.

i am new to the core debug option. before i post the logs from all my devices on both releases, is this all that I should see? i feel like the http raw data should be shown?

this is the working version, just to confirm it's the logging you need.

ESP-ROM:esp32s2-rc4-20191025 Build:Oct 25 2019 rst:0x1 (POWERON),boot:0x8 (SPI_FAST_FLASH_BOOT) SPIWP:0xee mode:DIO, clock div:1 load:0x3ffe6100,len:0x55c load:0x4004c000,len:0xa70 load:0x40050000,len:0x29d8 entry 0x4004c18c [ 629][V][WiFiServer.h:42] WiFiServer(): WiFiServer::WiFiServer(port=80, ...) [ 649][D][WiFiGeneric.cpp:1040] _eventCallback(): Arduino Event: 0 - WIFI_READY [ 694][V][WiFiGeneric.cpp:393] _arduino_event_cb(): AP Started [ 700][D][WiFiGeneric.cpp:1040] _eventCallback(): Arduino Event: 10 - AP_START [ 711][V][WiFiGeneric.cpp:396] _arduino_event_cb(): AP Stopped [ 717][D][WiFiGeneric.cpp:1040] _eventCallback(): Arduino Event: 11 - AP_STOP [ 726][V][WiFiGeneric.cpp:393] _arduino_event_cb(): AP Started [ 735][D][WiFiGeneric.cpp:1040] _eventCallback(): Arduino Event: 10 - AP_START [ 745][V][WiFiGeneric.cpp:97] set_esp_interface_ip(): Configuring SoftAP static IP: 8.8.4.4, MASK: 255.255.255.0, GW: 8.8.4.4 [ 758][V][WiFiGeneric.cpp:143] set_esp_interface_ip(): SoftAP: 8.8.4.4 | Gateway: 8.8.4.4 | DHCP Start: 0.0.0.0 | Netmask: 255.255.255.0 [ 771][V][WiFiGeneric.cpp:190] set_esp_interface_ip(): DHCP Server Range: 8.8.4.5 to 8.8.4.15 [ 17963][V][WiFiGeneric.cpp:408] _arduino_event_cb(): AP Station Connected: MAC: 92:bf:84:18:48:10, AID: 1 [ 17973][D][WiFiGeneric.cpp:1040] _eventCallback(): Arduino Event: 12 - AP_STACONNECTED [ 18125][V][WiFiGeneric.cpp:422] _arduino_event_cb(): AP Station IP Assigned:8.8.4.5 [ 18132][D][WiFiGeneric.cpp:1040] _eventCallback(): Arduino Event: 14 - AP_STAIPASSIGNED

TD-er commented 6 days ago

Why is DHCP start set to 0.0.0.0? As far as I can remember the DHCP IP-pool is quite limited in the network code (like /24 max) Also why do you set the softAP's IP-address to one of google's DNS IPs of 8.8.4.4? Was this range also working with 2.0.17 on this phone? Just to make sure it isn't something in the network code of Android checking for probably local or global IP-ranges.

esptini commented 6 days ago

that's the first thing i tried, making the AP IP 8.8.4.4 like the v2 debug shown. i am not sure why DHCP is showing to 0.0.0.0 but this is the debug that mostly works. the portal is not automatic, but my samsung DOES show a "sign into network" message and clicking it takes you to the portal. that may be as good as it gets.

from what i have read, there are reports of mixed results using work around of different private and public IP ranges all over the internet. there could be something to that, but I believe there could be multiple causes since 8.8.4.4 does not seem to work with the newer code. something else is different also. i will post the debug of v3.x now

esptini commented 6 days ago

debug from 3.x esp32-core and 3.x DNS captive portal example sketch which is different from 2.x sketch.

⸮ESP-ROM:esp32s2-rc4-20191025
Build:Oct 25 2019
rst:0x1 (POWERON),boot:0x8 (SPI_FAST_FLASH_BOOT)
SPIWP:0xee
mode:DIO, clock div:1
load:0x3ffe6110,len:0x1188
load:0x4004b000,len:0x4
load:0x4004b004,len:0xa04
load:0x4004f000,len:0x338c
entry 0x4004b164
[   722][V][esp32-hal-periman.c:235] perimanSetBusDeinit(): Deinit function for type UART_RX (2) successfully set to 0x40090930
[   734][V][esp32-hal-periman.c:235] perimanSetBusDeinit(): Deinit function for type UART_TX (3) successfully set to 0x40090900
[   747][V][esp32-hal-periman.c:235] perimanSetBusDeinit(): Deinit function for type UART_CTS (4) successfully set to 0x400908d0
[   760][V][esp32-hal-periman.c:235] perimanSetBusDeinit(): Deinit function for type UART_RTS (5) successfully set to 0x400908a0
[   774][V][esp32-hal-periman.c:235] perimanSetBusDeinit(): Deinit function for type UART_RX (2) successfully set to 0x40090930
[   787][V][esp32-hal-periman.c:235] perimanSetBusDeinit(): Deinit function for type UART_TX (3) successfully set to 0x40090900
[   801][V][esp32-hal-periman.c:235] perimanSetBusDeinit(): Deinit function for type UART_CTS (4) successfully set to 0x400908d0
[   814][V][esp32-hal-periman.c:235] perimanSetBusDeinit(): Deinit function for type UART_RTS (5) successfully set to 0x400908a0
[   828][V][NetworkServer.h:41] NetworkServer(): NetworkServer::NetworkServer(port=80, ...)
[   838][V][WebServer.cpp:55] WebServer(): WebServer::Webserver(port=80)
[   855][V][esp32-hal-periman.c:160] perimanSetPinBus(): Pin 44 successfully set to type UART_RX (2) with bus 0x3ffc2bc8
[   866][V][esp32-hal-periman.c:160] perimanSetPinBus(): Pin 43 successfully set to type UART_TX (3) with bus 0x3ffc2bc8
=========== Before Setup Start ===========
Chip Info:
------------------------------------------
  Model             : ESP32-S2
  Package           : 0
  Revision          : 0
  Cores             : 1
  CPU Frequency     : 240 MHz
  XTAL Frequency    : 40 MHz
  Features Bitfield : 0x00000002
  Embedded Flash    : No
  Embedded PSRAM    : No
  2.4GHz WiFi       : Yes
  Classic BT        : No
  BT Low Energy     : No
  IEEE 802.15.4     : No
------------------------------------------
INTERNAL Memory Info:
------------------------------------------
  Total Size        :   219864 B ( 214.7 KB)
  Free Bytes        :   193140 B ( 188.6 KB)
  Allocated Bytes   :    23928 B (  23.4 KB)
  Minimum Free Bytes:   192828 B ( 188.3 KB)
  Largest Free Block:   180212 B ( 176.0 KB)
------------------------------------------
Flash Info:
------------------------------------------
  Chip Size         :  4194304 B (4 MB)
  Block Size        :    65536 B (  64.0 KB)
  Sector Size       :     4096 B (   4.0 KB)
  Page Size         :      256 B (   0.2 KB)
  Bus Speed         : 80 MHz
  Bus Mode          : QIO
------------------------------------------
Partitions Info:
------------------------------------------
                nvs : addr: 0x00009000, size:    20.0 KB, type: DATA, subtype: NVS
            otadata : addr: 0x0000E000, size:     8.0 KB, type: DATA, subtype: OTA
               app0 : addr: 0x00010000, size:  1280.0 KB, type:  APP, subtype: OTA_0
               app1 : addr: 0x00150000, size:  1280.0 KB, type:  APP, subtype: OTA_1
             spiffs : addr: 0x00290000, size:  1408.0 KB, type: DATA, subtype: SPIFFS
           coredump : addr: 0x003F0000, size:    64.0 KB, type: DATA, subtype: COREDUMP
------------------------------------------
Software Info:
------------------------------------------
  Compile Date/Time : Sep 12 2024 06:59:02
  Compile Host OS   : windows
  ESP-IDF Version   : v5.1.4-586-gb6b4727c58-dirty
  Arduino Version   : 3.0.4
------------------------------------------
Board Info:
------------------------------------------
  Arduino Board     : ESP32S2_DEV
  Arduino Variant   : esp32s2
  Arduino FQBN      : esp32:esp32:esp32s2:JTAGAdapter=default,CDCOnBoot=default,MSCOnBoot=default,DFUOnBoot=default,UploadMode=default,PSRAM=disabled,PartitionScheme=default,CPUFreq=240,FlashMode=qio,FlashFreq=80,FlashSize=4M,UploadSpeed=921600,DebugLevel=verbose,EraseFlash=none,ZigbeeMode=default
============ Before Setup End ============
[  1382][V][esp32-hal-uart.c:408] uartBegin(): UART0 baud(115200) Mode(800001c) rxPin(44) txPin(43)
[  1391][V][esp32-hal-uart.c:497] uartBegin(): UART0 not installed. Starting installation
[  1402][V][esp32-hal-uart.c:560] uartBegin(): UART0 initialization done.
[  1425][V][NetworkEvents.cpp:119] checkForEvent(): Network Event: 9 - WIFI_READY
[  1481][V][AP.cpp:106] _onApEvent(): AP Started
[  1486][V][NetworkEvents.cpp:119] checkForEvent(): Network Event: 19 - AP_START
[  1493][V][AP.cpp:88] _onApArduinoEvent(): Arduino AP Event: 19 - AP_START
=========== After Setup Start ============
INTERNAL Memory Info:
------------------------------------------
  Total Size        :   219864 B ( 214.7 KB)
  Free Bytes        :   148840 B ( 145.4 KB)
  Allocated Bytes   :    65532 B (  64.0 KB)
  Minimum Free Bytes:   148616 B ( 145.1 KB)
  Largest Free Block:   139252 B ( 136.0 KB)
------------------------------------------
GPIO Info:
------------------------------------------
  GPIO : BUS_TYPE[bus/unit][chan]
  --------------------------------------  
    43 : UART_TX[0]
    44 : UART_RX[0]
============ After Setup End =============
[ 33269][V][AP.cpp:123] _onApEvent(): AP Station Connected: MAC: 92:bf:84:18:48:10, AID: 1
[ 33278][V][NetworkEvents.cpp:119] checkForEvent(): Network Event: 21 - AP_STACONNECTED
[ 33286][V][AP.cpp:88] _onApArduinoEvent(): Arduino AP Event: 21 - AP_STACONNECTED
[ 33466][V][NetworkInterface.cpp:146] _onIpEvent(): ap Assigned IP: 192.168.4.2 to MAC: 92:BF:84:18:48:10
[ 33475][V][NetworkEvents.cpp:119] checkForEvent(): Network Event: 23 - AP_STAIPASSIGNED
[ 33483][V][AP.cpp:88] _onApArduinoEvent(): Arduino AP Event: 23 - AP_STAIPASSIGNED
[ 34583][V][WebServer.cpp:418] handleClient(): New client: client.localIP()=192.168.4.1
[ 34592][V][Parsing.cpp:122] _parseRequest(): method: GET url: / search: 
[ 34599][V][Parsing.cpp:256] _parseRequest(): headerName: Connection
[ 34605][V][Parsing.cpp:257] _parseRequest(): headerValue: close
[ 34611][V][Parsing.cpp:256] _parseRequest(): headerName: User-Agent
[ 34617][V][Parsing.cpp:257] _parseRequest(): headerValue: Dalvik/2.1.0 (Linux; U; Android 14; SM-S911U1 Build/UP1A.231005.007)
[ 34630][V][Parsing.cpp:256] _parseRequest(): headerName: Host
[ 34636][V][Parsing.cpp:257] _parseRequest(): headerValue: 192.168.4.1
[ 34643][V][Parsing.cpp:256] _parseRequest(): headerName: Accept-Encoding
[ 34650][V][Parsing.cpp:257] _parseRequest(): headerValue: gzip
[ 34655][V][Parsing.cpp:284] _parseArguments(): args: 
[ 34661][V][Parsing.cpp:267] _parseRequest(): Request: /
[ 34666][V][Parsing.cpp:268] _parseRequest():  Arguments: 
esptini commented 6 days ago

so i just tried the example in 3.x with an iphone, it does NOT load the portal.