Open TinajaLabs opened 5 years ago
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
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.
It really all depends on flow, I would personally only start cp on demand or if creds empty
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; }
Avoid doing work inside a IF or callback, only set a flag etc.
That is why the shouldSaveConfig flag is used
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?
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:
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?
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/tzapu/WiFiManager/issues/801#issuecomment-694932461, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABXAAH7MSZIFAORK34DIEADSGN3URANCNFSM4GOSQLSQ .
sorry I misunderstood, I thought you mean "interrupt funciton" not if statement
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.