Skip to content
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

SensESPAppOptions - allows configuration of SensESPApp application #142

Merged
merged 24 commits into from
Aug 16, 2020
Merged

SensESPAppOptions - allows configuration of SensESPApp application #142

merged 24 commits into from
Aug 16, 2020

Conversation

JohnySeven
Copy link
Contributor

This PR was highly discussed and tested with @mairas and @ba58smith. Thank you guys for your feedback and help!

This PR will allow SensESP lib user configure following features:

  • Wifi - preconfiguration of connection settings from main.cpp, or using Wireless manager
  • Networking - allows user to enable / disable mDNS, use static server configuration from main.cpp, allows to preconfigure device hostname
  • Allows configuring LED blink intervals and / or pin number to use

In future it will allow any developer of the library to configure more parameters of SensESP from main.cpp. This PR adds more flexibility to SensESP library and defines the way how behaviour for SensESP library is changed by end user.

This PR is backwards compatible with previous code, so no breaking changes are introduced for end user if the end user doesn't change or rely on internals SensESP structures.

- new classes SKListener, SKValueListener<T> and DigitalOutput
Changed period to ListenDelay where required.
Added new short-cut types: SKFloatListener, SKIntListener, SKBoolListener and SKStringListener
Added new class ThresholdTransform that allows to change one value type to other.
Added helper classes NumericThreshold and IntegerThreshold for simple ThresholdTransform setup.
ThresholdTransform - removed this->, debug messages, renamed json "in-range" to "in_range".
NumericThreshold - added json schema descriptions, added class comment
IntegerThreshold - added json schema descriptions, added class comment
Tested on my environmental sensor and it works.
Http_server - added more information to /info page (MAC, hostname, configuration, etc.)
Networking - now configuration scheme is readonly if wifi config is from main.cpp
ws_client - now configuration scheme is readonly if server address config is from main.cpp
WSClient - added readonly label if config is from main.cpp
WSClient - fixed issue with not loading configuration from flash when using main.cpp config -> token not loaded from flash
relay_control sample - updated sample to match options changes
Networking.cpp - removed reference to Options class all information is passed by ctor arguments
led_blinker.cpp - removed reference to Options class all information is passed by ctor arguments
SensApp fixed hostname issue when hostname was already in config json file, but it was overriden in main.cpp
Copy link
Collaborator

@ba58smith ba58smith left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a lot going on in this PR, so I want to test it all before I merge it. And I don't want to test it all before you might make any changes as a result of my comments. So, read all the comments, reply to them, and we'll go from there. (Please be sure to reply "inline" - right after each comment, and NOT at the end of the "Conversation") Thanks so much - this was LOT of work!

examples/relay_control.cpp Outdated Show resolved Hide resolved
src/net/http.cpp Outdated Show resolved Hide resolved
src/net/http.h Show resolved Hide resolved
src/net/ws_client.h Show resolved Hide resolved
src/net/ws_client.cpp Show resolved Hide resolved
src/net/ws_client.cpp Show resolved Hide resolved
src/sensesp_app_options.cpp Show resolved Hide resolved
sensesp_app_options.cpp - changed LED
ws_client.cpp - corrected debug messages
platformio.ini Outdated Show resolved Hide resolved
src/net/http.cpp Outdated Show resolved Hide resolved
src/net/networking.cpp Outdated Show resolved Hide resolved
src/sensesp_app_options.h Outdated Show resolved Hide resolved
Copy link
Collaborator

@mairas mairas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please see my individual comments.

Also, could you reformat the files to conform to the project formatting style (Google C++ Style)? The formatting style is defined in .clang-format and VS Code should pick it up automatically from there, so just applying the "Reformat Document" command for each of the changed files should be enough.

@mairas
Copy link
Collaborator

mairas commented Aug 7, 2020

One more design consideration: if you used the builder pattern as discussed on Slack, you could use the SensESPApp class to store and access the configuration options. There is a global pointer to the app object, so you wouldn't have to pass the options object around. Accessing the different options could be limited/enabled by defining HTTPServer a friend class of SensESPApp, if so desired.

@JohnySeven
Copy link
Contributor Author

@mairas that was my initial approach, but problem with this is the app global pointer is set by user in main.cpp and I can't be sure when the user will do it and I didn't want to change this as it would be breaking change. Another option is to create library wide global pointer to app object that will be set in SensESPApp ctor, then I'll be sure when it's set to current app.

@mairas
Copy link
Collaborator

mairas commented Aug 8, 2020

@mairas that was my initial approach, but problem with this is the app global pointer is set by user in main.cpp and I can't be sure when the user will do it and I didn't want to change this as it would be breaking change. Another option is to create library wide global pointer to app object that will be set in SensESPApp ctor, then I'll be sure when it's set to current app.

I don't think you need to use that global pointer during initialization. The only need I see for that is for the /info URL handler in http.cpp. That needs to access the current state of different objects, and for that the global sensesp_app pointer makes most sense. For initialization purposes, it's better to provide any required data as constructor arguments.

Removed upload speed from platformio.ini
SensESPAppOptions - made isWifiSet and IsServerSet based on String.isEmpty()
HttpServer - removed reference to SensESPAppOptions in ctor - using global pointer for options
Networking - changed "set from main.cpp" to "set from SensespAppOptions"
WSClient - removed reference to SensESPAppOptions in ctor
@JohnySeven
Copy link
Contributor Author

New commit addresses all requested changes, I've formatted all changed files as @mairas requested. Just let me know if you spot anything else prior merging the changes. Thanks!

@ba58smith
Copy link
Collaborator

Thoroughly tested with ESP8266. One issue found with configuring hostname in main.cpp, but not configuring ssid and password in main.cpp (or vice versa), but after disccusion with @JohnySeven, we decided to fix that in a new issue after this PR is merged.

Compiles with ESP32, but the known problem with mDNS is preventing further testing at the moment. Will go ahead and merge, then address that issue, then continue testing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants