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

Prepare Release 2024.11.20 #1413

Merged
merged 133 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
133 commits
Select commit Hold shift + click to select a range
d0b2b97
Update UpgradePartition.md
janrombold Oct 3, 2024
bcf4b70
Fix: cpplint errors
tbnobody Oct 15, 2024
e5cf12c
Update nrf24/RF24 from 1.4.9 to 1.4.10
tbnobody Oct 16, 2024
cf1693e
Upgrade ESPAsyncWebServer from 3.3.16 to 3.3.17
tbnobody Oct 16, 2024
aa9f36e
Rename config API to file API
tbnobody Oct 19, 2024
1690148
Refactor file handling API and add endpoint to delete files
tbnobody Oct 19, 2024
1e857b7
Feature: Refactor config management interface
tbnobody Oct 19, 2024
8257eb7
webapp: Use global AlertResponse interface
tbnobody Oct 19, 2024
e29b86e
Add API endpoint to retrieve custom languages and complete language pack
tbnobody Oct 16, 2024
c3d3d94
webapp: Allow upload of language packs
tbnobody Oct 18, 2024
d9a8461
Feature: Allow custom language pack for webapp
tbnobody Oct 18, 2024
05006e0
Feature: Added spanish language pack
tbnobody Oct 18, 2024
4a247f5
Feature: Added italian language pack
tbnobody Oct 18, 2024
68c87c9
Move lookup for translation path to separate method
tbnobody Oct 18, 2024
2e23c7e
Check if language pack metadata are valid
tbnobody Oct 21, 2024
521fce3
webapp: Added global reboot wait screen
tbnobody Oct 21, 2024
2a21e53
webapp: Rename interface to prevent lint errors
tbnobody Oct 21, 2024
b1edb13
add and use configuration write guard
schlimmchen Oct 17, 2024
17016b1
actions: use RELEASE_TOKEN to create a release
schlimmchen Oct 22, 2024
d36b30a
Fix: SBS Unipower battery discharge current handling
AndreasBoehm Oct 23, 2024
2e85b42
Feature: add SoC & voltage thresholds for battery current limit
ranma Sep 28, 2024
cfb5c3f
webapp: prettify battery settings UI
AndreasBoehm Oct 23, 2024
3c1d3f7
Feature: retrieve absorption and float voltage from Victron MPPTs (#1…
SW-Niko Oct 25, 2024
6113e07
webapp: Fix: WaitRetstartView showed basic auth dialog
tbnobody Oct 25, 2024
d259042
Rewrite display language handling to work with locale strings instead…
tbnobody Oct 25, 2024
70f3019
Feature: Implement language pack support for display texts
tbnobody Oct 25, 2024
8452a8d
Feature: Added spanish display translation
tbnobody Oct 25, 2024
8566b08
Feature: Added italian display translation
tbnobody Oct 25, 2024
b21e8f8
Added README.md to lang folder
tbnobody Oct 25, 2024
4594bcb
Feature: Added device info for HMS-700
tbnobody Oct 26, 2024
225cab6
Fix: Take DST into account when recalculating the sunrise sunset time
tbnobody Oct 27, 2024
993f321
Fix: skip BOM in JSON files (pin_mapping and config)
schlimmchen Oct 29, 2024
94123fe
webapp: right-align labels for inputs on non-sm viewports
schlimmchen Oct 25, 2024
c5f37a8
webapp: last table row shall have no bottom border
schlimmchen Oct 25, 2024
983b58f
webapp: remove table's bottom margin
schlimmchen Oct 25, 2024
4aa9080
webapp: add gap between inverter selectors
schlimmchen Oct 26, 2024
3edfdb7
webapp: avoid inline style in inverter channel info card
schlimmchen Oct 26, 2024
e15fdab
webapp: equalize style of cards with tables in live view
schlimmchen Oct 26, 2024
d8fa703
webapp: use reasonable name for radio stats accordion
schlimmchen Oct 25, 2024
28bbd27
webapp: align table headers with card headers
schlimmchen Oct 26, 2024
aef0efc
webapp: apply card-table class to info view cards
schlimmchen Oct 26, 2024
a582f9c
webapp: adjust look of tables in accordions to live view cards
schlimmchen Oct 26, 2024
0a5bd65
webapp: beautify radio statistics reset button
schlimmchen Oct 26, 2024
b6c0a85
webapp: fix inverter "add" and "save order" button positions
schlimmchen Oct 26, 2024
8c46521
webapp: do not use div with v-if but template elements
schlimmchen Oct 26, 2024
dc78a83
webapp: avoid spurious DOM elements, avoid v-show, use v-if
schlimmchen Oct 27, 2024
2d49093
webapp: optimize spacing on bottom of cards
schlimmchen Oct 26, 2024
8174fb1
webapp: MQTT: use v-if in favor of v-show
schlimmchen Oct 26, 2024
31c26b0
webapp: MQTT: no login with cert if TLS disabled
schlimmchen Oct 26, 2024
bad5260
webapp: avoid inline style for inverter channel info value
schlimmchen Oct 26, 2024
50db501
webapp: use value class to format live values
schlimmchen Oct 26, 2024
db55204
webapp: fixup battery total cards
schlimmchen Oct 26, 2024
89a433c
webapp: consistently use no colon in form labels
schlimmchen Oct 27, 2024
121b7cf
webapp: replace remaining "OpenDTU" texts with "OpenDTU-OnBattery"
schlimmchen Oct 26, 2024
c87ba97
webapp: optimize placement of device profile doc buttons
schlimmchen Oct 27, 2024
3c3d97f
webapp: show pin mapping categories as cards
schlimmchen Oct 27, 2024
72e0708
webapp: device manager: optimize cards for tab nav
schlimmchen Oct 27, 2024
2f0699d
webapp: properly space alert with hint for hostname
schlimmchen Oct 27, 2024
e6ee0d5
webapp: optimize look of firmware update cards
schlimmchen Oct 27, 2024
a425be5
webapp: inverter advanced tab needs space at the top
schlimmchen Oct 27, 2024
c0cfdf0
webapp: fix AC charger admin view
schlimmchen Oct 27, 2024
29cf2bc
webapp: optimize look of login page
schlimmchen Oct 27, 2024
77e889c
webapp: optimize spacing around power meter test buttons
schlimmchen Oct 28, 2024
4a5aea0
webapp: always scroll up when navigating to another view
schlimmchen Oct 28, 2024
1bd2237
webapp: optimize body bottom padding and length
schlimmchen Oct 28, 2024
a352821
restructure and improve README
schlimmchen Oct 29, 2024
33b7697
add "important differences" to README
schlimmchen Oct 29, 2024
7cd1984
Feature: support for JBD BMS using serial connection
MoleBre Aug 31, 2024
3b0c83f
webapp: generalize battery serial interface settings
schlimmchen Sep 13, 2024
ad0e9fa
webapp: add JDB BMS issue texts
schlimmchen Oct 30, 2024
c55ff7d
Feature: add HASS autodiscovery for JBD BMS
schlimmchen Oct 30, 2024
8019eaf
Feature: Validate JSON before uploading
tbnobody Nov 1, 2024
0fc1ffc
webapp: Update dependencies
tbnobody Nov 1, 2024
2878807
Upgrade ESPAsyncWebServer from 3.3.17 to 3.3.21
tbnobody Nov 1, 2024
6c903ab
Fix: Lint Error
tbnobody Nov 1, 2024
55c98ef
Fix: skip BOM in JSON files (pin_mapping and config)
tbnobody Nov 1, 2024
130d90c
Merge branch 'pr2328' into dev
tbnobody Nov 1, 2024
c750def
webapp: right-align labels for inputs on non-sm viewports
schlimmchen Oct 25, 2024
d06ea51
webapp: last table row shall have no bottom border
schlimmchen Oct 25, 2024
d3eabc3
webapp: remove table's bottom margin
schlimmchen Oct 25, 2024
376912d
webapp: add gap between inverter selectors
schlimmchen Oct 26, 2024
0aba159
webapp: avoid inline style in inverter channel info card
schlimmchen Oct 26, 2024
d324a5c
webapp: equalize style of cards with tables in live view
schlimmchen Oct 26, 2024
e6a994f
webapp: use reasonable name for radio stats accordion
schlimmchen Oct 25, 2024
ad73fd8
webapp: align table headers with card headers
schlimmchen Oct 26, 2024
68d2f7b
webapp: apply card-table class to info view cards
schlimmchen Oct 26, 2024
3c188f2
webapp: adjust look of tables in accordions to live view cards
schlimmchen Oct 26, 2024
0832d3e
webapp: beautify radio statistics reset button
schlimmchen Oct 26, 2024
ba304b2
webapp: fix inverter "add" and "save order" button positions
schlimmchen Oct 26, 2024
eecd7f7
webapp: optimize spacing on bottom of cards
schlimmchen Oct 26, 2024
9132a88
webapp: MQTT: use v-if in favor of v-show
schlimmchen Oct 26, 2024
866b539
webapp: MQTT: no login with cert if TLS disabled
schlimmchen Oct 26, 2024
94cecc2
webapp: avoid inline style for inverter channel info value
schlimmchen Oct 26, 2024
54b4a2e
webapp: properly space alert with hint for hostname
schlimmchen Oct 27, 2024
e724fb8
webapp: optimize look of firmware update cards
schlimmchen Oct 27, 2024
f85297d
webapp: inverter advanced tab needs space at the top
schlimmchen Oct 27, 2024
08f4d62
webapp: optimize look of login page
schlimmchen Oct 27, 2024
9f31520
webapp: optimize body bottom padding and length
schlimmchen Oct 28, 2024
bac7179
webapp: consistently use no colon in form labels
schlimmchen Oct 27, 2024
f1c095e
webapp: optimize placement of device profile doc buttons
schlimmchen Oct 27, 2024
71f312d
webapp: show pin mapping categories as cards
schlimmchen Oct 27, 2024
3fa864c
webapp: device manager: optimize cards for tab nav
schlimmchen Oct 27, 2024
661ea6c
webapp: always scroll up when navigating to another view
schlimmchen Oct 28, 2024
41fd52d
Fix: protect api/powerlimiter/status endpoint
schlimmchen Nov 2, 2024
fcf21ac
keep console.log() when serving webapp
schlimmchen Nov 3, 2024
f9b84a0
Feature: add VE.Direct "load current" to live view, MQTT, and HASS (#…
SW-Niko Nov 3, 2024
8a2192e
webapp: fix inverter selection button breaking
schlimmchen Nov 3, 2024
3c56ec3
webapp: fix inverter selection button breaking
schlimmchen Nov 3, 2024
3948adf
keep console.log() when serving webapp
schlimmchen Nov 3, 2024
ab60875
Remove not required include
tbnobody Nov 6, 2024
53b496f
Replace multiline print by printf
tbnobody Nov 6, 2024
ca060e4
Remove not required include
tbnobody Nov 6, 2024
74e3947
Merge branch 'pr2360' into dev
tbnobody Nov 6, 2024
827a272
webapp: declare emitted event in FormFooter component
schlimmchen Nov 6, 2024
d088021
webapp: declare emitted event in FormFooter component
schlimmchen Nov 6, 2024
69c67f9
webapp: Update dependencies
tbnobody Nov 7, 2024
63405a7
Upgrade ESPAsyncWebServer from 3.3.21 to 3.3.22
tbnobody Nov 7, 2024
9a53d6e
Fix lint errors
tbnobody Nov 7, 2024
ecb5e9c
Build factory.bin in every compile attempt
tbnobody Nov 7, 2024
3dc70ab
webapp: add app.js.gz
tbnobody Nov 7, 2024
4f6f0fd
Merge upstream tag 'v24.11.7' into development
schlimmchen Nov 11, 2024
d9177da
support localization for grid usage in display
schlimmchen Nov 11, 2024
386e6b8
use config write guard
schlimmchen Nov 11, 2024
d5d66ec
replace C-style casts with C++ static_casts
schlimmchen Nov 12, 2024
7e19f19
webapp: fix line break for reload button
schlimmchen Nov 11, 2024
4524c04
Feature: DPL: add support for multiple inverters
schlimmchen Sep 22, 2024
cf4a59c
Feature: DPL: support overscaling on all inverters (#1286)
vaterlangen Oct 22, 2024
cbffafa
DPL: multiple inverters: add proper support for solar-powered inverte…
AndreasBoehm Oct 23, 2024
a8f57d9
DPL: clean up automatic inverter restart
schlimmchen Nov 15, 2024
61aa32a
webapp: DPL: order inverters as configured
schlimmchen Nov 18, 2024
1d5816d
readme: add section "Getting Started"
schlimmchen Nov 20, 2024
4beea35
Feature: add VE.Direct "RELAY" to live view, MQTT, and HASS
SW-Niko Nov 7, 2024
bfa55a8
Feature: process VE.Direct "FWE" text data
schlimmchen Nov 20, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -189,4 +189,4 @@ jobs:
files: |
artifacts/*.zip, artifacts/*.bin
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_TOKEN: ${{ secrets.RELEASE_TOKEN }}
2 changes: 1 addition & 1 deletion .github/workflows/cpplint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install cpplint==1.6.1
pip install cpplint
- name: Linting
run: |
cpplint --repository=. --recursive \
Expand Down
90 changes: 56 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,30 +1,49 @@
[![OpenDTU-OnBattery Build](https://github.com/hoylabs/OpenDTU-OnBattery/actions/workflows/build.yml/badge.svg)](https://github.com/hoylabs/OpenDTU-OnBattery/actions/workflows/build.yml)
[![cpplint](https://github.com/hoylabs/OpenDTU-OnBattery/actions/workflows/cpplint.yml/badge.svg)](https://github.com/hoylabs/OpenDTU-OnBattery/actions/workflows/cpplint.yml)
[![Yarn Linting](https://github.com/hoylabs/OpenDTU-OnBattery/actions/workflows/yarnlint.yml/badge.svg)](https://github.com/hoylabs/OpenDTU-OnBattery/actions/workflows/yarnlint.yml)
<!---
disabled while "create release badge" action is broken, see .github/build.yml
![GitHub tag (latest SemVer)](https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/helgeerbe/68b47cc8c8994d04ab3a4fa9d8aee5e6/raw/openDTUcoreRelease.json)
--->

- [OpenDTU-OnBattery](#opendtu-onbattery)
- [What is OpenDTU-OnBattery](#what-is-opendtu-onbattery)
- [Getting Started](#getting-started)
- [Important Differences](#important-differences)
- [Documentation](#documentation)
- [State of the project](#state-of-the-project)
- [History of the project](#history-of-the-project)
- [Project State](#project-state)
- [Project History](#project-history)
- [Acknowledgments](#acknowledgments)

# OpenDTU-OnBattery

This is a fork of [OpenDTU](https://github.com/tbnobody/OpenDTU).
OpenDTU-OnBattery is a fork of [OpenDTU](https://github.com/tbnobody/OpenDTU),
which adds support for battery chargers, battery management systems (BMS), and
power meters on a single ESP32. Its Dynamic Power Limiter can adjust the
inverter's power production to the actual houshold consumption. In this way, it
is possible to implement a zero export policy.

<!---
disabled while "create release badge" action is broken, see .github/build.yml
![GitHub tag (latest SemVer)](https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/helgeerbe/68b47cc8c8994d04ab3a4fa9d8aee5e6/raw/openDTUcoreRelease.json)
--->
## Getting Started

[![OpenDTU-OnBattery Build](https://github.com/hoylabs/OpenDTU-OnBattery/actions/workflows/build.yml/badge.svg)](https://github.com/hoylabs/OpenDTU-OnBattery/actions/workflows/build.yml)
[![cpplint](https://github.com/hoylabs/OpenDTU-OnBattery/actions/workflows/cpplint.yml/badge.svg)](https://github.com/hoylabs/OpenDTU-OnBattery/actions/workflows/cpplint.yml)
[![Yarn Linting](https://github.com/hoylabs/OpenDTU-OnBattery/actions/workflows/yarnlint.yml/badge.svg)](https://github.com/hoylabs/OpenDTU-OnBattery/actions/workflows/yarnlint.yml)
See the documentation to learn [what hardware](https://opendtu-onbattery.net/hardware/)
to acquire, how to [initialize](https://opendtu-onbattery.net/firmware/) it
with OpenDTU-OnBattery firmware, and how to
[configure](https://opendtu-onbattery.net/firmware/device_profiles/)
OpenDTU-OnBattery for your hardware.

## Important Differences

## What is OpenDTU-OnBattery
Generally speaking, OpenDTU-OnBattery and the upstream project are compatible
with each other, because OpenDTU-OnBattery mostly only extends the upstream
project. However, there are a few notable differences aside from the added functionality:

OpenDTU-OnBattery is an extension of the original OpenDTU to support battery
chargers, battery management systems (BMS) and power meters on a single ESP32.
With the help of a Dynamic Power Limiter, the power production can be adjusted
to the actual consumption. In this way, it is possible to implement a zero
export policy.
* OpenDTU-OnBattery, due to its code footprint, cannot offer support for
over-the-air (OTA) updates on ESP32 with only 4MB of flash memory. Consult
the [documentation](https://opendtu-onbattery.net/firmware/howto/upgrade_8mb/#background)
to learn more.
* Unlike in the upstream project, you **must** compile the web application
yourself when attempting to build your own firmware blob. See the
[documentation](https://opendtu-onbattery.net/firmware/compile_webapp/) for
details.

## Documentation

Expand All @@ -35,37 +54,40 @@ You may find additional helpful information in the project's
community-maintained [Github
Wiki](https://github.com/hoylabs/OpenDTU-OnBattery/wiki).

To find out what's new or improved have a look at the changelog of the
To find out what's new or improved have a look at the
[releases](https://github.com/hoylabs/OpenDTU-OnBattery/releases).

## State of the project
## Project State

OpenDTU-OnBattery is actively maintained. Please note that OpenDTU-OnBattery
may change significantly during its development. Bug reports, comments, feature
requests and pull requests are welcome!

## History of the project
## Project History

The original OpenDTU project was started from [a discussion on
Mikrocontroller.net](https://www.mikrocontroller.net/topic/525778). It was the
goal to replace the original Hoymiles DTU (Telemetry Gateway) to avoid using
Hoymile's cloud. With a lot of reverse engineering the Hoymiles protocol was
decrypted and analyzed.
Mikrocontroller.net](https://www.mikrocontroller.net/topic/525778). The
original ambition was to replace the original Hoymiles DTU (Telemetry Gateway)
to avoid using Hoymile's cloud. With a lot of reverse engineering, the Hoymiles
protocol was decrypted and analyzed.

In the summer of 2022 @helgeerbe bought a Victron MPPT charge cntroller, and
didn't like the idea to set up a separate ESP32 to receive the charger's data.
He decided to fork OpenDTU and extend it with battery charger support and a
Dynamic Power Limiter.
In the summer of 2022 [@helgeerbe](https://github.com/helgeerbe) bought a
Victron MPPT charge controller, and didn't like the idea to set up a separate
ESP32 to receive the charger's data. He decided to fork OpenDTU and extend it
with battery charger support and a Dynamic Power Limiter.

In early October 2024, the project moved to the newly founded GitHub
organisation `hoylabs` and is since maintained by multiple community members.

## Acknowledgments

* Special thanks to Thomas Basler (@tbnobody), the author of the [upstream
project](https://github.com/tbnobody/OpenDTU), for hist continued effort!
* Thanks to @helgeerbe for starting OpenDTU-OnBattery and his dedication to the
project, as well as his trust in the current maintainers of the project,
which act as part of the `hoylabs` GitHub organisation.
* Special thanks to Thomas Basler ([@tbnobody](https://github.com/tbnobody)),
the author of the [upstream project](https://github.com/tbnobody/OpenDTU),
for his continued effort!
* Thanks to [@helgeerbe](https://github.com/helgeerbe) for starting
OpenDTU-OnBattery, for his dedication to the project, as well as for his
trust in the current maintainers of the project, which act as part of the
`hoylabs` GitHub organisation.
* We like to thank all contributors. With your ideas and enhancements, you have
made OpenDTU-OnBattery much more than @helgeerbe originally had in mind.
made OpenDTU-OnBattery much more than
[@helgeerbe](https://github.com/helgeerbe) originally had in mind.
31 changes: 30 additions & 1 deletion include/BatteryStats.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "AsyncJson.h"
#include "Arduino.h"
#include "JkBmsDataPoints.h"
#include "JbdBmsDataPoints.h"
#include "VeDirectShuntController.h"
#include <cfloat>

Expand Down Expand Up @@ -159,7 +160,6 @@ class SBSBatteryStats : public BatteryStats {

float _chargeVoltage;
float _chargeCurrentLimitation;
float _dischargeCurrentLimitation;
uint16_t _stateOfHealth;
float _current;
float _temperature;
Expand Down Expand Up @@ -284,6 +284,35 @@ class JkBmsBatteryStats : public BatteryStats {
uint32_t _cellVoltageTimestamp = 0;
};

class JbdBmsBatteryStats : public BatteryStats {
public:
void getLiveViewData(JsonVariant& root) const final {
getJsonData(root, false);
}

void getInfoViewData(JsonVariant& root) const {
getJsonData(root, true);
}

void mqttPublish() const final;

uint32_t getMqttFullPublishIntervalMs() const final { return 60 * 1000; }

void updateFrom(JbdBms::DataPointContainer const& dp);

private:
void getJsonData(JsonVariant& root, bool verbose) const;

JbdBms::DataPointContainer _dataPoints;
mutable uint32_t _lastMqttPublish = 0;
mutable uint32_t _lastFullMqttPublish = 0;

uint16_t _cellMinMilliVolt = 0;
uint16_t _cellAvgMilliVolt = 0;
uint16_t _cellMaxMilliVolt = 0;
uint32_t _cellVoltageTimestamp = 0;
};

class VictronSmartShuntStats : public BatteryStats {
public:
void getLiveViewData(JsonVariant& root) const final;
Expand Down
99 changes: 67 additions & 32 deletions include/Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@
#include "PinMapping.h"
#include <cstdint>
#include <ArduinoJson.h>
#include <TaskSchedulerDeclarations.h>
#include <mutex>
#include <condition_variable>

#define CONFIG_FILENAME "/config.json"
#define CONFIG_VERSION 0x00011c00 // 0.1.28 // make sure to clean all after change
#define CONFIG_VERSION 0x00011d00 // 0.1.29 // make sure to clean all after change

#define WIFI_MAX_SSID_STRLEN 32
#define WIFI_MAX_PASSWORD_STRLEN 64
Expand All @@ -33,6 +36,7 @@
#define CHAN_MAX_NAME_STRLEN 31

#define DEV_MAX_MAPPING_NAME_STRLEN 63
#define LOCALE_STRLEN 2

#define HTTP_REQUEST_MAX_URL_STRLEN 1024
#define HTTP_REQUEST_MAX_USERNAME_STRLEN 64
Expand Down Expand Up @@ -128,6 +132,43 @@ struct POWERMETER_HTTP_SML_CONFIG_T {
};
using PowerMeterHttpSmlConfig = struct POWERMETER_HTTP_SML_CONFIG_T;

struct POWERLIMITER_INVERTER_CONFIG_T {
uint64_t Serial;
bool IsGoverned;
bool IsBehindPowerMeter;
bool IsSolarPowered;
bool UseOverscalingToCompensateShading;
uint16_t LowerPowerLimit;
uint16_t UpperPowerLimit;
};
using PowerLimiterInverterConfig = struct POWERLIMITER_INVERTER_CONFIG_T;

struct POWERLIMITER_CONFIG_T {
bool Enabled;
bool VerboseLogging;
bool SolarPassThroughEnabled;
uint8_t SolarPassThroughLosses;
bool BatteryAlwaysUseAtNight;
int16_t TargetPowerConsumption;
uint16_t TargetPowerConsumptionHysteresis;
uint16_t BaseLoadLimit;
bool IgnoreSoc;
uint16_t BatterySocStartThreshold;
uint16_t BatterySocStopThreshold;
float VoltageStartThreshold;
float VoltageStopThreshold;
float VoltageLoadCorrectionFactor;
uint16_t FullSolarPassThroughSoc;
float FullSolarPassThroughStartVoltage;
float FullSolarPassThroughStopVoltage;
uint64_t InverterSerialForDcVoltage;
uint8_t InverterChannelIdForDcVoltage;
int8_t RestartHour;
uint16_t TotalUpperPowerLimit;
PowerLimiterInverterConfig Inverters[INV_MAX_COUNT];
};
using PowerLimiterConfig = struct POWERLIMITER_CONFIG_T;

enum BatteryVoltageUnit { Volts = 0, DeciVolts = 1, CentiVolts = 2, MilliVolts = 3 };

enum BatteryAmperageUnit { Amps = 0, MilliAmps = 1 };
Expand All @@ -145,6 +186,8 @@ struct BATTERY_CONFIG_T {
BatteryVoltageUnit MqttVoltageUnit;
bool EnableDischargeCurrentLimit;
float DischargeCurrentLimit;
float DischargeCurrentLimitBelowSoc;
float DischargeCurrentLimitBelowVoltage;
bool UseBatteryReportedDischargeCurrentLimit;
char MqttDischargeCurrentTopic[MQTT_MAX_TOPIC_STRLEN + 1];
char MqttDischargeCurrentJsonPath[BATTERY_JSON_MAX_PATH_STRLEN + 1];
Expand Down Expand Up @@ -251,7 +294,7 @@ struct CONFIG_T {
bool ScreenSaver;
uint8_t Rotation;
uint8_t Contrast;
uint8_t Language;
char Locale[LOCALE_STRLEN + 1];
struct {
uint32_t Duration;
uint8_t Mode;
Expand All @@ -278,34 +321,7 @@ struct CONFIG_T {
PowerMeterHttpSmlConfig HttpSml;
} PowerMeter;

struct {
bool Enabled;
bool VerboseLogging;
bool SolarPassThroughEnabled;
uint8_t SolarPassThroughLosses;
bool BatteryAlwaysUseAtNight;
uint32_t Interval;
bool IsInverterBehindPowerMeter;
bool IsInverterSolarPowered;
bool UseOverscalingToCompensateShading;
uint64_t InverterId;
uint8_t InverterChannelId;
int32_t TargetPowerConsumption;
int32_t TargetPowerConsumptionHysteresis;
int32_t LowerPowerLimit;
int32_t BaseLoadLimit;
int32_t UpperPowerLimit;
bool IgnoreSoc;
uint32_t BatterySocStartThreshold;
uint32_t BatterySocStopThreshold;
float VoltageStartThreshold;
float VoltageStopThreshold;
float VoltageLoadCorrectionFactor;
int8_t RestartHour;
uint32_t FullSolarPassThroughSoc;
float FullSolarPassThroughStartVoltage;
float FullSolarPassThroughStopVoltage;
} PowerLimiter;
PowerLimiterConfig PowerLimiter;

BatteryConfig Battery;

Expand All @@ -331,11 +347,23 @@ struct CONFIG_T {

class ConfigurationClass {
public:
void init();
void init(Scheduler& scheduler);
bool read();
bool write();
void migrate();
CONFIG_T& get();
CONFIG_T const& get();

class WriteGuard {
public:
WriteGuard();
CONFIG_T& getConfig();
~WriteGuard();

private:
std::unique_lock<std::mutex> _lock;
};

WriteGuard getWriteGuard();

INVERTER_CONFIG_T* getFreeInverterSlot();
INVERTER_CONFIG_T* getInverterConfig(const uint64_t serial);
Expand All @@ -347,13 +375,20 @@ class ConfigurationClass {
static void serializePowerMeterHttpJsonConfig(PowerMeterHttpJsonConfig const& source, JsonObject& target);
static void serializePowerMeterHttpSmlConfig(PowerMeterHttpSmlConfig const& source, JsonObject& target);
static void serializeBatteryConfig(BatteryConfig const& source, JsonObject& target);
static void serializePowerLimiterConfig(PowerLimiterConfig const& source, JsonObject& target);

static void deserializeHttpRequestConfig(JsonObject const& source, HttpRequestConfig& target);
static void deserializePowerMeterMqttConfig(JsonObject const& source, PowerMeterMqttConfig& target);
static void deserializePowerMeterSerialSdmConfig(JsonObject const& source, PowerMeterSerialSdmConfig& target);
static void deserializePowerMeterHttpJsonConfig(JsonObject const& source, PowerMeterHttpJsonConfig& target);
static void deserializePowerMeterHttpSmlConfig(JsonObject const& source, PowerMeterHttpSmlConfig& target);
static void deserializeBatteryConfig(JsonObject const& source, BatteryConfig& target);
static void deserializePowerLimiterConfig(JsonObject const& source, PowerLimiterConfig& target);

private:
void loop();

Task _loopTask;
};

extern ConfigurationClass Configuration;
Loading