diff --git a/README.md b/README.md
index 45677b55..5392e74d 100644
--- a/README.md
+++ b/README.md
@@ -1,23 +1,23 @@
-- [OpenDTU-onBattery](#opendtu-onbattery)
- - [What is OpenDTU-onBattery](#what-is-opendtu-onbattery)
+- [OpenDTU-OnBattery](#opendtu-onbattery)
+ - [What is OpenDTU-OnBattery](#what-is-opendtu-onbattery)
- [History of the project](#history-of-the-project)
- - [Highlights of OpenDTU-onBattery](#highlights-of-opendtu-onbattery)
+ - [Highlights of OpenDTU-OnBattery](#highlights-of-opendtu-onbattery)
- [Documentation](#documentation)
- [Acknowledgment](#acknowledgment)
-# OpenDTU-onBattery
+# OpenDTU-OnBattery
This is a fork from the Hoymiles project [OpenDTU](https://github.com/tbnobody/OpenDTU).

-[](https://github.com/helgeerbe/OpenDTU-OnBattery/actions/workflows/build.yml)
+[](https://github.com/helgeerbe/OpenDTU-OnBattery/actions/workflows/build.yml)
[](https://github.com/helgeerbe/OpenDTU-OnBattery/actions/workflows/cpplint.yml)
[](https://github.com/helgeerbe/OpenDTU-OnBattery/actions/workflows/yarnlint.yml)
-## What is OpenDTU-onBattery
+## 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.
+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
@@ -25,7 +25,7 @@ The original OpenDTU project was started from [this](https://www.mikrocontroller
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
+## Highlights of OpenDTU-OnBattery
This project is still under development and adds following features:
@@ -40,11 +40,11 @@ This project is still under development and adds following features:
## Documentation
-[Full documentation of OpenDTU-onBattery extensions can be found at the project's wiki](https://github.com/helgeerbe/OpenDTU-OnBattery/wiki).
+Documentation of OpenDTU-OnBattery extensions can be found in [the project's wiki](https://github.com/helgeerbe/OpenDTU-OnBattery/wiki).
-For documentation of openDTU core functionality I refer to the original [repo](https://github.com/tbnobody/OpenDTU) and its [documentation](https://tbnobody.github.io/OpenDTU-docs/).
+For documentation of OpenDTU core functionality refer to the original [repo](https://github.com/tbnobody/OpenDTU) and its [documentation](https://opendtu.solar).
-Please note that openDTU-onBattery may change significantly during its development.
+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](https://github.com/helgeerbe/OpenDTU-OnBattery/releases).
@@ -53,4 +53,4 @@ To find out what's new or improved have a look at the [changelog](https://github
A special Thank to Thomas Basler (tbnobody) the author of the original [OpenDTU](https://github.com/tbnobody/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.
+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.
diff --git a/README_onBattery.md b/README_onBattery.md
index 3f484c5c..e1489af6 100644
--- a/README_onBattery.md
+++ b/README_onBattery.md
@@ -6,7 +6,7 @@ This is a fork from the Hoymiles project [OpenDTU](https://github.com/tbnobody/O
> **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.
+> 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.
## Features
@@ -106,7 +106,7 @@ Some points for consideration are:
#### Operation modes
-openDTU-onBattery supports three operation modes for the Huawei PSU:
+openDTU-OnBattery supports three operation modes for the Huawei PSU:
1. Fully manual - In this mode the PSU needs to be turned on/off externally using MQTT and voltage and current limits need to be provided. See [MQTT Documentation](docs/MQTT_Topics.md) for details on these commands
2. Manual with auto power on / off - In this mode the PSU is turned on when a current limit > 1A is set. If the current limit is < 1A for some time the PSU is turned off. Current and voltage limits need to be provided externally using MQTT. See [MQTT Documentation](docs/MQTT_Topics.md) for details on these commands.
3. Automatic - In this mode the PSU power is controlled by the Power Meter and information provided in the web-interface. If excess power is present the PSU is turned on. The voltage limit is set as per web-interface and the current limit is set so that the maximum PSU output power equals the Power Meter value. Minium and maximum PSU power levels as configured in the web-interface are respected in this process. The PSU is turned off if the output current is limited and the output power drops below the minium power level. This will disable automatic mode until the battery is discharged below the start voltage level (set in the web-interface). This mode can be enabled using the web-interface and MQTT. See [MQTT Documentation](docs/MQTT_Topics.md)
@@ -135,7 +135,7 @@ It was the goal to replace the original Hoymiles DTU (Telemetry Gateway) with th
### Status
-[](https://github.com/helgeerbe/OpenDTU-OnBattery/actions/workflows/build.yml)
+[](https://github.com/helgeerbe/OpenDTU-OnBattery/actions/workflows/build.yml)
[](https://github.com/helgeerbe/OpenDTU-OnBattery/actions/workflows/cpplint.yml)
[](https://github.com/helgeerbe/OpenDTU-OnBattery/actions/workflows/yarnlint.yml)
diff --git a/docs/DeviceProfiles.md b/docs/DeviceProfiles.md
index 3444acc6..8976b821 100644
--- a/docs/DeviceProfiles.md
+++ b/docs/DeviceProfiles.md
@@ -1,91 +1,3 @@
# Device Profiles
-This documentation will has been moved and can be found here:
-
-## Structure of the json file for openDTU-onBattery (outdated example)
-
-```json
-[
- {
- "name": "Generic NodeMCU 38 pin",
- "nrf24": {
- "miso": 19,
- "mosi": 23,
- "clk": 18,
- "irq": 16,
- "en": 4,
- "cs": 5
- },
- "victron": {
- "rx": 22,
- "tx": 21
- },
- "battery": {
- "rx": 27,
- "tx": 14
- },
- "huawei": {
- "miso": 12,
- "mosi": 13,
- "clk": 26,
- "irq": 25,
- "power": 33,
- "cs": 15
- },
- "eth": {
- "enabled": false,
- "phy_addr": -1,
- "power": -1,
- "mdc": -1,
- "mdio": -1,
- "type": -1,
- "clk_mode": -1
- }
- },
- {
- "name": "Generic NodeMCU 38 pin with SSD1306",
- "nrf24": {
- "miso": 19,
- "mosi": 23,
- "clk": 18,
- "irq": 16,
- "en": 4,
- "cs": 5
- },
- "eth": {
- "enabled": false,
- "phy_addr": -1,
- "power": -1,
- "mdc": -1,
- "mdio": -1,
- "type": -1,
- "clk_mode": -1
- },
- "display": {
- "type": 2,
- "data": 21,
- "clk": 22
- }
- },
- {
- "name": "Olimex ESP32-POE",
- "nrf24": {
- "miso": 15,
- "mosi": 2,
- "clk": 14,
- "irq": 13,
- "en": 16,
- "cs": 5
- },
- "eth": {
- "enabled": true,
- "phy_addr": 0,
- "power": 12,
- "mdc": 23,
- "mdio": 18,
- "type": 0,
- "clk_mode": 3
- }
- }
-]
-```
\ No newline at end of file
+This documentation has been [moved to the wiki](https://github.com/helgeerbe/OpenDTU-OnBattery/wiki/Device-Profiles).
\ No newline at end of file
diff --git a/docs/hardware_flash.md b/docs/hardware_flash.md
index e8aa193c..2d1db186 100644
--- a/docs/hardware_flash.md
+++ b/docs/hardware_flash.md
@@ -2,15 +2,28 @@
## Hardware you need
+For a highly integrated board with most peripherals already included, have a
+look at the [OpenDTU Fusion](https://shop.allianceapps.io/products/opendtu-fusion-community-edition)
+board. There are also [OpenDTU-OnBattery-specific addons](https://github.com/markusdd/OpenDTUFusionDocs/blob/main/CANIso.md).
+
+Otherwise, read on to assemble your own components.
+
### ESP32 board
-For ease of use, buy a "ESP32 DEVKIT DOIT" or "ESP32 NodeMCU Development Board" with an ESP32-S3 or ESP-WROOM-32 chipset on it.
+For ease of use, buy a "ESP32 DEVKIT DOIT" or "ESP32 NodeMCU Development Board"
+with an ESP32-S3 chipset on it, **with at least 8 MB of flash memory**.
+Preferrably, the ESP32 should also have some embedded PSRAM. Look out for
+labels like "N8R2", "N16R8", where the number after the N is the amount of
+flash in Megabytes, and the number after the R is the amount of PSRAM in
+Megabytes.
Sample Picture:

-Also supported: Board with Ethernet-Connector and Power-over-Ethernet [Olimex ESP32-POE](https://www.olimex.com/Products/IoT/ESP32/ESP32-POE/open-source-hardware)
+Also supported: Board with Ethernet-Connector and Power-over-Ethernet (PoE)
+(select version with 8 MB of flash memory or more)
+[Olimex ESP32-POE](https://www.olimex.com/Products/IoT/ESP32/ESP32-POE/open-source-hardware)
### NRF24L01+ radio board (See inverter table above for supported inverters)
@@ -41,7 +54,10 @@ The CMT2300A uses 3-Wire half duplex SPI communication. Due to this fact it curr
### 3.3V / 5V logic level converter
-The logic level converter is used to interface with the Victron MPPT charge controller and the relay board. It converts the 3.3V logic level used by the ESP32 to 5V logic used by the other devices.
+The logic level converter is used to interface with the Victron MPPT charge
+controller and the relay board. It converts the 3.3V logic level used by the
+ESP32 to 5V logic used by the other devices. A commonly used digital isolator
+is the ADUM1201.
### SN65HVD230 CAN bus transceiver
@@ -49,7 +65,7 @@ The SN65HVD230 CAN bus transceiver is used to interface with the Pylontech batte
### MCP2515 CAN bus module
-See [Wiki](https://github.com/helgeerbe/OpenDTU-OnBattery/wiki/Huawei-AC-PSU) for details.
+Used to connect to the Huawei PSU (AC charger). See [the Wiki](https://github.com/helgeerbe/OpenDTU-OnBattery/wiki/Huawei-AC-PSU) for details.
### Relay module
@@ -71,30 +87,8 @@ Use a power supply with 5 V and 1 A. The USB cable connected to your PC/Notebook
### Change pin assignment
-Its possible to change all the pins of the NRF24L01+ module, the Display, the LED etc.
-The recommend way to change the pin assignment is by creating a custom [device profile](DeviceProfiles.md).
-It is also possible to create a custom environment and compile the source yourself. This can be achieved by copying one of the [env:....] sections from 'platformio.ini' to 'platformio_override.ini' and editing the 'platformio_override.ini' file and add/change one or more of the following lines to the 'build_flags' parameter:
-
-```makefile
--DHOYMILES_PIN_MISO=19
--DHOYMILES_PIN_MOSI=23
--DHOYMILES_PIN_SCLK=18
--DHOYMILES_PIN_IRQ=16
--DHOYMILES_PIN_CE=4
--DHOYMILES_PIN_CS=5
--DVICTRON_PIN_TX=21
--DVICTRON_PIN_RX=22
--DPYLONTECH_PIN_RX=27
--DPYLONTECH_PIN_TX=14
--DHUAWEI_PIN_MISO=12
--DHUAWEI_PIN_MOSI=13
--DHUAWEI_PIN_SCLK=26
--DHUAWEI_PIN_IRQ=25
--DHUAWEI_PIN_CS=15
--DHUAWEI_PIN_POWER=33
-```
-
-It is recommended to make all changes only in the 'platformio_override.ini', this is your personal copy.
+It is possible to change all the pins of the NRF24L01+ module, the Display, the LED etc.
+The way to change the pin assignment is by creating a custom [device profile](https://github.com/helgeerbe/OpenDTU-OnBattery/wiki/Device-Profiles).
## Flashing and starting up
diff --git a/include/Battery.h b/include/Battery.h
index 700c46c4..5130381c 100644
--- a/include/Battery.h
+++ b/include/Battery.h
@@ -14,7 +14,6 @@ public:
virtual void deinit() = 0;
virtual void loop() = 0;
virtual std::shared_ptr getStats() const = 0;
- virtual bool usesHwPort2() const { return false; }
};
class BatteryClass {
diff --git a/include/BatteryStats.h b/include/BatteryStats.h
index ca669aa8..0f86c7c5 100644
--- a/include/BatteryStats.h
+++ b/include/BatteryStats.h
@@ -58,6 +58,8 @@ class BatteryStats {
}
String _manufacturer = "unknown";
+ String _hwversion = "";
+ String _fwversion = "";
uint32_t _lastUpdate = 0;
private:
@@ -157,8 +159,9 @@ class VictronSmartShuntStats : public BatteryStats {
uint32_t _timeToGo;
float _chargedEnergy;
float _dischargedEnergy;
- String _modelName;
int32_t _instantaneousPower;
+ float _midpointVoltage;
+ float _midpointDeviation;
float _consumedAmpHours;
int32_t _lastFullCharge;
diff --git a/include/JkBmsController.h b/include/JkBmsController.h
index bbc5a5ac..7156d760 100644
--- a/include/JkBmsController.h
+++ b/include/JkBmsController.h
@@ -7,6 +7,8 @@
#include "Battery.h"
#include "JkBmsSerialMessage.h"
+//#define JKBMS_DUMMY_SERIAL
+
class DataPointContainer;
namespace JkBms {
@@ -19,11 +21,16 @@ class Controller : public BatteryProvider {
void deinit() final;
void loop() final;
std::shared_ptr getStats() const final { return _stats; }
- bool usesHwPort2() const final {
- return ARDUINO_USB_CDC_ON_BOOT != 1;
- }
private:
+ static char constexpr _serialPortOwner[] = "JK BMS";
+
+#ifdef JKBMS_DUMMY_SERIAL
+ std::unique_ptr _upSerial;
+#else
+ std::unique_ptr _upSerial;
+#endif
+
enum class Status : unsigned {
Initializing,
Timeout,
diff --git a/include/PinMapping.h b/include/PinMapping.h
index f6db7a2d..75b27294 100644
--- a/include/PinMapping.h
+++ b/include/PinMapping.h
@@ -45,6 +45,8 @@ struct PinMapping_t {
int8_t victron_rx;
int8_t victron_tx2;
int8_t victron_rx2;
+ int8_t victron_tx3;
+ int8_t victron_rx3;
int8_t battery_rx;
int8_t battery_rxen;
int8_t battery_tx;
diff --git a/include/PowerMeter.h b/include/PowerMeter.h
index 0ce38f61..5b3d8f31 100644
--- a/include/PowerMeter.h
+++ b/include/PowerMeter.h
@@ -60,6 +60,8 @@ private:
mutable std::mutex _mutex;
+ static char constexpr _sdmSerialPortOwner[] = "SDM power meter";
+ std::unique_ptr _upSdmSerial = nullptr;
std::unique_ptr _upSdm = nullptr;
std::unique_ptr _upSmlSerial = nullptr;
diff --git a/include/SerialPortManager.h b/include/SerialPortManager.h
index 4d4c2dab..372b9c50 100644
--- a/include/SerialPortManager.h
+++ b/include/SerialPortManager.h
@@ -1,27 +1,21 @@
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
-#include