[GH-ISSUE #461] shared webserver instance #388

Open
opened 2026-02-28 01:25:04 +03:00 by kerem · 20 comments
Owner

Originally created by @tablatronix on GitHub (Nov 19, 2017).
Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/461

I am testing this already, but I am using a getter and a shared_ptr, not sure which way will be final.
Ill post my branch later, I was adding some callbacks and testing what kind of parameters and callouts we would want to plan for templating and sharing webserver control.

There are several options, make server public, add getter with shared_pointer, and a few others.
I am unsure which is the best design pattern for this, or how we want to control ownership.

Thoughts welcome.

Originally created by @tablatronix on GitHub (Nov 19, 2017). Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/461 I am testing this already, but I am using a getter and a shared_ptr, not sure which way will be final. Ill post my branch later, I was adding some callbacks and testing what kind of parameters and callouts we would want to plan for templating and sharing webserver control. There are several options, make server public, add getter with shared_pointer, and a few others. I am unsure which is the best design pattern for this, or how we want to control ownership. Thoughts welcome.
Author
Owner

@ageurtse commented on GitHub (Feb 20, 2018):

Is there a way you could provide an example on how to run a shared webserver.

<!-- gh-comment-id:367115426 --> @ageurtse commented on GitHub (Feb 20, 2018): Is there a way you could provide an example on how to run a shared webserver.
Author
Owner

@tablatronix commented on GitHub (Feb 20, 2018):

Sure, when I figure out how

<!-- gh-comment-id:367164216 --> @tablatronix commented on GitHub (Feb 20, 2018): Sure, when I figure out how
Author
Owner

@spilz87 commented on GitHub (Jul 18, 2018):

Ok, i see it's something everybody would like ^^
What about a way to link the dnsserver to a specific page of the web server, not the "/" , something like "/captivePortail", is it possible ?

<!-- gh-comment-id:406039484 --> @spilz87 commented on GitHub (Jul 18, 2018): Ok, i see it's something everybody would like ^^ What about a way to link the dnsserver to a specific page of the web server, not the "/" , something like "/captivePortail", is it possible ?
Author
Owner

@tablatronix commented on GitHub (Jul 18, 2018):

dnsserver? dns server resolves domains

<!-- gh-comment-id:406041072 --> @tablatronix commented on GitHub (Jul 18, 2018): dnsserver? dns server resolves domains
Author
Owner

@spilz87 commented on GitHub (Jul 18, 2018):

Hi I see
As you can see I'm not a specialist ^^
You understand the idea : captive portal point to a "/captiveportal" page not to the "/" default page

<!-- gh-comment-id:406052437 --> @spilz87 commented on GitHub (Jul 18, 2018): Hi I see As you can see I'm not a specialist ^^ You understand the idea : captive portal point to a "/captiveportal" page not to the "/" default page
Author
Owner

@spilz87 commented on GitHub (Jul 18, 2018):

An other idea could be to check if the client is connected to AP or from network , and link to different pages, if it is connected on AP the page as only few button which link to other specific pages, so the difference is only on the first page
Do you see what I mean ?
Maybe it's already what you do

<!-- gh-comment-id:406053431 --> @spilz87 commented on GitHub (Jul 18, 2018): An other idea could be to check if the client is connected to AP or from network , and link to different pages, if it is connected on AP the page as only few button which link to other specific pages, so the difference is only on the first page Do you see what I mean ? Maybe it's already what you do
Author
Owner

@tablatronix commented on GitHub (Jul 18, 2018):

Yeah the idea is to share the webserver instance so you can access in your own code, you can do this now by just making it public, but I have not decided if that is the final route. It might be better to makde it a shared pointer so that memory gets cleaned up better.

<!-- gh-comment-id:406054025 --> @tablatronix commented on GitHub (Jul 18, 2018): Yeah the idea is to share the webserver instance so you can access in your own code, you can do this now by just making it public, but I have not decided if that is the final route. It might be better to makde it a shared pointer so that memory gets cleaned up better.
Author
Owner

@spilz87 commented on GitHub (Jul 18, 2018):

A shared pointer allow you to keep the same webserver but the configuration of this webserver (.on(..) , etc.) is erase when captive portal is open, isn't it ?
Do I understand well or I'm wrong ?
Let me know if it's not the good place to have this discussion

<!-- gh-comment-id:406068180 --> @spilz87 commented on GitHub (Jul 18, 2018): A shared pointer allow you to keep the same webserver but the configuration of this webserver (.on(..) , etc.) is erase when captive portal is open, isn't it ? Do I understand well or I'm wrong ? Let me know if it's not the good place to have this discussion
Author
Owner

@tablatronix commented on GitHub (Jul 18, 2018):

I wouldn't think so, not sure what you mean. webportal is always on when configportal is on

<!-- gh-comment-id:406071655 --> @tablatronix commented on GitHub (Jul 18, 2018): I wouldn't think so, not sure what you mean. webportal is always on when configportal is on
Author
Owner

@spilz87 commented on GitHub (Jul 18, 2018):

Does the setupConfigPortal erase the setup of the server done in the setup() of the sketch ?

<!-- gh-comment-id:406076629 --> @spilz87 commented on GitHub (Jul 18, 2018): Does the setupConfigPortal erase the setup of the server done in the setup() of the sketch ?
Author
Owner

@tablatronix commented on GitHub (Jul 18, 2018):

Ah I see what you are saying, yes that resets the webserver. hmm you have to setup yours after that, wm would have to be setup to allow that to be skipped, it also gets torn down on closeconfigportal

Good point

  • if sharing web sever, allow setup and tear down
  • allow passing in webserver ref then we do nothing, except assign handlers
<!-- gh-comment-id:406077642 --> @tablatronix commented on GitHub (Jul 18, 2018): Ah I see what you are saying, yes that resets the webserver. hmm you have to setup yours after that, wm would have to be setup to allow that to be skipped, it also gets torn down on closeconfigportal Good point - [ ] if sharing web sever, allow setup and tear down - [ ] allow passing in webserver ref then we do nothing, except assign handlers
Author
Owner

@spilz87 commented on GitHub (Jul 18, 2018):

For my project, I'm not saying it's the best solution for everyone, pass a pointer of web server to WM and just assign handlers looks good.

Is there a way to know if the client is connected to AP or through network ?

<!-- gh-comment-id:406079936 --> @spilz87 commented on GitHub (Jul 18, 2018): For my project, I'm not saying it's the best solution for everyone, pass a pointer of web server to WM and just assign handlers looks good. Is there a way to know if the client is connected to AP or through network ?
Author
Owner

@tablatronix commented on GitHub (Jul 18, 2018):

Curious , Did you add a new constructor to pass the webserver in , or use a setter?

I guess you could check by client ip, or get the clients attached to ap and check them for that ip request.
There is a function in esp to get stas that are connected, I forget it

<!-- gh-comment-id:406081236 --> @tablatronix commented on GitHub (Jul 18, 2018): Curious , Did you add a new constructor to pass the webserver in , or use a setter? I guess you could check by client ip, or get the clients attached to ap and check them for that ip request. There is a function in esp to get stas that are connected, I forget it
Author
Owner

@spilz87 commented on GitHub (Jul 18, 2018):

Not in WM, it was a test in a personal library

Ok i will look for this function :)

<!-- gh-comment-id:406086458 --> @spilz87 commented on GitHub (Jul 18, 2018): Not in WM, it was a test in a personal library Ok i will look for this function :)
Author
Owner

@spilz87 commented on GitHub (Jul 18, 2018):

If you remember the name, let me know ^^
Thanks

<!-- gh-comment-id:406087670 --> @spilz87 commented on GitHub (Jul 18, 2018): If you remember the name, let me know ^^ Thanks
Author
Owner

@tablatronix commented on GitHub (Jul 18, 2018):

https://github.com/esp8266/Arduino/issues/2681

<!-- gh-comment-id:406106713 --> @tablatronix commented on GitHub (Jul 18, 2018): https://github.com/esp8266/Arduino/issues/2681
Author
Owner

@spilz87 commented on GitHub (Jul 19, 2018):

Ok thanks,
I just test it, it works well, as expected only for client connected to AP. So it's possible to compare IP to know if it connected to AP or through network, and send a different first web page

<!-- gh-comment-id:406168981 --> @spilz87 commented on GitHub (Jul 19, 2018): Ok thanks, I just test it, it works well, as expected only for client connected to AP. So it's possible to compare IP to know if it connected to AP or through network, and send a different first web page
Author
Owner

@spilz87 commented on GitHub (Jul 19, 2018):

I just test something, with my iPhone, I don't know if it's true with android and I didn't get captive portal on my computer, but the captive portal seems to request the "/hotspot-detect.html"
Is it a standard ?...

<!-- gh-comment-id:406238228 --> @spilz87 commented on GitHub (Jul 19, 2018): I just test something, with my iPhone, I don't know if it's true with android and I didn't get captive portal on my computer, but the captive portal seems to request the "/hotspot-detect.html" Is it a standard ?...
Author
Owner

@tablatronix commented on GitHub (Jul 19, 2018):

no there is no standard for captive portals, I always get captive portal on iphone and osx, if you have connected before you might have to "forget" the access point or else it auto joins and doesnt do captive portals. Also if you are on 2 networks sometimes it will not launch the captive portal, but my iphone almost always works. There is an open issue in esp lib about android captive portals not working with certain IPs

<!-- gh-comment-id:406258534 --> @tablatronix commented on GitHub (Jul 19, 2018): no there is no standard for captive portals, I always get captive portal on iphone and osx, if you have connected before you might have to "forget" the access point or else it auto joins and doesnt do captive portals. Also if you are on 2 networks sometimes it will not launch the captive portal, but my iphone almost always works. There is an open issue in esp lib about android captive portals not working with certain IPs
Author
Owner

@tablatronix commented on GitHub (Oct 12, 2018):

for now I am testing this out

  • moving server to public, keeping it unique pointer
  • adding setWebServerCallback that fires after webserver is setup and before route events are setup ( this allows user to override routes eg. /info )

testing added to DEV example

#452

<!-- gh-comment-id:429459662 --> @tablatronix commented on GitHub (Oct 12, 2018): for now I am testing this out * moving server to public, keeping it unique pointer * adding `setWebServerCallback` that fires after webserver is setup and before route events are setup ( this allows user to override routes eg. /info ) testing added to DEV example #452
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#388
No description provided.