Software for ESP32 to talk to Hoymiles/TSUN/Solenso Inverters
Go to file
Bernhard Kirchen d23b991f5c
VE.Direct: Fix design issues and prepare support for multiple instances (#505)
* introduce VictronMpptClass

this solves a design issue where the loop() method of a static instance
of VeDirectMpptController, which is part of library code, is called as
part of the main loop() implementation. that is a problem because the
call to this loop() must be handled differently from all other calls:
the lib does not know whether or not the feature is enabled at all.
also, the instance would not be initialized when enabling the feature
during normal operation. that would even lead to a nullptr exception
since the pointer to the serial implementation is still uninitialized.

this new intermediate class is implemented with the support for multiple
Victron charge controllers in mind. adding support for more charge
controllers should be more viable than ever.

fixes #481.

related to #397 #129.

* VE.Direct: move get.*AsString methods to respective structs

those structs, which hold the data to be translated into strings, know
best how to translate them. this change also simplifies access to those
translation, as no parameter must be handed to the respective methods:
they now act upon the data of the instance they are called for. adds
constness to those methods.

* VE.Direct: simplify and clean up get.*AsString methods

use a map, which is much easier to maintain and which reads much easier.
move the strings to flash memory to save RAM.

* DPL: use VictronMpptClass::getPowerOutputWatts method

remove redundant calculation of output power from DPL. consider
separation of concern: VictronMpptClass will provide the total solar
output power. the DPL shall not concern itself about how that value is
calculated and it certainly should be unaware about how many MPPT charge
controllers there actually are.

* VE.Direct: avoid shadowing struct member "P"

P was part of the base struct for both MPPT and SmartShunt controller.
however, P was also part of the SmartShunt controller data struct,
shadowing the member in the base struct.

since P has slightly different meaning in MPPT versus SmartShunt, and
since P is calculated for MPPT controllers but read from SmartShunts, P
now lives in both derived structs, but not in the base struct.

* VE.Direct: isDataValid(): avoid copying data structs

pass a const reference to the base class implementation of isDataValid()
rather than a copy of the whole struct.

* VE.Direct: unify logging of text events

* VE.Direct: stop processing text event if handled by base

in case the base class processed a text event, do not try to match it
against values that are only valid in the derived class -- none will
match.

* VE.Direct MPPT: manage data in a shared_ptr

instead of handing out a reference to a struct which is part of a class
instance that may disappear, e.g., on a config change, we now manage the
lifetime of said data structure using a shared_ptr and hand out copies
of that shared_ptr. this makes sure that users have a valid copy of the
data as long as they hold the shared_ptr.

* VE.Direct MPPT: implement getDataAgeMillis()

this works even if millis() wraps around.

* VE.Direct: process frame end event only for valid frames

save a parameters, save a level of indention, save a function call for
invalid frames.
2023-10-19 16:15:29 +02:00
.github remove manual builds from action 2023-09-22 18:05:49 +02:00
.vscode Apply correct order to extension.json items 2023-04-17 21:49:17 +02:00
docs Merge remote-tracking branch 'tbnobody/OpenDTU/master' into development 2023-08-29 09:24:25 +02:00
include VE.Direct: Fix design issues and prepare support for multiple instances (#505) 2023-10-19 16:15:29 +02:00
lib VE.Direct: Fix design issues and prepare support for multiple instances (#505) 2023-10-19 16:15:29 +02:00
patches/esp32c3 Added functionality to apply custom patch files during building 2023-04-20 23:13:18 +02:00
pio-scripts dummy commit to check system info 2023-08-10 16:40:17 +02:00
src VE.Direct: Fix design issues and prepare support for multiple instances (#505) 2023-10-19 16:15:29 +02:00
test Initial commit 2022-04-09 11:05:14 +02:00
webapp Merge remote-tracking branch 'tbnobody/OpenDTU/master' into development 2023-10-10 09:26:43 +02:00
webapp_dist Merge remote-tracking branch 'tbnobody/OpenDTU/master' into development 2023-10-10 09:26:43 +02:00
.DS_Store First version 2022-08-11 17:26:00 +02:00
.gitignore Add new log location to .gitignore 2023-05-19 18:21:07 +02:00
COPYING Updated license file to match right phrase 2022-07-15 19:35:08 +02:00
LICENSE Change License to GPLv2 as the RF24 lib uses GPL-2.0-only 2022-07-15 18:05:58 +02:00
partitions_custom.csv BREAKING CHANGE: Updated partition table: Make sure you have a configuration backup and completly reflash the device! 2023-03-15 20:39:32 +01:00
platformio_override.ini Merge branch 'pr/MalteSchm/144' into development 2023-03-27 22:16:53 +02:00
platformio.ini Merge remote-tracking branch 'tbnobody/OpenDTU/master' into development 2023-10-10 09:26:43 +02:00
README_onBattery.md Dynamic power control and more power control modes on the Huawei PSU 2023-07-01 12:37:55 +02:00
README.md Replace Readme with wiki home page 2023-07-24 13:02:12 +02:00

OpenDTU-onBattery

This is a fork from the Hoymiles project OpenDTU.

GitHub tag (latest SemVer)

OpenDTU-onBattery Build cpplint Yarn Linting

What is OpenDTU-onBattery

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 come as close as possible to the goal of zero feed-in.

History of the project

The original OpenDTU project was started from this discussion (Mikrocontroller.net). It was the goal to replace the original Hoymiles DTU (Telemetry Gateway) with their cloud access. With a lot of reverse engineering the Hoymiles protocol was decrypted and analyzed.

Summer 2022 I bought my Victron MPPT battery charger, and didn't like the idea to set up a separate esp32 to recieve the charger data. I decided to fork OpenDTU and extend it with battery charger support and a dynamic power limitter to my own needs. Hoping someone can make use of it.

Highlights of OpenDTU-onBattery

This project is still under development and adds following features:

Warning

In contrast to the original openDTU, with release 2023.05.23.post1 openDTU-onBattery supports only 5 inverters. Otherwise, there is not enough memory for the liveData view.

  • Support Victron's Ve.Direct protocol on the same chip (cable based serial interface!). Additional information about Ve.direct can be downloaded directly from Victron's website.
  • Dynamically sets the Hoymiles power limited according to the currently used energy in the household. Needs an HTTP JSON based power meter (e.g. Tasmota), an MQTT based power meter like Shelly 3EM or an SDM power meter.
  • Battery support: Read the voltage from Victron MPPT charge controller or from the Hoymiles DC inputs and starts/stops the power producing based on configurable voltage thresholds
  • Voltage correction that takes the voltage drop because of the current output load into account (not 100% reliable calculation)
  • Can read the current solar panel power from the Victron MPPT and adjust the limiter accordingly to not save energy in the battery (for increased system efficiency). Increases the battery lifespan and reduces energy loses.
  • Settings can be configured in the UI
  • Pylontech Battery support (via CAN bus interface). Use the SOC for starting/stopping the power output and provide the battery data via MQTT (autodiscovery for home assistant is currently not supported). Pin Mapping is supported (default RX PIN 27, TX PIN 26). Actual no live view support for Pylontech Battery.
  • Huawei R4850G2 power supply unit that can act as AC charger. Supports status shown on the web interface and options to set voltage and current limits on the web interface and via MQTT. Connection is done using CAN bus (needs to be separate from Pylontech CAN bus) via SN65HVD230 interface.

Documentation

Full documentation of OpenDTU-onBattery extensions can be found at the project's wiki.

For documentation of openDTU core functionality I refer to the original repo and its wiki.

Please note that openDTU-onBattery may change significantly during its development. Bug reports, comments, feature requests and fixes are most welcome!

To find out what's new or improved have a look at the changelog.

Acknowledgment

A special Thank to Thomas Basler (tbnobody) the author of the original OpenDTU project. You are doing a great job!

Last but not least, I would like to thank all the contributors. With your ideas and enhancements, you have made OpenDTU-onBattery much more than I originally had in mind.