Skip to content

Commit

Permalink
Merge upstream tag 'v24.6.10' into development
Browse files Browse the repository at this point in the history
  • Loading branch information
schlimmchen committed Jun 21, 2024
2 parents 83ac154 + c144b68 commit 5e3a53d
Show file tree
Hide file tree
Showing 65 changed files with 664 additions and 517 deletions.
26 changes: 22 additions & 4 deletions .github/ISSUE_TEMPLATE/bug_report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,18 @@ body:
- type: markdown
attributes:
value: >
### ✋ **This is bug tracker, not a support forum**
### ⚠️ Please remember: issues are for *bugs*
That is, something you believe affects every single user of OpenDTU, not just you. If you're not sure, start with one of the other options below.
- type: markdown
attributes:
value: |
#### Have a question? 👉 [Start a new discussion](https://github.com/tbnobody/OpenDTU/discussions/new) or [ask in chat](https://discord.gg/WzhxEY62mB).
If something isn't working right, you have questions or need help, [**get in touch on the Discussions**](https://github.com/tbnobody/OpenDTU/discussions).
#### Before opening an issue, please double check:
Please quickly search existing issues first before submitting a bug.
- [Documentation](https://www.opendtu.solar).
- [The FAQs](https://www.opendtu.solar/firmware/faq/).
- [Existing issues and discussions](https://github.com/tbnobody/OpenDTU/search?q=&type=issues).
- type: textarea
id: what-happened
attributes:
Expand Down Expand Up @@ -65,4 +72,15 @@ body:
Links? References? Anything that will give us more context about the issue you are encountering!
Tip: You can attach images or log files by clicking this area to highlight it and then dragging files in.
validations:
required: false
required: false
- type: checkboxes
id: required-checks
attributes:
label: Please confirm the following
options:
- label: I believe this issue is a bug that affects all users of OpenDTU, not something specific to my installation.
required: true
- label: I have already searched for relevant existing issues and discussions before opening this report.
required: true
- label: I have updated the title field above with a concise description.
required: true
1 change: 1 addition & 0 deletions include/Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ struct INVERTER_CONFIG_T {
uint8_t ReachableThreshold;
bool ZeroRuntimeDataIfUnrechable;
bool ZeroYieldDayOnMidnight;
bool ClearEventlogOnMidnight;
bool YieldDayCorrection;
CHANNEL_CONFIG_T channel[INV_MAX_CHAN_COUNT];
};
Expand Down
3 changes: 3 additions & 0 deletions include/MqttHandleInverter.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ class MqttHandleInverterClass {

static String getTopic(std::shared_ptr<InverterAbstract> inv, const ChannelType_t type, const ChannelNum_t channel, const FieldId_t fieldId);

void subscribeTopics();
void unsubscribeTopics();

private:
void loop();
void publishField(std::shared_ptr<InverterAbstract> inv, const ChannelType_t type, const ChannelNum_t channel, const FieldId_t fieldId);
Expand Down
51 changes: 51 additions & 0 deletions lib/CpuTemperature/src/CpuTemperature.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* Copyright (C) 2024 Thomas Basler and others
*/

#include "CpuTemperature.h"
#include <Arduino.h>

#if defined(CONFIG_IDF_TARGET_ESP32)
// there is no official API available on the original ESP32
extern "C" {
uint8_t temprature_sens_read();
}
#elif defined(CONFIG_IDF_TARGET_ESP32C3) || defined(CONFIG_IDF_TARGET_ESP32S2) || defined(CONFIG_IDF_TARGET_ESP32S3)
#include "driver/temp_sensor.h"
#endif

CpuTemperatureClass CpuTemperature;

float CpuTemperatureClass::read()
{
std::lock_guard<std::mutex> lock(_mutex);

float temperature = NAN;
bool success = false;

#if defined(CONFIG_IDF_TARGET_ESP32)
uint8_t raw = temprature_sens_read();
ESP_LOGV(TAG, "Raw temperature value: %d", raw);
temperature = (raw - 32) / 1.8f;
success = (raw != 128);
#elif defined(CONFIG_IDF_TARGET_ESP32C3) || defined(CONFIG_IDF_TARGET_ESP32S2) || defined(CONFIG_IDF_TARGET_ESP32S3)
temp_sensor_config_t tsens = TSENS_CONFIG_DEFAULT();
temp_sensor_set_config(tsens);
temp_sensor_start();
#if defined(CONFIG_IDF_TARGET_ESP32S3) && (ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(4, 4, 3))
#error \
"ESP32-S3 internal temperature sensor requires ESP IDF V4.4.3 or higher. See https://github.com/esphome/issues/issues/4271"
#endif
esp_err_t result = temp_sensor_read_celsius(&temperature);
temp_sensor_stop();
success = (result == ESP_OK);
#endif

if (success && std::isfinite(temperature)) {
return temperature;
} else {
ESP_LOGD(TAG, "Ignoring invalid temperature (success=%d, value=%.1f)", success, temperature);
return NAN;
}
}
14 changes: 14 additions & 0 deletions lib/CpuTemperature/src/CpuTemperature.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once

#include <mutex>

class CpuTemperatureClass {
public:
float read();

private:
std::mutex _mutex;
};

extern CpuTemperatureClass CpuTemperature;
3 changes: 3 additions & 0 deletions lib/Hoymiles/src/Hoymiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,9 @@ void HoymilesClass::loop()
if (inv->getZeroYieldDayOnMidnight()) {
inv->Statistics()->zeroDailyData();
}
if (inv->getClearEventlogOnMidnight()) {
inv->EventLog()->clearBuffer();
}
}

lastWeekDay = currentWeekDay;
Expand Down
4 changes: 2 additions & 2 deletions lib/Hoymiles/src/HoymilesRadio.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ class HoymilesRadio {
}

template <typename T>
std::shared_ptr<T> prepareCommand()
std::shared_ptr<T> prepareCommand(InverterAbstract* inv)
{
return std::make_shared<T>();
return std::make_shared<T>(inv);
}

protected:
Expand Down
26 changes: 13 additions & 13 deletions lib/Hoymiles/src/commands/ActivePowerControlCommand.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* Copyright (C) 2022-2023 Thomas Basler and others
* Copyright (C) 2022-2024 Thomas Basler and others
*/

/*
Expand All @@ -25,8 +25,8 @@ ID Target Addr Source Addr Cmd SCmd ? Limit Type CRC16 CRC8

#define CRC_SIZE 6

ActivePowerControlCommand::ActivePowerControlCommand(const uint64_t target_address, const uint64_t router_address)
: DevControlCommand(target_address, router_address)
ActivePowerControlCommand::ActivePowerControlCommand(InverterAbstract* inv, const uint64_t router_address)
: DevControlCommand(inv, router_address)
{
_payload[10] = 0x0b;
_payload[11] = 0x00;
Expand Down Expand Up @@ -62,24 +62,24 @@ void ActivePowerControlCommand::setActivePowerLimit(const float limit, const Pow
udpateCRC(CRC_SIZE);
}

bool ActivePowerControlCommand::handleResponse(InverterAbstract& inverter, const fragment_t fragment[], const uint8_t max_fragment_id)
bool ActivePowerControlCommand::handleResponse(const fragment_t fragment[], const uint8_t max_fragment_id)
{
if (!DevControlCommand::handleResponse(inverter, fragment, max_fragment_id)) {
if (!DevControlCommand::handleResponse(fragment, max_fragment_id)) {
return false;
}

if ((getType() == PowerLimitControlType::RelativNonPersistent) || (getType() == PowerLimitControlType::RelativPersistent)) {
inverter.SystemConfigPara()->setLimitPercent(getLimit());
_inv->SystemConfigPara()->setLimitPercent(getLimit());
} else {
const uint16_t max_power = inverter.DevInfo()->getMaxPower();
const uint16_t max_power = _inv->DevInfo()->getMaxPower();
if (max_power > 0) {
inverter.SystemConfigPara()->setLimitPercent(static_cast<float>(getLimit()) / max_power * 100);
_inv->SystemConfigPara()->setLimitPercent(static_cast<float>(getLimit()) / max_power * 100);
} else {
// TODO(tbnobody): Not implemented yet because we only can publish the percentage value
}
}
inverter.SystemConfigPara()->setLastUpdateCommand(millis());
inverter.SystemConfigPara()->setLastLimitCommandSuccess(CMD_OK);
_inv->SystemConfigPara()->setLastUpdateCommand(millis());
_inv->SystemConfigPara()->setLastLimitCommandSuccess(CMD_OK);
return true;
}

Expand All @@ -94,7 +94,7 @@ PowerLimitControlType ActivePowerControlCommand::getType()
return (PowerLimitControlType)(((uint16_t)_payload[14] << 8) | _payload[15]);
}

void ActivePowerControlCommand::gotTimeout(InverterAbstract& inverter)
void ActivePowerControlCommand::gotTimeout()
{
inverter.SystemConfigPara()->setLastLimitCommandSuccess(CMD_NOK);
}
_inv->SystemConfigPara()->setLastLimitCommandSuccess(CMD_NOK);
}
8 changes: 4 additions & 4 deletions lib/Hoymiles/src/commands/ActivePowerControlCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ typedef enum { // ToDo: to be verified by field tests

class ActivePowerControlCommand : public DevControlCommand {
public:
explicit ActivePowerControlCommand(const uint64_t target_address = 0, const uint64_t router_address = 0);
explicit ActivePowerControlCommand(InverterAbstract* inv, const uint64_t router_address = 0);

virtual String getCommandName() const;

virtual bool handleResponse(InverterAbstract& inverter, const fragment_t fragment[], const uint8_t max_fragment_id);
virtual void gotTimeout(InverterAbstract& inverter);
virtual bool handleResponse(const fragment_t fragment[], const uint8_t max_fragment_id);
virtual void gotTimeout();

void setActivePowerLimit(const float limit, const PowerLimitControlType type = RelativNonPersistent);
float getLimit() const;
PowerLimitControlType getType();
};
};
28 changes: 14 additions & 14 deletions lib/Hoymiles/src/commands/AlarmDataCommand.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* Copyright (C) 2022-2023 Thomas Basler and others
* Copyright (C) 2022-2024 Thomas Basler and others
*/

/*
Expand All @@ -23,8 +23,8 @@ ID Target Addr Source Addr Idx DT ? Time Gap AlarmId Pa
#include "AlarmDataCommand.h"
#include "inverters/InverterAbstract.h"

AlarmDataCommand::AlarmDataCommand(const uint64_t target_address, const uint64_t router_address, const time_t time)
: MultiDataCommand(target_address, router_address)
AlarmDataCommand::AlarmDataCommand(InverterAbstract* inv, const uint64_t router_address, const time_t time)
: MultiDataCommand(inv, router_address)
{
setTime(time);
setDataType(0x11);
Expand All @@ -36,28 +36,28 @@ String AlarmDataCommand::getCommandName() const
return "AlarmData";
}

bool AlarmDataCommand::handleResponse(InverterAbstract& inverter, const fragment_t fragment[], const uint8_t max_fragment_id)
bool AlarmDataCommand::handleResponse(const fragment_t fragment[], const uint8_t max_fragment_id)
{
// Check CRC of whole payload
if (!MultiDataCommand::handleResponse(inverter, fragment, max_fragment_id)) {
if (!MultiDataCommand::handleResponse(fragment, max_fragment_id)) {
return false;
}

// Move all fragments into target buffer
uint8_t offs = 0;
inverter.EventLog()->beginAppendFragment();
inverter.EventLog()->clearBuffer();
_inv->EventLog()->beginAppendFragment();
_inv->EventLog()->clearBuffer();
for (uint8_t i = 0; i < max_fragment_id; i++) {
inverter.EventLog()->appendFragment(offs, fragment[i].fragment, fragment[i].len);
_inv->EventLog()->appendFragment(offs, fragment[i].fragment, fragment[i].len);
offs += (fragment[i].len);
}
inverter.EventLog()->endAppendFragment();
inverter.EventLog()->setLastAlarmRequestSuccess(CMD_OK);
inverter.EventLog()->setLastUpdate(millis());
_inv->EventLog()->endAppendFragment();
_inv->EventLog()->setLastAlarmRequestSuccess(CMD_OK);
_inv->EventLog()->setLastUpdate(millis());
return true;
}

void AlarmDataCommand::gotTimeout(InverterAbstract& inverter)
void AlarmDataCommand::gotTimeout()
{
inverter.EventLog()->setLastAlarmRequestSuccess(CMD_NOK);
}
_inv->EventLog()->setLastAlarmRequestSuccess(CMD_NOK);
}
8 changes: 4 additions & 4 deletions lib/Hoymiles/src/commands/AlarmDataCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@

class AlarmDataCommand : public MultiDataCommand {
public:
explicit AlarmDataCommand(const uint64_t target_address = 0, const uint64_t router_address = 0, const time_t time = 0);
explicit AlarmDataCommand(InverterAbstract* inv, const uint64_t router_address = 0, const time_t time = 0);

virtual String getCommandName() const;

virtual bool handleResponse(InverterAbstract& inverter, const fragment_t fragment[], const uint8_t max_fragment_id);
virtual void gotTimeout(InverterAbstract& inverter);
};
virtual bool handleResponse(const fragment_t fragment[], const uint8_t max_fragment_id);
virtual void gotTimeout();
};
6 changes: 3 additions & 3 deletions lib/Hoymiles/src/commands/ChannelChangeCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ ID Target Addr Source Addr ? ? ? CH ? CRC8
*/
#include "ChannelChangeCommand.h"

ChannelChangeCommand::ChannelChangeCommand(const uint64_t target_address, const uint64_t router_address, const uint8_t channel)
: CommandAbstract(target_address, router_address)
ChannelChangeCommand::ChannelChangeCommand(InverterAbstract* inv, const uint64_t router_address, const uint8_t channel)
: CommandAbstract(inv, router_address)
{
_payload[0] = 0x56;
_payload[13] = 0x14;
Expand Down Expand Up @@ -67,7 +67,7 @@ void ChannelChangeCommand::setCountryMode(const CountryModeId_t mode)
}
}

bool ChannelChangeCommand::handleResponse(InverterAbstract& inverter, const fragment_t fragment[], const uint8_t max_fragment_id)
bool ChannelChangeCommand::handleResponse(const fragment_t fragment[], const uint8_t max_fragment_id)
{
return true;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/Hoymiles/src/commands/ChannelChangeCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class ChannelChangeCommand : public CommandAbstract {
public:
explicit ChannelChangeCommand(const uint64_t target_address = 0, const uint64_t router_address = 0, const uint8_t channel = 0);
explicit ChannelChangeCommand(InverterAbstract* inv, const uint64_t router_address = 0, const uint8_t channel = 0);

virtual String getCommandName() const;

Expand All @@ -15,7 +15,7 @@ class ChannelChangeCommand : public CommandAbstract {

void setCountryMode(const CountryModeId_t mode);

virtual bool handleResponse(InverterAbstract& inverter, const fragment_t fragment[], const uint8_t max_fragment_id);
virtual bool handleResponse(const fragment_t fragment[], const uint8_t max_fragment_id);

virtual uint8_t getMaxResendCount();
};
11 changes: 7 additions & 4 deletions lib/Hoymiles/src/commands/CommandAbstract.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* Copyright (C) 2022-2023 Thomas Basler and others
* Copyright (C) 2022-2024 Thomas Basler and others
*/

/*
Expand Down Expand Up @@ -29,13 +29,16 @@ Source Address: 80 12 23 04
#include "CommandAbstract.h"
#include "crc.h"
#include <string.h>
#include "../inverters/InverterAbstract.h"

CommandAbstract::CommandAbstract(const uint64_t target_address, const uint64_t router_address)
CommandAbstract::CommandAbstract(InverterAbstract* inv, const uint64_t router_address)
{
memset(_payload, 0, RF_LEN);
_payload_size = 0;

setTargetAddress(target_address);
_inv = inv;

setTargetAddress(_inv->serial());
setRouterAddress(router_address);
setSendCount(0);
setTimeout(0);
Expand Down Expand Up @@ -122,7 +125,7 @@ void CommandAbstract::convertSerialToPacketId(uint8_t buffer[], const uint64_t s
buffer[0] = s.b[3];
}

void CommandAbstract::gotTimeout(InverterAbstract& inverter)
void CommandAbstract::gotTimeout()
{
}

Expand Down
Loading

0 comments on commit 5e3a53d

Please sign in to comment.