forked from tbnobody/OpenDTU
-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3d55498
commit e23be05
Showing
10 changed files
with
107 additions
and
95 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// SPDX-License-Identifier: GPL-2.0-or-later | ||
#pragma once | ||
|
||
#include <Arduino.h> | ||
|
||
namespace SolarChargers { | ||
|
||
class Stats { | ||
public: | ||
void mqttLoop(); | ||
|
||
// the interval at which all data will be re-published, even | ||
// if they did not change. used to calculate Home Assistent expiration. | ||
virtual uint32_t getMqttFullPublishIntervalMs() const; | ||
|
||
protected: | ||
virtual void mqttPublish() const; | ||
|
||
private: | ||
uint32_t _lastMqttPublish = 0; | ||
}; | ||
|
||
} // namespace SolarChargers |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// SPDX-License-Identifier: GPL-2.0-or-later | ||
#pragma once | ||
|
||
#include <solarcharger/Stats.h> | ||
#include <VeDirectMpptController.h> | ||
#include <map> | ||
|
||
namespace SolarChargers::Victron { | ||
|
||
class Stats : public ::SolarChargers::Stats { | ||
public: | ||
void mqttPublish() const final; | ||
|
||
private: | ||
mutable std::map<std::string, VeDirectMpptController::data_t> _kvFrames; | ||
|
||
// point of time in millis() when updated values will be published | ||
mutable uint32_t _nextPublishUpdatesOnly = 0; | ||
|
||
// point of time in millis() when all values will be published | ||
mutable uint32_t _nextPublishFull = 1; | ||
|
||
mutable bool _PublishFull; | ||
|
||
void publish_mppt_data(const VeDirectMpptController::data_t &mpptData, | ||
const VeDirectMpptController::data_t &frame) const; | ||
}; | ||
|
||
} // namespace SolarChargers::Victron |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// SPDX-License-Identifier: GPL-2.0-or-later | ||
#include <solarcharger/Stats.h> | ||
#include <Configuration.h> | ||
#include <MqttSettings.h> | ||
|
||
namespace SolarChargers { | ||
|
||
void Stats::mqttLoop() | ||
{ | ||
auto& config = Configuration.get(); | ||
|
||
if (!MqttSettings.getConnected() | ||
|| (millis() - _lastMqttPublish) < (config.Mqtt.PublishInterval * 1000)) { | ||
return; | ||
} | ||
|
||
mqttPublish(); | ||
|
||
_lastMqttPublish = millis(); | ||
} | ||
|
||
uint32_t Stats::getMqttFullPublishIntervalMs() const | ||
{ | ||
auto& config = Configuration.get(); | ||
|
||
// this is the default interval, see mqttLoop(). mqttPublish() | ||
// implementations in derived classes may choose to publish some values | ||
// with a lower frequency and hence implement this method with a different | ||
// return value. | ||
return config.Mqtt.PublishInterval * 1000; | ||
} | ||
|
||
} // namespace SolarChargers |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters