Skip to content

Commit

Permalink
Revert "Merge remote-tracking branch 'tbnobody/OpenDTU/master' into d…
Browse files Browse the repository at this point in the history
…evelopment"

This reverts commit eb1c2db, reversing
changes made to 0cb42a6.

merge of v23.9.11 broke the system
  • Loading branch information
helgeerbe committed Sep 12, 2023
1 parent a7ea15c commit 2eeb5f1
Show file tree
Hide file tree
Showing 66 changed files with 465 additions and 1,060 deletions.
22 changes: 9 additions & 13 deletions include/Configuration.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once

#include <cstdint>
#include <Arduino.h>

#define CONFIG_FILENAME "/config.json"
#define CONFIG_VERSION 0x00011900 // 0.1.24 // make sure to clean all after change
Expand Down Expand Up @@ -54,9 +54,6 @@ struct INVERTER_CONFIG_T {
bool Poll_Enable_Night;
bool Command_Enable;
bool Command_Enable_Night;
uint8_t ReachableThreshold;
bool ZeroRuntimeDataIfUnrechable;
bool ZeroYieldDayOnMidnight;
CHANNEL_CONFIG_T channel[INV_MAX_CHAN_COUNT];
};

Expand All @@ -75,18 +72,18 @@ struct POWERMETER_HTTP_PHASE_CONFIG_T {

struct CONFIG_T {
uint32_t Cfg_Version;
uint32_t Cfg_SaveCount;
uint Cfg_SaveCount;

char WiFi_Ssid[WIFI_MAX_SSID_STRLEN + 1];
char WiFi_Password[WIFI_MAX_PASSWORD_STRLEN + 1];
uint8_t WiFi_Ip[4];
uint8_t WiFi_Netmask[4];
uint8_t WiFi_Gateway[4];
uint8_t WiFi_Dns1[4];
uint8_t WiFi_Dns2[4];
byte WiFi_Ip[4];
byte WiFi_Netmask[4];
byte WiFi_Gateway[4];
byte WiFi_Dns1[4];
byte WiFi_Dns2[4];
bool WiFi_Dhcp;
char WiFi_Hostname[WIFI_MAX_HOSTNAME_STRLEN + 1];
uint32_t WiFi_ApTimeout;
uint WiFi_ApTimeout;

char Ntp_Server[NTP_MAX_SERVER_STRLEN + 1];
char Ntp_Timezone[NTP_MAX_TIMEZONE_STRLEN + 1];
Expand All @@ -98,7 +95,7 @@ struct CONFIG_T {
bool Mqtt_Enabled;
char Mqtt_Hostname[MQTT_MAX_HOSTNAME_STRLEN + 1];
bool Mqtt_VerboseLogging;
uint32_t Mqtt_Port;
uint Mqtt_Port;
char Mqtt_Username[MQTT_MAX_USERNAME_STRLEN + 1];
char Mqtt_Password[MQTT_MAX_PASSWORD_STRLEN + 1];
char Mqtt_Topic[MQTT_MAX_TOPIC_STRLEN + 1];
Expand All @@ -107,7 +104,6 @@ struct CONFIG_T {
char Mqtt_LwtValue_Online[MQTT_MAX_LWTVALUE_STRLEN + 1];
char Mqtt_LwtValue_Offline[MQTT_MAX_LWTVALUE_STRLEN + 1];
uint32_t Mqtt_PublishInterval;
bool Mqtt_CleanSession;

INVERTER_CONFIG_T Inverter[INV_MAX_COUNT];

Expand Down
16 changes: 8 additions & 8 deletions include/Datastore.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,16 @@ class DatastoreClass {
float getTotalDcIrradiation();

// Amount of relevant digits for yield total
uint32_t getTotalAcYieldTotalDigits();
unsigned int getTotalAcYieldTotalDigits();

// Amount of relevant digits for yield total
uint32_t getTotalAcYieldDayDigits();
unsigned int getTotalAcYieldDayDigits();

// Amount of relevant digits for AC power
uint32_t getTotalAcPowerDigits();
unsigned int getTotalAcPowerDigits();

// Amount of relevant digits for DC power
uint32_t getTotalDcPowerDigits();
unsigned int getTotalDcPowerDigits();

// True, if at least one inverter is reachable
bool getIsAtLeastOneReachable();
Expand Down Expand Up @@ -68,10 +68,10 @@ class DatastoreClass {
float _totalDcPowerIrradiation = 0;
float _totalDcIrradiationInstalled = 0;
float _totalDcIrradiation = 0;
uint32_t _totalAcYieldTotalDigits = 0;
uint32_t _totalAcYieldDayDigits = 0;
uint32_t _totalAcPowerDigits = 0;
uint32_t _totalDcPowerDigits = 0;
unsigned int _totalAcYieldTotalDigits = 0;
unsigned int _totalAcYieldDayDigits = 0;
unsigned int _totalAcPowerDigits = 0;
unsigned int _totalDcPowerDigits = 0;
bool _isAtLeastOneReachable = false;
bool _isAtLeastOneProducing = false;
bool _isAllEnabledProducing = false;
Expand Down
3 changes: 0 additions & 3 deletions include/MqttHandleInverter.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

#include "Configuration.h"
#include <Hoymiles.h>
#include <TimeoutHelper.h>
#include <espMqttClient.h>

class MqttHandleInverterClass {
Expand All @@ -20,8 +19,6 @@ class MqttHandleInverterClass {
uint32_t _lastPublishStats[INV_MAX_COUNT];
uint32_t _lastPublish;

TimeoutHelper _statsTimeout;

FieldId_t _publishFields[14] = {
FLD_UDC,
FLD_IDC,
Expand Down
8 changes: 4 additions & 4 deletions include/NetworkSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ class NetworkSettingsClass {
void NetworkEvent(WiFiEvent_t event);
bool adminEnabled = true;
bool forceDisconnection = false;
uint32_t adminTimeoutCounter = 0;
uint32_t adminTimeoutCounterMax = 0;
uint32_t connectTimeoutTimer = 0;
uint32_t connectRedoTimer = 0;
int adminTimeoutCounter = 0;
int adminTimeoutCounterMax = 0;
int connectTimeoutTimer = 0;
int connectRedoTimer = 0;
uint32_t lastTimerCall = 0;
const byte DNS_PORT = 53;
IPAddress apIp;
Expand Down
4 changes: 2 additions & 2 deletions include/SunPosition.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ class SunPositionClass {
SunSet _sun;
bool _isDayPeriod = true;
bool _isSunsetAvailable = true;
uint32_t _sunriseMinutes = 0;
uint32_t _sunsetMinutes = 0;
uint _sunriseMinutes = 0;
uint _sunsetMinutes = 0;

uint32_t _lastUpdate = 0;
bool _isValidInfo = false;
Expand Down
2 changes: 0 additions & 2 deletions include/WebApi.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include "WebApi_dtu.h"
#include "WebApi_eventlog.h"
#include "WebApi_firmware.h"
#include "WebApi_gridprofile.h"
#include "WebApi_inverter.h"
#include "WebApi_limit.h"
#include "WebApi_maintenance.h"
Expand Down Expand Up @@ -53,7 +52,6 @@ class WebApiClass {
WebApiDtuClass _webApiDtu;
WebApiEventlogClass _webApiEventlog;
WebApiFirmwareClass _webApiFirmware;
WebApiGridProfileClass _webApiGridprofile;
WebApiInverterClass _webApiInverter;
WebApiLimitClass _webApiLimit;
WebApiMaintenanceClass _webApiMaintenance;
Expand Down
15 changes: 0 additions & 15 deletions include/WebApi_gridprofile.h

This file was deleted.

2 changes: 0 additions & 2 deletions include/WebApi_ws_live.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,4 @@ class WebApiWsLiveClass {
uint32_t _lastInvUpdateCheck = 0;
uint32_t _lastWsCleanup = 0;
uint32_t _newestInverterTimestamp = 0;

std::mutex _mutex;
};
3 changes: 0 additions & 3 deletions include/defaults.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@
#define MQTT_LWT_ONLINE "online"
#define MQTT_LWT_OFFLINE "offline"
#define MQTT_PUBLISH_INTERVAL 5U
#define MQTT_CLEAN_SESSION true

#define DTU_SERIAL 0x99978563412U
#define DTU_POLL_INTERVAL 5U
Expand All @@ -96,8 +95,6 @@
#define DISPLAY_CONTRAST 60U
#define DISPLAY_LANGUAGE 0U

#define REACHABLE_THRESHOLD 2U

#define VEDIRECT_ENABLED false
#define VEDIRECT_VERBOSE_LOGGING false
#define VEDIRECT_UPDATESONLY true
Expand Down
119 changes: 52 additions & 67 deletions lib/Hoymiles/src/Hoymiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
* Copyright (C) 2022 Thomas Basler and others
*/
#include "Hoymiles.h"
#include "Utils.h"
#include "inverters/HMS_1CH.h"
#include "inverters/HMS_2CH.h"
#include "inverters/HMS_4CH.h"
Expand All @@ -13,10 +12,18 @@
#include "inverters/HM_4CH.h"
#include <Arduino.h>

#define HOY_SEMAPHORE_TAKE() \
do { \
} while (xSemaphoreTake(_xSemaphore, portMAX_DELAY) != pdPASS)
#define HOY_SEMAPHORE_GIVE() xSemaphoreGive(_xSemaphore)

HoymilesClass Hoymiles;

void HoymilesClass::init()
{
_xSemaphore = xSemaphoreCreateMutex();
HOY_SEMAPHORE_GIVE(); // release before first use

_pollInterval = 0;
_radioNrf.reset(new HoymilesRadio_NRF());
_radioCmt.reset(new HoymilesRadio_CMT());
Expand All @@ -34,7 +41,7 @@ void HoymilesClass::initCMT(int8_t pin_sdio, int8_t pin_clk, int8_t pin_cs, int8

void HoymilesClass::loop()
{
std::lock_guard<std::mutex> lock(_mutex);
HOY_SEMAPHORE_TAKE();
_radioNrf->loop();
_radioCmt->loop();

Expand All @@ -50,90 +57,67 @@ void HoymilesClass::loop()
}

if (iv != nullptr && iv->getRadio()->isInitialized() && iv->getRadio()->isQueueEmpty()) {
_messageOutput->print("Fetch inverter: ");
_messageOutput->println(iv->serial(), HEX);

if (iv->getEnablePolling() || iv->getEnableCommands()) {
_messageOutput->print("Fetch inverter: ");
_messageOutput->println(iv->serial(), HEX);
if (!iv->isReachable()) {
iv->sendChangeChannelRequest();
}

if (!iv->isReachable()) {
iv->sendChangeChannelRequest();
}
iv->sendStatsRequest();

iv->sendStatsRequest();
// Fetch event log
bool force = iv->EventLog()->getLastAlarmRequestSuccess() == CMD_NOK;
iv->sendAlarmLogRequest(force);

// Fetch event log
bool force = iv->EventLog()->getLastAlarmRequestSuccess() == CMD_NOK;
iv->sendAlarmLogRequest(force);
// Fetch limit
if ((iv->SystemConfigPara()->getLastLimitRequestSuccess() == CMD_NOK)
|| ((millis() - iv->SystemConfigPara()->getLastUpdateRequest() > HOY_SYSTEM_CONFIG_PARA_POLL_INTERVAL)
&& (millis() - iv->SystemConfigPara()->getLastUpdateCommand() > HOY_SYSTEM_CONFIG_PARA_POLL_MIN_DURATION))) {
_messageOutput->println("Request SystemConfigPara");
iv->sendSystemConfigParaRequest();
}

// Fetch limit
if (((millis() - iv->SystemConfigPara()->getLastUpdateRequest() > HOY_SYSTEM_CONFIG_PARA_POLL_INTERVAL)
&& (millis() - iv->SystemConfigPara()->getLastUpdateCommand() > HOY_SYSTEM_CONFIG_PARA_POLL_MIN_DURATION))) {
_messageOutput->println("Request SystemConfigPara");
iv->sendSystemConfigParaRequest();
}
// Set limit if required
if (iv->SystemConfigPara()->getLastLimitCommandSuccess() == CMD_NOK) {
_messageOutput->println("Resend ActivePowerControl");
iv->resendActivePowerControlRequest();
}

// Set limit if required
if (iv->SystemConfigPara()->getLastLimitCommandSuccess() == CMD_NOK) {
_messageOutput->println("Resend ActivePowerControl");
iv->resendActivePowerControlRequest();
}
// Set power status if required
if (iv->PowerCommand()->getLastPowerCommandSuccess() == CMD_NOK) {
_messageOutput->println("Resend PowerCommand");
iv->resendPowerControlRequest();
}

// Set power status if required
if (iv->PowerCommand()->getLastPowerCommandSuccess() == CMD_NOK) {
_messageOutput->println("Resend PowerCommand");
iv->resendPowerControlRequest();
}
// Fetch dev info (but first fetch stats)
if (iv->Statistics()->getLastUpdate() > 0) {
bool invalidDevInfo = !iv->DevInfo()->containsValidData()
&& iv->DevInfo()->getLastUpdateAll() > 0
&& iv->DevInfo()->getLastUpdateSimple() > 0;

// Fetch dev info (but first fetch stats)
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 (invalidDevInfo) {
_messageOutput->println("DevInfo: No Valid Data");
}

// Fetch grid profile
if (iv->Statistics()->getLastUpdate() > 0 && iv->GridProfile()->getLastUpdate() == 0) {
iv->sendGridOnProFileParaRequest();
if ((iv->DevInfo()->getLastUpdateAll() == 0)
|| (iv->DevInfo()->getLastUpdateSimple() == 0)
|| invalidDevInfo) {
_messageOutput->println("Request device info");
iv->sendDevInfoRequest();
}

_lastPoll = millis();
}

if (++inverterPos >= getNumInverters()) {
inverterPos = 0;
}
}

// Perform housekeeping of all inverters on day change
int8_t currentWeekDay = Utils::getWeekDay();
static int8_t lastWeekDay = -1;
if (lastWeekDay == -1) {
lastWeekDay = currentWeekDay;
} else {
if (currentWeekDay != lastWeekDay) {

for (auto& inv : _inverters) {
if (inv->getZeroYieldDayOnMidnight()) {
inv->Statistics()->zeroDailyData();
}
}

lastWeekDay = currentWeekDay;
}
_lastPoll = millis();
}
}
}

HOY_SEMAPHORE_GIVE();
}

std::shared_ptr<InverterAbstract> HoymilesClass::addInverter(const char* name, uint64_t serial)
Expand Down Expand Up @@ -211,8 +195,9 @@ void HoymilesClass::removeInverterBySerial(uint64_t serial)
{
for (uint8_t i = 0; i < _inverters.size(); i++) {
if (_inverters[i]->serial() == serial) {
std::lock_guard<std::mutex> lock(_mutex);
HOY_SEMAPHORE_TAKE();
_inverters.erase(_inverters.begin() + i);
HOY_SEMAPHORE_GIVE();
return;
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Hoymiles/src/Hoymiles.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class HoymilesClass {
std::unique_ptr<HoymilesRadio_NRF> _radioNrf;
std::unique_ptr<HoymilesRadio_CMT> _radioCmt;

std::mutex _mutex;
SemaphoreHandle_t _xSemaphore;

uint32_t _pollInterval = 0;
bool _verboseLogging = true;
Expand Down
Loading

0 comments on commit 2eeb5f1

Please sign in to comment.