mirror of
https://github.com/tzapu/WiFiManager.git
synced 2026-04-28 01:25:49 +03:00
[GH-ISSUE #801] Example - my approach to including wifimanager into the code #672
Labels
No labels
📶 WiFi
🕸️ HTTP
Branch
DEV Help Wanted
Discussion
Documentation
ESP32
Example
Good First Issue
Hotfix
In Progress
Incomplete
Needs Feeback
Priority
QA
Question
Task
Upstream/Dependancy
bug
duplicate
enhancement
invalid
pull-request
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/WiFiManager#672
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @TinajaLabs on GitHub (Jan 8, 2019).
Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/801
Showing this here for feedback. I love wifimanager but I find it difficult to intersperse the various pieces of wifiManager code into my own code.
This is an example that I use for a tip-cup rain gauge. The wifiManager part allows a user to set the local wifi station as well as the mqtt server (node-red) and part of the mqtt topic for location info.
The main parts of wifimanager have been broken into the following methods which make it easier for me to set up for other sensors. I'm including features like
On Demand button,reset with long press down,SPIFFS.I would like to know if I'm covering all the bases properly or if there's a better way to do this. Not an expert with the Arduino C-like code:The thought here is that perhaps there could be some examples that show these pieces as methods rather than large chunks of code in the setup or loop methods.Also, as I mentioned, I also collect some location info in the wifiManager page which is to be used to create the appropriate mqtt topics when using the sensors in different locations. Typical topics might look like this:
The first part (farm/barn/fenceline) is collected by a wifiManager parameter and then constructed into the final topic string in a separate method, setRainTopics.
I would like to know if this is a reasonable approach or maybe a better way.Thanks for any tips,
Chris.
@tablatronix commented on GitHub (Jan 8, 2019):
I use the development branch DEV example as my template for sample code, I have also added some better examples of use cases.
code is a bit to read, and not syntax highlighted
@TinajaLabs commented on GitHub (Jan 8, 2019):
OK. Syntax highlighting added but I understand... it is a bit to read. ;)
The main point I was making was to come up with blocks of method code to call from setup() or loop(), with button interrupt, so as to minimize the detailed code into those methods.
I have existing hard wired sensor code into which I want to add wifiManager. Methods like runWifiManager, loadConfigFile, saveConfigFile make it easier for me to re-wire existing code.
Thanks,
Chris.
@tablatronix commented on GitHub (Jan 8, 2019):
It really all depends on flow, I would personally only start cp on demand or if creds empty
@Jeppedy commented on GitHub (Sep 17, 2020):
I love that you worked to clean this up. I may do something similar in my code.
I had a comment/suggestion/question...
If "ParamSave callback" is not called, should you pull back the values from the portal?
If the callback wasn't invoked, doesn't that mean the user did not intend the values to be stored?
I'm still working on some mods to this library, but that's one of the changes I'm proving out within my application.
Your sketch code I'm referring to is:
//JAH: Should these two lines be moved within the IF?
strcpy(mqtt_server, custom_mqtt_server.getValue());
strcpy(topic_loc, custom_topic_loc.getValue());
// ----------------------------- save the custom parameters to FS
if (shouldSaveConfig) {
saveConfigFile();
shouldSaveConfig = false;
}
@tablatronix commented on GitHub (Sep 18, 2020):
Avoid doing work inside a IF or callback, only set a flag etc.
That is why the shouldSaveConfig flag is used
@Jeppedy commented on GitHub (Sep 18, 2020):
I'm unclear. I'm not familiar with this approach of doing work you don't need to do to keep logic out of an IF block.
If the config is not to be "saved", do you want to pull back the values from the portal? (That may be the real question here)
If no, then this is logic that is only needed when a certain condition is true, use the IF block.
It takes up cycles, and potentially causes undesirable results later... Wouldn't it?
@ramanraja commented on GitHub (Sep 19, 2020):
I have made similar modification in my code as @Jeppedy has done, and so
far it seems to work.
if the flag shouldSaveConfig is not true, I just return from the function.
Please let me know if there is any logical or practical flaw in my
approach. That will help correct myself.
(I may not fully understand memory management and the overheads of strcpy
etc.)
Thanks,
Rajaraman
India
On Fri, Sep 18, 2020 at 8:54 PM Jeppedy notifications@github.com wrote:
@tablatronix commented on GitHub (Sep 19, 2020):
sorry I misunderstood, I thought you mean "interrupt funciton" not if statement