-
Notifications
You must be signed in to change notification settings - Fork 79
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow ability to turn off built-in webserver #86
Conversation
src/ConfigManager.cpp
Outdated
DebugPrintln(WiFi.localIP()); | ||
this->mode = basic; | ||
|
||
if (!this->disabledWIFI) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was the bulk of the change
Moving this to a WIP -- persistence of WIFI configs seems to not be a thing for some reason |
21d3b4a
to
ceb9322
Compare
OK, this was dumb, Dont do this
💥 there goes your flash memory ... With that, I finally added a way to update the settings from code versus the browser .. it may not be pretty, but it appears to work
I once again tried to turn the objects parameter store into a |
src/ConfigManager.cpp
Outdated
DebugPrintln(WiFi.localIP()); | ||
DebugPrintln(F("\"")); | ||
|
||
EEPROM.get(MAGIC_LENGTH + SSID_LENGTH, password); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
attempt to grab ssid/password after validate magic
src/ConfigManager.h
Outdated
JsonObject json = doc.createNestedObject(); | ||
json[name] = value; | ||
(*it)->fromJson(&json); | ||
break; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
slightly hacky (?) ... couldnt get the Type definition into BaseParameter for the different types, so went the good old way of changing it to JSON and using the already set up update methods!!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Disregard everything I wrote ... It appears I chased my tail, as there is some weird issue if you update a setting continually in the loop
I thought it was the way I was doing updates/saves ... Ill not squash this commit in the event you like this updateParameter
hook ... it does abstract away from of how to handle the different types .. maybe ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The one benefit to this method is that it does the type casting for you .. and you cant try to jam a random
as an int
... no bueno
template <typename T>
void updateParameter(const char* name, T value) {
std::list<BaseParameter*>::iterator it;
for (it = parameters.begin(); it != parameters.end(); ++it) {
if ((*it)->getName() == name) {
DynamicJsonDocument doc(1024);
JsonObject json = doc.createNestedObject();
json[name] = value;
(*it)->fromJson(&json);
break;
ceb9322
to
610c7ae
Compare
This appears to be some odd issue when updating a setting continually in |
This is resolved ... setting an
|
Hey. Wow, that is a change in deed. Some starting questions around the idea:
Arguably I can see how disabling the WiFi might be interesting for someone, but from a quick naive PoV I think I do however take your point that you want to use a different web server to what is built in. Perhaps another way to look at |
Happy Monday -- my coffee is brewing, so please bear with me ;)
I think the elegance is how you manage configuration in the SPIFFS is really the power of
I could easily be talked out of even including
This is an odd combination, but again, the power and beauty of ConfigManager in my perspective is the actual management of memory based persistence of configuration. There are a bunch of other projects that already have UI, but could benefit just from the ease of use of the configuration store. I could be wrong ... Someone would really need/want to understand why they turned both those off.
I think if Wifi is disabled, this is just like any of project, its an island. But I feel since both WIFI and HTTP disables are optional, you really need a reason to use them.
Intrigued and curious, but not following. I would argue that outside of |
So I never considered the idea of just using it for storing config, like it never even crossed my mind. So my first set of questions have been answered. I finally understand what you are aiming at.
So my point here is to allow any web server adapter that anyone can think of, as long as it implements the methods we want, by way of an interface. Where we are starting and binding to a webserver, we instead make use of an interface that exposes the webserver to ConfigManager. We would then have a class for ESP8266 and anther for ESP32. If someone else prefers to provide their own they can, and setting it to nil will not use the webserver at all. (This was my first thought, but understanding more about the use case, perhaps it is not what we need).
Well that is not great. Not sure what to do about it though. Must say, i have never tried this before. |
I will answer the rest in a separate thread, but if you take the saved_config demo and just add
On next reboot you have cleared the memory ... Im not exactly sure why, but I think its cause you are jamming too much in? or the offsets are wrong? I tried for a cleaner parameter update. I tried having
and in this case, those classes have strict typing of each member ... I just could not get the |
Thats where I thought you were going, my brain is slow on seeing how they are all tied together ... I think its something like:
I like this for AP mode, I think it gets convoluted (overkill) for API mode .. reason being, I see API mode being a more custom defined page and not just a settings editor. I could not be thinking completely through this. To an earlier point, if you are going to use ConfigManager for Wifi Handling, why fold in so many layers of the interface to expose a 2 field configuration? I'd just use AP mode, its credentialAPI and call it a cay, simple and efficient .. With that, maybe its better to just have the developer stop the onboard server when desired? .. of course I think of this now ... so the flow in our co-mingled use case would be:
In this world, they get the implicit ability to not use However .. that leads me to ask if your |
Perhaps you are right, the only benefit i see to having things split out and included via interface is compile size. If you dont use it, you dont pay the cost in the binary. Thinking along these lines, the natural split would be WifiManager, HTTPManager and ConfigManager which binds them all. All WiFi related code in WiFiManger, the 2 provided HTTPManagers and ConfigManager which by default has the "correct" instances. If you turn something off, the code is tree shaken out. Thoughts? |
I What are your thoughts on my over-simplified 'just stop the webserver when you dont need it' ... I could easily re-shuffle the PR for that, remove the It does 98% suck that the server that is embedded in ConfigManager has naming conflicts, I was able to work around that via a namespace, but Ive also seen that fail miserably trying to namespace libraries that other things aggressively assume are named one thing ... and for that I love the segmented module approach .. BUT for v1 of this I can quickly rework to stop the server, some code clean that is in this PR .. and see where it lands? As always, thank you for talking me off the cliff .. good stewardship of code protection with ConfigManger ;) |
Thanks, it is always great to have the discussion 😄 I think you are ultimately correct. While the reshuffle is perhaps a better direction, it is better in a major version. So lets do |
2a8b49d
to
89299a2
Compare
@nrwiersma updated per discussion, much thinner... compiles -- UNTESTED ... open for feedback |
@@ -73,9 +72,13 @@ class ConfigParameter : public BaseParameter { | |||
|
|||
ParameterMode getMode() { return this->mode; } | |||
|
|||
void update(T value) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like it 👍 It gives me an idea for the future to move JSON out of ConfigManager.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would be awesome, a pure update
hook of the data
89299a2
to
af5b218
Compare
The code is looking pretty good. Nice work 👍 |
WIP library wrangling whitespace no working CM http no working CM http almost all working .. WTF is up with the scan packer SCANNER return minJSON final touches quick clean flash memory working WTF add ability to update settings add ability to update settings disregard everything I said about updating start/stop webserver start/stop webserver start/stop webserver start/stop webserver start/stop webserver cleanup
af5b218
to
42112cd
Compare
@nrwiersma tested on ESP8266/32 everything works as expected. Shutting down of the HTTP is nicer than expected, and less code mucking .. good call ... Added to the README.md and some minor sweep up. Let me know if there are other areas of concern/change |
Thanks very much. Nice work 👍 |
@nrwiersma MUCH THANKS! |
Tested
Multi-configurations on both ESP8266 and ESP32
Disclaimer
I'd release this as an Release Candidate before promotion ;) .. I did get under the hood a bit
Objective
To provide optional settings to disable ConfigManagers built-in Wifi and HTTP server.
Reason
I want to use another package that has a conflicting server, and didn't necessarily want to have the device running multiple all the time.
End Result
To additional methods provided that will one-time-only (ie no toggling out of it, as it is usually done during
setup
) disable eitherWifi
orHTTP
, but allow either to also continue to work if they are not both turned off (ie, HTTP will still serve if WIFI has been disabled)Of course, this is Buyer Beware, as you can't really have a useful HTTP thing without WIFI, so you would need to have custom WIFI or HTTP methods of your own.
Abstracted out methods used by ConfigManagers HTTP
For the HTTP calls (ie
/scan
), I unrolled some the underlying code so they are more readily exposed to other processesExample Code
Example code provided which should easily let one test the code out, as well as try the different disabling configurations.