Skip to content

Commit

Permalink
Merge remote-tracking branch v23.12.18 'tbnobody/OpenDTU/master' into…
Browse files Browse the repository at this point in the history
… merge-v23.12.16
  • Loading branch information
helgeerbe committed Dec 19, 2023
2 parents 7c11a5a + 677d822 commit a2107f9
Show file tree
Hide file tree
Showing 13 changed files with 320 additions and 145 deletions.
13 changes: 11 additions & 2 deletions include/MqttHandleHass.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,20 @@ class MqttHandleHassClass {
private:
void loop();
void publish(const String& subtopic, const String& payload);
void publishField(std::shared_ptr<InverterAbstract> inv, const ChannelType_t type, const ChannelNum_t channel, const byteAssign_fieldDeviceClass_t fieldType, const bool clear = false);
void publishDtuSensor(const char* name, const char* device_class, const char* category, const char* icon, const char* unit_of_measure, const char* subTopic);
void publishDtuBinarySensor(const char* name, const char* device_class, const char* category, const char* payload_on, const char* payload_off, const char* subTopic = "");
void publishInverterField(std::shared_ptr<InverterAbstract> inv, const ChannelType_t type, const ChannelNum_t channel, const byteAssign_fieldDeviceClass_t fieldType, const bool clear = false);
void publishInverterButton(std::shared_ptr<InverterAbstract> inv, const char* caption, const char* icon, const char* category, const char* deviceClass, const char* subTopic, const char* payload);
void publishInverterNumber(std::shared_ptr<InverterAbstract> inv, const char* caption, const char* icon, const char* category, const char* commandTopic, const char* stateTopic, const char* unitOfMeasure, const int16_t min = 1, const int16_t max = 100);
void publishInverterBinarySensor(std::shared_ptr<InverterAbstract> inv, const char* caption, const char* subTopic, const char* payload_on, const char* payload_off);
void createDeviceInfo(JsonObject& object, std::shared_ptr<InverterAbstract> inv);

static void createInverterInfo(DynamicJsonDocument& doc, std::shared_ptr<InverterAbstract> inv);
static void createDtuInfo(DynamicJsonDocument& doc);

static void createDeviceInfo(DynamicJsonDocument& doc, const String& name, const String& identifiers, const String& configuration_url, const String& manufacturer, const String& model, const String& sw_version, const String& via_device = "");

static String getDtuUniqueId();
static String getDtuUrl();

Task _loopTask;

Expand Down
1 change: 0 additions & 1 deletion lib/Hoymiles/src/Hoymiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ void HoymilesClass::loop()
if (iv != nullptr && iv->getRadio()->isInitialized() && iv->getRadio()->isQueueEmpty()) {

if (iv->getZeroValuesIfUnreachable() && !iv->isReachable()) {
Hoymiles.getMessageOutput()->println("Set runtime data to zero");
iv->Statistics()->zeroRuntimeData();
}

Expand Down
55 changes: 50 additions & 5 deletions lib/Hoymiles/src/parser/GridProfileParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const std::array<const ProfileType_t, PROFILE_TYPE_COUNT> GridProfileParser::_pr
{ 0x0a, 0x00, "European - EN 50549-1:2019" },
{ 0x0c, 0x00, "AT Tor - EU_EN50438" },
{ 0x0d, 0x04, "France" },
{ 0x12, 0x00, "Poland" },
{ 0x12, 0x00, "Poland - EU_EN50438" },
{ 0x37, 0x00, "Swiss - CH_NA EEA-NE7-CH2020" },
} };

Expand Down Expand Up @@ -45,7 +45,7 @@ constexpr GridProfileItemDefinition_t make_value(frozen::string Name, frozen::st
return v;
}

constexpr frozen::map<uint8_t, GridProfileItemDefinition_t, 0x38> itemDefinitions = {
constexpr frozen::map<uint8_t, GridProfileItemDefinition_t, 0x39> itemDefinitions = {
{ 0x01, make_value("Nominale Voltage (NV)", "V", 10) },
{ 0x02, make_value("Low Voltage 1 (LV1)", "V", 10) },
{ 0x03, make_value("LV1 Maximum Trip Time (MTT)", "s", 10) },
Expand Down Expand Up @@ -102,6 +102,7 @@ constexpr frozen::map<uint8_t, GridProfileItemDefinition_t, 0x38> itemDefinition
{ 0x36, make_value("WPF Function Activated", "bool", 1) },
{ 0x37, make_value("Start of Power of WPF (Pstart)", "%Pn", 10) },
{ 0x38, make_value("Power Factor ar Rated Power (PFRP)", "", 100) },
{ 0xff, make_value("Unkown Value", "", 1) },
};

const std::array<const GridProfileValue_t, SECTION_VALUE_COUNT> GridProfileParser::_profileValues = { {
Expand All @@ -123,6 +124,14 @@ const std::array<const GridProfileValue_t, SECTION_VALUE_COUNT> GridProfileParse
{ 0x00, 0x03, 0x08 },
{ 0x00, 0x03, 0x09 },

// Version 0x08
{ 0x00, 0x08, 0x01 },
{ 0x00, 0x08, 0x02 },
{ 0x00, 0x08, 0x03 },
{ 0x00, 0x08, 0x04 },
{ 0x00, 0x08, 0x05 },
{ 0x00, 0x08, 0xff },

// Version 0x0a
{ 0x00, 0x0a, 0x01 },
{ 0x00, 0x0a, 0x02 },
Expand Down Expand Up @@ -159,6 +168,21 @@ const std::array<const GridProfileValue_t, SECTION_VALUE_COUNT> GridProfileParse
{ 0x00, 0x0c, 0x0c },
{ 0x00, 0x0c, 0x0a },

// Version 0x35
{ 0x00, 0x35, 0x01 },
{ 0x00, 0x35, 0x02 },
{ 0x00, 0x35, 0x03 },
{ 0x00, 0x35, 0x04 },
{ 0x00, 0x35, 0x05 },
{ 0x00, 0x35, 0x06 },
{ 0x00, 0x35, 0x07 },
{ 0x00, 0x35, 0x08 },
{ 0x00, 0x35, 0x09 },
{ 0x00, 0x35, 0xff },
{ 0x00, 0x35, 0xff },
{ 0x00, 0x35, 0xff },
{ 0x00, 0x35, 0xff },

// Frequency (H/LFRT)
// Version 0x00
{ 0x10, 0x00, 0x0d },
Expand Down Expand Up @@ -190,6 +214,15 @@ const std::array<const GridProfileValue_t, SECTION_VALUE_COUNT> GridProfileParse
{ 0x30, 0x03, 0x1a },
{ 0x30, 0x03, 0x1b },

// Version 0x07
{ 0x30, 0x07, 0x17 },
{ 0x30, 0x07, 0x18 },
{ 0x30, 0x07, 0x19 },
{ 0x30, 0x07, 0x1a },
{ 0x30, 0x07, 0x1b },
{ 0x30, 0x07, 0xff },
{ 0x30, 0x07, 0xff },

// Ramp Rates (RR)
// Version 0x00
{ 0x40, 0x00, 0x1c },
Expand Down Expand Up @@ -217,6 +250,13 @@ const std::array<const GridProfileValue_t, SECTION_VALUE_COUNT> GridProfileParse
{ 0x50, 0x08, 0x22 },
{ 0x50, 0x08, 0x23 },

// Version 0x11
{ 0x50, 0x11, 0x1e },
{ 0x50, 0x11, 0x1f },
{ 0x50, 0x11, 0x20 },
{ 0x50, 0x11, 0x21 },
{ 0x50, 0x11, 0x22 },

// Volt Watt (VW)
// Version 0x00
{ 0x60, 0x00, 0x24 },
Expand Down Expand Up @@ -336,7 +376,7 @@ std::list<GridProfileSection_t> GridProfileParser::getProfile() const
do {
const uint8_t section_id = _payloadGridProfile[pos];
const uint8_t section_version = _payloadGridProfile[pos + 1];
const int8_t section_start = getSectionStart(section_id, section_version);
const int16_t section_start = getSectionStart(section_id, section_version);
const uint8_t section_size = getSectionSize(section_id, section_version);
pos += 2;

Expand All @@ -348,6 +388,11 @@ std::list<GridProfileSection_t> GridProfileParser::getProfile() const
break;
}

if (section_start == -1) {
section.SectionName = "Unknown";
break;
}

for (uint8_t val_id = 0; val_id < section_size; val_id++) {
auto itemDefinition = itemDefinitions.at(_profileValues[section_start + val_id].ItemDefinition);

Expand Down Expand Up @@ -382,9 +427,9 @@ uint8_t GridProfileParser::getSectionSize(const uint8_t section_id, const uint8_
return count;
}

int8_t GridProfileParser::getSectionStart(const uint8_t section_id, const uint8_t section_version)
int16_t GridProfileParser::getSectionStart(const uint8_t section_id, const uint8_t section_version)
{
uint8_t count = -1;
int16_t count = -1;
for (auto& values : _profileValues) {
count++;
if (values.Section == section_id && values.Version == section_version) {
Expand Down
4 changes: 2 additions & 2 deletions lib/Hoymiles/src/parser/GridProfileParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

#define GRID_PROFILE_SIZE 141
#define PROFILE_TYPE_COUNT 7
#define SECTION_VALUE_COUNT 113
#define SECTION_VALUE_COUNT 144

typedef struct {
uint8_t lIdx;
Expand Down Expand Up @@ -45,7 +45,7 @@ class GridProfileParser : public Parser {

private:
static uint8_t getSectionSize(const uint8_t section_id, const uint8_t section_version);
static int8_t getSectionStart(const uint8_t section_id, const uint8_t section_version);
static int16_t getSectionStart(const uint8_t section_id, const uint8_t section_version);

uint8_t _payloadGridProfile[GRID_PROFILE_SIZE] = {};
uint8_t _gridProfileLength = 0;
Expand Down
5 changes: 1 addition & 4 deletions lib/Hoymiles/src/parser/StatisticsParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,6 @@ void StatisticsParser::clearBuffer()
{
memset(_payloadStatistic, 0, STATISTIC_PACKET_SIZE);
_statisticLength = 0;

memset(_lastYieldDay, 0, sizeof(_lastYieldDay));
}

void StatisticsParser::appendFragment(const uint8_t offset, const uint8_t* payload, const uint8_t len)
Expand Down Expand Up @@ -111,8 +109,7 @@ void StatisticsParser::endAppendFragment()
// currently all values are zero --> Add last known values to offset
Hoymiles.getMessageOutput()->printf("Yield Day reset detected!\r\n");

setChannelFieldOffset(TYPE_DC, c, FLD_YD,
getChannelFieldOffset(TYPE_DC, c, FLD_YD) + _lastYieldDay[static_cast<uint8_t>(c)]);
setChannelFieldOffset(TYPE_DC, c, FLD_YD, _lastYieldDay[static_cast<uint8_t>(c)]);

_lastYieldDay[static_cast<uint8_t>(c)] = 0;
} else {
Expand Down
2 changes: 1 addition & 1 deletion lib/Hoymiles/src/parser/StatisticsParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,5 +168,5 @@ class StatisticsParser : public Parser {
uint32_t _lastUpdateFromInternal = 0;

bool _enableYieldDayCorrection = false;
float _lastYieldDay[CH_CNT];
float _lastYieldDay[CH_CNT] = {};
};
Loading

0 comments on commit a2107f9

Please sign in to comment.