tzapu / WiFiManager

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

shared webserver instance #461

Open tablatronix opened 6 years ago

tablatronix commented 6 years ago

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.

ageurtse commented 6 years ago

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

tablatronix commented 6 years ago

Sure, when I figure out how

spilz87 commented 6 years ago

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 ?

tablatronix commented 6 years ago

dnsserver? dns server resolves domains

spilz87 commented 6 years ago

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

spilz87 commented 6 years ago

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

tablatronix commented 6 years ago

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.

spilz87 commented 6 years ago

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

tablatronix commented 6 years ago

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

spilz87 commented 6 years ago

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

tablatronix commented 6 years ago

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

spilz87 commented 6 years ago

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 ?

tablatronix commented 6 years ago

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

spilz87 commented 6 years ago

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

Ok i will look for this function :)

spilz87 commented 6 years ago

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

tablatronix commented 6 years ago

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

spilz87 commented 6 years ago

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

spilz87 commented 6 years ago

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

tablatronix commented 6 years ago

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

tablatronix commented 5 years ago

for now I am testing this out

testing added to DEV example

452