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

Add some additional Features #33

Merged
merged 10 commits into from
Apr 27, 2022
Merged

Add some additional Features #33

merged 10 commits into from
Apr 27, 2022

Conversation

mretich
Copy link
Contributor

@mretich mretich commented Apr 25, 2022

I have added some additional features, I think are usefull.
This includes:

  • A back button on all screens except the Home.
  • Display of the current BMS serial number on the settings page
  • Setting your own AP name if in AP mode, helping people having more than one board with a chip
  • Display of the AP name on the Home page also helping people with more boards
  • Autoupdate of the variable home values (current, cells, Ah, ...)
    (Currently this is updated ever 1 second via the Browser calling the endpoint actively.
    I´m planning to make this adjustable via the settings page, but this will probably take a little bit)
    For this I intruduced the ArduinoJson.h file, making dynamic update way easier.
  • Make the WLAN power output adjustable (between 9 and 12), since on my XR the default of 9 is not enought to reach at least 1 Meters when using a Smartphone and sometimes preventing a successful OTA update...
  • Moved the version number to a variable instead of a static return in the HTTP request, making it more readable.. (IMHO)

I also have updated the version number while developing, so this should be reversed or overriden!!
I still suggest that you add some kind of minor versioning when makuing updates on your code, since this helps a LOT to find out if the chip needs an update or not.

@mretich mretich changed the title Add some additionals Features Add some additional Features Apr 25, 2022
Copy link
Owner

@lolwheel lolwheel left a comment

Choose a reason for hiding this comment

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

Overall looks great!

A couple of comments:

src/network.cpp Outdated
@@ -38,6 +41,35 @@ inline String uptimeString() {
return ret;
}

DynamicJsonDocument parseOwieStatusData() {
Copy link
Owner

Choose a reason for hiding this comment

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

Please name this function "generateOwieStatusJson()" or something like that as it doesn't do any parsing.

src/network.cpp Outdated
String(relay->getRegeneratedChargeMah()) + " mAh";
status["UPTIME"] = uptimeString();
status["CELL_VOLTAGE_TABLE"] = out;
return status;
Copy link
Owner

Choose a reason for hiding this comment

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

A suggestion: In the spirit of better encapsulation, perform the serialization to string in this function instead of the call site as the caller doesn't require the JSON object.

@mretich mretich requested a review from lolwheel April 26, 2022 20:08
src/network.cpp Outdated
// add aditional sanity checks, so that the power range is between 9 and
// 12 only!
if (wifiPower == nullptr || wifiPower->value().toInt() < 9 || wifiPower->value().toInt() > 12) {
request->send(400, "text/html", "Wifi Power range MUST be between 9 and 12.");
Copy link
Owner

Choose a reason for hiding this comment

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

According to https://arduino-esp8266.readthedocs.io/en/latest/esp8266wifi/generic-class.html#setoutputpower this can be anywhere from 0 and 20.5 with the docs suggesting that 17.5 is a good sweet spot. Maybe limit this from say 4 to 17?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My first intention on this was only to raise the value only little bit, and to not allow a value lower as your hard coded "default". But I would not go as low as 4, since the top shilding of the Batterybox may prevent the Signal from spreading on a value of 4. On a XR the "default" 9 from you was just a little to less...
Therefore I suggest to limit this from say min. 8 to 17 with a default of 9?

Copy link
Owner

Choose a reason for hiding this comment

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

Sure why not, sounds good.

Copy link
Owner

Choose a reason for hiding this comment

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

Thanks again for great work!

src/settings.cpp Outdated
@@ -70,5 +70,7 @@ void disableFlashPageRotation() { getEeprom().rotate(false); }

void nukeSettings() {
*Settings = DEFAULT_SETTINGS;
// set default value of the wifi power output
Settings->wifi_power = 9;
Copy link
Owner

Choose a reason for hiding this comment

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

One thing that came to my mind is that we need to sanity test this setting on load. When users install this new version and the old protocol buffer gets read, wifi_power will be initialized to 0. You have to handle that case and clamp the setting value to the same limits as the ones you have in the web form check

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since im very new to Device programming and relatively rusty on C++ can you give me some guidance, where I can / should check the loaded Settings value for sanity (and probably reset it to a sane value)?
The nukeSettings is only called if there are NO values in the eeprom or if somethig went wrong on decoding the eeprom value, right? So if old settings are loaded this won´t be called?
My intention would be putting the check and setting to a sane default value into the loadSettings() function, right before it returns after decoding into the Settings object. Right?

Copy link
Owner

Choose a reason for hiding this comment

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

Yeah for sure. Call the function sanitizeSettings() where you check wifi_power and clamp its values if necessary. Call it from both nukeSettings() instead of setting wifi_power directly and also from loadSettings() on line 43 in this file, right after "DPRINTF("Read and decoded settings, size = %d bytes.", len);"

@mretich mretich requested a review from lolwheel April 27, 2022 20:25
@lolwheel lolwheel merged commit 0d6b14d into lolwheel:main Apr 27, 2022
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.

2 participants