[GH-ISSUE #1223] On Client Connect Callback? #1042

Open
opened 2026-02-28 01:28:15 +03:00 by kerem · 9 comments
Owner

Originally created by @OldGreyCells on GitHub (Mar 6, 2021).
Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/1223

Basic Infos

I notice the WiFiManager knows when a client connects to the Access Point:

*WM: [2] <- Request redirected to captive portal

Would it be possible to have an onAPClientConnectCallback?

Hardware

WiFimanager Branch/Release: Development

Esp8266:

Hardware: D1 Mini

Description

Problem description

Settings in IDE

Module: Wemos D1

Additional libraries:

Originally created by @OldGreyCells on GitHub (Mar 6, 2021). Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/1223 ### Basic Infos I notice the WiFiManager knows when a client connects to the Access Point: ``` *WM: [2] <- Request redirected to captive portal ``` Would it be possible to have an ```onAPClientConnectCallback```? #### Hardware WiFimanager Branch/Release: Development Esp8266: Hardware: D1 Mini ### Description Problem description ### Settings in IDE Module: Wemos D1 Additional libraries:
Author
Owner

@tablatronix commented on GitHub (Mar 6, 2021):

possibly, you could also do loop check ( non blocking mode )

uint8_t WiFiManager::WiFi_softap_num_stations(){
  #ifdef ESP8266
    return wifi_softap_get_station_num();
  #elif defined(ESP32)
    return WiFi.softAPgetStationNum();
  #endif
}
<!-- gh-comment-id:792070471 --> @tablatronix commented on GitHub (Mar 6, 2021): possibly, you could also do loop check ( non blocking mode ) ``` uint8_t WiFiManager::WiFi_softap_num_stations(){ #ifdef ESP8266 return wifi_softap_get_station_num(); #elif defined(ESP32) return WiFi.softAPgetStationNum(); #endif } ```
Author
Owner

@tablatronix commented on GitHub (Mar 6, 2021):

Also look at wifievents

https://github.com/esp8266/Arduino/blob/master/libraries/ESP8266WiFi/examples/WiFiEvents/WiFiEvents.ino

<!-- gh-comment-id:792070651 --> @tablatronix commented on GitHub (Mar 6, 2021): Also look at wifievents https://github.com/esp8266/Arduino/blob/master/libraries/ESP8266WiFi/examples/WiFiEvents/WiFiEvents.ino
Author
Owner

@OldGreyCells commented on GitHub (Mar 6, 2021):

Thank you, I will have a look at those - I'm trying to get the trigger to change the end user prompt from "Please connect to this WiFi Access Point" to "Please use this URL if the captive portal hasn't popped up on you phone" (cos I've only seen the elusive portal automatically once!) so I'll have to see where those WiFi 'Station Connected' events pop up while in AP Mode. Will report back!

<!-- gh-comment-id:792078537 --> @OldGreyCells commented on GitHub (Mar 6, 2021): Thank you, I will have a look at those - I'm trying to get the trigger to change the end user prompt from "Please connect to this WiFi Access Point" to "Please use this URL if the captive portal hasn't popped up on you phone" (cos I've only seen the elusive portal automatically once!) so I'll have to see where those WiFi 'Station Connected' events pop up while in AP Mode. Will report back!
Author
Owner

@tablatronix commented on GitHub (Mar 6, 2021):

ahh, so you want to actually detect the captive portal.. hmm

let me think on it, a callback might be the best way

A typical captive portal failure reason ,is your device is failing to get or use the aps dns.

<!-- gh-comment-id:792097276 --> @tablatronix commented on GitHub (Mar 6, 2021): ahh, so you want to actually detect the captive portal.. hmm let me think on it, a callback might be the best way A typical captive portal failure reason ,is your device is failing to get or use the aps dns.
Author
Owner

@OldGreyCells commented on GitHub (Mar 6, 2021):

Thank you - it's all about the user experience with me! My first programming 'customer' broke everything, so I still think like he does.
I thought the lack of captive portal failure may be because it's a 'saved' network?

<!-- gh-comment-id:792114862 --> @OldGreyCells commented on GitHub (Mar 6, 2021): Thank you - it's all about the user experience with me! My first programming 'customer' broke *everything*, so I still think like he does. I thought the lack of captive portal failure may be because it's a 'saved' network?
Author
Owner

@tablatronix commented on GitHub (Mar 7, 2021):

Sometimes that is also a reason, mostly on IOS you MUST forget ap to get it to come back up typically.

But there is a issue on esp about android forcing google dns, and not redirecting to cp ever, also win10 and firewalls.
basically captive portals are not foolproof or 100% reliable as they are entirely non standard

Another issue with trying to detect this is that every single request hits the captive portal as a request, every background service, every polling update check, maybe we can detect requester by user agent...

<!-- gh-comment-id:792153064 --> @tablatronix commented on GitHub (Mar 7, 2021): Sometimes that is also a reason, mostly on IOS you MUST forget ap to get it to come back up typically. But there is a issue on esp about android forcing google dns, and not redirecting to cp ever, also win10 and firewalls. basically captive portals are not foolproof or 100% reliable as they are entirely non standard Another issue with trying to detect this is that every single request hits the captive portal as a request, every background service, every polling update check, maybe we can detect requester by user agent...
Author
Owner

@tablatronix commented on GitHub (Mar 7, 2021):

You know I have been trying to identify captive portals also for ota, as upload forms do not work. RIght now it just says goto ip on the page..

<!-- gh-comment-id:792166576 --> @tablatronix commented on GitHub (Mar 7, 2021): You know I have been trying to identify captive portals also for ota, as upload forms do not work. RIght now it just says goto ip on the page..
Author
Owner

@OldGreyCells commented on GitHub (Mar 7, 2021):

It would appear the callback I require is WiFi.onSoftAPModeStationConnected() - this is fired when a client connects to a bare (ie WiFiManager not installed, flash erased) ESP8266. It would seem an AP is created automatically by the core WiFi lib but if I go to 192.168.4.1 I get 'Connection Refused' rather than the expected 'Address unreachable' which implies something is running on the ESP...
The WiFi.onSoftAPModeStationConnected() event has two members:
.aid - appears to be the number of the the client (ie 1 for the first, 2 for the second).
.mac - I haven't yet matched to the client mac but is different for each one...
Still digging.
Update: the on my phone, the 'IP Address' shows as '192.168.4.2' (assigned by the ESP?) along with a string that matches the .mac value - IPV6?

<!-- gh-comment-id:792290798 --> @OldGreyCells commented on GitHub (Mar 7, 2021): It would appear the callback I require is ```WiFi.onSoftAPModeStationConnected()``` - this is fired when a client connects to a bare (ie ```WiFiManager``` not installed, flash erased) ESP8266. It would seem an AP is created automatically by the core WiFi lib but if I go to 192.168.4.1 I get 'Connection Refused' rather than the expected 'Address unreachable' which implies something is running on the ESP... The ```WiFi.onSoftAPModeStationConnected()``` event has two members: ```.aid``` - appears to be the number of the the client (ie 1 for the first, 2 for the second). ```.mac``` - I haven't yet matched to the client mac but is different for each one... Still digging. Update: the on my phone, the 'IP Address' shows as '192.168.4.2' (assigned by the ESP?) along with a string that matches the ```.mac``` value - IPV6?
Author
Owner

@OldGreyCells commented on GitHub (Mar 7, 2021):

let me think on it, a callback might be the best way

On the basis it looks like the WiFi.onSoftAPModeStationConnected() callback meets the requirement, feel free to close this without creating a callback (following the *nix 'do one thing well' principle').

<!-- gh-comment-id:792299126 --> @OldGreyCells commented on GitHub (Mar 7, 2021): > let me think on it, a callback might be the best way On the basis it looks like the ```WiFi.onSoftAPModeStationConnected()``` callback meets the requirement, feel free to close this without creating a callback (following the *nix 'do one thing well' principle').
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#1042
No description provided.