Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
  • Loading branch information
helgeerbe committed Aug 29, 2023
2 parents 026bca9 + 929b477 commit d5308b1
Show file tree
Hide file tree
Showing 36 changed files with 318 additions and 199 deletions.
45 changes: 45 additions & 0 deletions docs/DeviceProfiles/lilygo_ttgo_t-internet_poe.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,50 @@
"type": 0,
"clk_mode": 3
}
},
{
"name": "LILYGO TTGO T-Internet-POE, nrf24 direct solder",
"nrf24": {
"miso": 12,
"mosi": 4,
"clk": 15,
"irq": 33,
"en": 14,
"cs": 2
},
"eth": {
"enabled": true,
"phy_addr": 0,
"power": -1,
"mdc": 23,
"mdio": 18,
"type": 0,
"clk_mode": 3
}
},
{
"name": "LILYGO TTGO T-Internet-POE, nrf24 direct solder, SSD1306",
"nrf24": {
"miso": 12,
"mosi": 4,
"clk": 15,
"irq": 33,
"en": 14,
"cs": 2
},
"eth": {
"enabled": true,
"phy_addr": 0,
"power": -1,
"mdc": 23,
"mdio": 18,
"type": 0,
"clk_mode": 3
},
"display": {
"type": 2,
"data": 16,
"clk": 32
}
}
]
3 changes: 3 additions & 0 deletions include/Display_Graphic.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class DisplayGraphicClass {
void init(DisplayType_t type, uint8_t data, uint8_t clk, uint8_t cs, uint8_t reset);
void loop();
void setContrast(uint8_t contrast);
void setStatus(bool turnOn);
void setOrientation(uint8_t rotation = DISPLAY_ROTATION);
void setLanguage(uint8_t language);
void setStartupDisplay();
Expand All @@ -33,6 +34,8 @@ class DisplayGraphicClass {

U8G2* _display;

bool _displayTurnedOn;

DisplayType_t _display_type = DisplayType_t::None;
uint8_t _display_language = DISPLAY_LANGUAGE;
uint8_t _mExtra;
Expand Down
4 changes: 4 additions & 0 deletions include/Led_Single.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ class LedSingleClass {
void init();
void loop();

void turnAllOff();
void turnAllOn();

private:
enum class LedState_t {
On,
Expand All @@ -27,6 +30,7 @@ class LedSingleClass {
};

LedState_t _ledState[PINMAPPING_LED_COUNT];
LedState_t _allState;
TimeoutHelper _updateTimeout;
TimeoutHelper _blinkTimeout;
uint8_t _ledActive = 0;
Expand Down
2 changes: 1 addition & 1 deletion include/MqttHandlePowerLimiter.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class MqttHandlePowerLimiterClass {
void loop();

private:
void onMqttMessage(const espMqttClientTypes::MessageProperties& properties, const char* topic, const uint8_t* payload, size_t len, size_t index, size_t total);
void onCmdMode(const espMqttClientTypes::MessageProperties& properties, const char* topic, const uint8_t* payload, size_t len, size_t index, size_t total);

uint32_t _lastPublishStats;
uint32_t _lastPublish;
Expand Down
13 changes: 10 additions & 3 deletions include/PowerLimiter.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,15 @@ class PowerLimiterClass {
void loop();
uint8_t getPowerLimiterState();
int32_t getLastRequestedPowerLimit();
void setMode(uint8_t mode);
bool getMode();

enum class Mode : unsigned {
Normal = 0,
Disabled = 1,
UnconditionalFullSolarPassthrough = 2
};

void setMode(Mode m) { _mode = m; }
Mode getMode() const { return _mode; }
void calcNextInverterRestart();

private:
Expand All @@ -63,7 +70,7 @@ class PowerLimiterClass {
uint32_t _lastCalculation = 0;
static constexpr uint32_t _calculationBackoffMsDefault = 128;
uint32_t _calculationBackoffMs = _calculationBackoffMsDefault;
uint8_t _mode = PL_MODE_ENABLE_NORMAL_OP;
Mode _mode = Mode::Normal;
std::shared_ptr<InverterAbstract> _inverter = nullptr;
bool _batteryDischargeEnabled = false;
uint32_t _nextInverterRestart = 0; // Values: 0->not calculated / 1->no restart configured / >1->time of next inverter restart in millis()
Expand Down
1 change: 1 addition & 0 deletions include/Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ class Utils {
static uint32_t getChipId();
static uint64_t generateDtuSerial();
static int getTimezoneOffset();
static void restartDtu();
};
45 changes: 25 additions & 20 deletions include/WebApi_prometheus.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,33 +13,38 @@ class WebApiPrometheusClass {
private:
void onPrometheusMetricsGet(AsyncWebServerRequest* request);

void addField(AsyncResponseStream* stream, String& serial, uint8_t idx, std::shared_ptr<InverterAbstract> inv, ChannelType_t type, ChannelNum_t channel, FieldId_t fieldId, const char* channelName = NULL);
void addField(AsyncResponseStream* stream, String& serial, uint8_t idx, std::shared_ptr<InverterAbstract> inv, ChannelType_t type, ChannelNum_t channel, FieldId_t fieldId, const char* metricName, const char* channelName = NULL);

void addPanelInfo(AsyncResponseStream* stream, String& serial, uint8_t idx, std::shared_ptr<InverterAbstract> inv, ChannelType_t type, ChannelNum_t channel);

AsyncWebServer* _server;

enum {
METRIC_TYPE_NONE = 0,
METRIC_TYPE_GAUGE,
METRIC_TYPE_COUNTER,
enum MetricType_t {
NONE = 0,
GAUGE,
COUNTER,
};
const char* _metricTypes[3] = { 0, "gauge", "counter" };

std::map<FieldId_t, uint8_t> _fieldMetricAssignment {
{ FLD_UDC, METRIC_TYPE_GAUGE },
{ FLD_IDC, METRIC_TYPE_GAUGE },
{ FLD_PDC, METRIC_TYPE_GAUGE },
{ FLD_YD, METRIC_TYPE_COUNTER },
{ FLD_YT, METRIC_TYPE_COUNTER },
{ FLD_UAC, METRIC_TYPE_GAUGE },
{ FLD_IAC, METRIC_TYPE_GAUGE },
{ FLD_PAC, METRIC_TYPE_GAUGE },
{ FLD_F, METRIC_TYPE_GAUGE },
{ FLD_T, METRIC_TYPE_GAUGE },
{ FLD_PF, METRIC_TYPE_GAUGE },
{ FLD_EFF, METRIC_TYPE_GAUGE },
{ FLD_IRR, METRIC_TYPE_GAUGE },
{ FLD_Q, METRIC_TYPE_GAUGE }
struct publish_type_t {
FieldId_t field;
MetricType_t type;
};

const publish_type_t _publishFields[14] = {
{ FLD_PAC, MetricType_t::GAUGE },
{ FLD_UAC, MetricType_t::GAUGE },
{ FLD_IAC, MetricType_t::GAUGE },
{ FLD_PDC, MetricType_t::GAUGE },
{ FLD_UDC, MetricType_t::GAUGE },
{ FLD_IDC, MetricType_t::GAUGE },
{ FLD_YD, MetricType_t::COUNTER },
{ FLD_YT, MetricType_t::COUNTER },
{ FLD_F, MetricType_t::GAUGE },
{ FLD_T, MetricType_t::GAUGE },
{ FLD_PF, MetricType_t::GAUGE },
{ FLD_Q, MetricType_t::GAUGE },
{ FLD_EFF, MetricType_t::GAUGE },
{ FLD_IRR, MetricType_t::GAUGE },
};
};
18 changes: 15 additions & 3 deletions lib/Hoymiles/src/Hoymiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,21 @@ void HoymilesClass::loop()
}

// Fetch dev info (but first fetch stats)
if (iv->Statistics()->getLastUpdate() > 0 && (iv->DevInfo()->getLastUpdateAll() == 0 || iv->DevInfo()->getLastUpdateSimple() == 0)) {
_messageOutput->println("Request device info");
iv->sendDevInfoRequest();
if (iv->Statistics()->getLastUpdate() > 0) {
bool invalidDevInfo = !iv->DevInfo()->containsValidData()
&& iv->DevInfo()->getLastUpdateAll() > 0
&& iv->DevInfo()->getLastUpdateSimple() > 0;

if (invalidDevInfo) {
_messageOutput->println("DevInfo: No Valid Data");
}

if ((iv->DevInfo()->getLastUpdateAll() == 0)
|| (iv->DevInfo()->getLastUpdateSimple() == 0)
|| invalidDevInfo) {
_messageOutput->println("Request device info");
iv->sendDevInfoRequest();
}
}

if (++inverterPos >= getNumInverters()) {
Expand Down
2 changes: 1 addition & 1 deletion lib/Hoymiles/src/inverters/HMS_4CH.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ static const byteAssign_t byteAssignment[] = {
{ TYPE_AC, CH0, FLD_UAC, UNIT_V, 50, 2, 10, false, 1 },
{ TYPE_AC, CH0, FLD_IAC, UNIT_A, 58, 2, 100, false, 2 },
{ TYPE_AC, CH0, FLD_PAC, UNIT_W, 54, 2, 10, false, 1 },
{ TYPE_AC, CH0, FLD_Q, UNIT_VAR, 56, 2, 10, false, 1 },
{ TYPE_AC, CH0, FLD_Q, UNIT_VAR, 56, 2, 10, true, 1 },
{ TYPE_AC, CH0, FLD_F, UNIT_HZ, 52, 2, 100, false, 2 },
{ TYPE_AC, CH0, FLD_PF, UNIT_NONE, 60, 2, 1000, false, 3 },

Expand Down
10 changes: 10 additions & 0 deletions lib/Hoymiles/src/parser/DevInfoParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,16 @@ String DevInfoParser::getHwModelName()
return devInfo[idx].modelName;
}

bool DevInfoParser::containsValidData()
{
time_t t = getFwBuildDateTime();

struct tm info;
localtime_r(&t, &info);

return info.tm_year > (2016 - 1900);
}

uint8_t DevInfoParser::getDevIdx()
{
uint8_t ret = 0xff;
Expand Down
2 changes: 2 additions & 0 deletions lib/Hoymiles/src/parser/DevInfoParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ class DevInfoParser : public Parser {
uint16_t getMaxPower();
String getHwModelName();

bool containsValidData();

private:
time_t timegm(struct tm* tm);
uint8_t getDevIdx();
Expand Down
7 changes: 7 additions & 0 deletions lib/Hoymiles/src/parser/StatisticsParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,13 @@ float StatisticsParser::getChannelFieldValue(ChannelType_t type, ChannelNum_t ch
return 0;
}

String StatisticsParser::getChannelFieldValueString(ChannelType_t type, ChannelNum_t channel, FieldId_t fieldId)
{
return String(
getChannelFieldValue(type, channel, fieldId),
static_cast<unsigned int>(getChannelFieldDigits(type, channel, fieldId)));
}

bool StatisticsParser::hasChannelFieldValue(ChannelType_t type, ChannelNum_t channel, FieldId_t fieldId)
{
const byteAssign_t* pos = getAssignmentByChannelField(type, channel, fieldId);
Expand Down
1 change: 1 addition & 0 deletions lib/Hoymiles/src/parser/StatisticsParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ class StatisticsParser : public Parser {
fieldSettings_t* getSettingByChannelField(ChannelType_t type, ChannelNum_t channel, FieldId_t fieldId);

float getChannelFieldValue(ChannelType_t type, ChannelNum_t channel, FieldId_t fieldId);
String getChannelFieldValueString(ChannelType_t type, ChannelNum_t channel, FieldId_t fieldId);
bool hasChannelFieldValue(ChannelType_t type, ChannelNum_t channel, FieldId_t fieldId);
const char* getChannelFieldUnit(ChannelType_t type, ChannelNum_t channel, FieldId_t fieldId);
const char* getChannelFieldName(ChannelType_t type, ChannelNum_t channel, FieldId_t fieldId);
Expand Down
1 change: 1 addition & 0 deletions pio-scripts/auto_firmware_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

from dulwich import porcelain


def get_firmware_specifier_build_flag():
try:
build_version = porcelain.describe('.') # '.' refers to the repository root dir
Expand Down
17 changes: 15 additions & 2 deletions src/Display_Graphic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ void DisplayGraphicClass::init(DisplayType_t type, uint8_t data, uint8_t clk, ui
_display = constructor(reset, clk, data, cs);
_display->begin();
setContrast(DISPLAY_CONTRAST);
setStatus(true);
}
}

Expand Down Expand Up @@ -139,10 +140,11 @@ void DisplayGraphicClass::loop()
if ((millis() - _lastDisplayUpdate) > _period) {

_display->clearBuffer();
bool displayPowerSave = false;

//=====> Actual Production ==========
if (Datastore.getIsAtLeastOneReachable()) {
_display->setPowerSave(false);
displayPowerSave = false;
if (Datastore.getTotalAcPowerEnabled() > 999) {
snprintf(_fmtText, sizeof(_fmtText), i18n_current_power_kw[_display_language], (Datastore.getTotalAcPowerEnabled() / 1000));
} else {
Expand All @@ -158,7 +160,7 @@ void DisplayGraphicClass::loop()
printText(i18n_offline[_display_language], 0);
// check if it's time to enter power saving mode
if (millis() - _previousMillis >= (_interval * 2)) {
_display->setPowerSave(enablePowerSafe);
displayPowerSave = enablePowerSafe;
}
}
//<=======================
Expand All @@ -184,6 +186,12 @@ void DisplayGraphicClass::loop()

_mExtra++;
_lastDisplayUpdate = millis();

if (!_displayTurnedOn) {
displayPowerSave = true;
}

_display->setPowerSave(displayPowerSave);
}
}

Expand All @@ -195,4 +203,9 @@ void DisplayGraphicClass::setContrast(uint8_t contrast)
_display->setContrast(contrast * 2.55f);
}

void DisplayGraphicClass::setStatus(bool turnOn)
{
_displayTurnedOn = turnOn;
}

DisplayGraphicClass Display;
16 changes: 15 additions & 1 deletion src/Led_Single.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ void LedSingleClass::init()
{
_blinkTimeout.set(500);
_updateTimeout.set(LEDSINGLE_UPDATE_INTERVAL);
turnAllOn();

for (uint8_t i = 0; i < PINMAPPING_LED_COUNT; i++) {
auto& pin = PinMapping.get();
Expand All @@ -40,7 +41,7 @@ void LedSingleClass::loop()
return;
}

if (_updateTimeout.occured()) {
if (_updateTimeout.occured() && _allState == LedState_t::On) {
const CONFIG_T& config = Configuration.get();

// Update network status
Expand Down Expand Up @@ -68,6 +69,9 @@ void LedSingleClass::loop()
}

_updateTimeout.reset();
} else if (_updateTimeout.occured() && _allState == LedState_t::Off) {
_ledState[0] = LedState_t::Off;
_ledState[1] = LedState_t::Off;
}

for (uint8_t i = 0; i < PINMAPPING_LED_COUNT; i++) {
Expand All @@ -93,3 +97,13 @@ void LedSingleClass::loop()
}
}
}

void LedSingleClass::turnAllOff()
{
_allState = LedState_t::Off;
}

void LedSingleClass::turnAllOn()
{
_allState = LedState_t::On;
}
Loading

0 comments on commit d5308b1

Please sign in to comment.