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.
Feature: add support for MQTT solar chargers
adds support to integrate solar charge controller output power, current, and voltage values from the MQTT broker, allowing the DPL to do solar-passthrough with any solar charge controller hardware as long as it publishes the relevant values to the MQTT broker.
- Loading branch information
1 parent
d7ff717
commit b914447
Showing
22 changed files
with
832 additions
and
114 deletions.
There are no files selected for viewing
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,50 @@ | ||
// SPDX-License-Identifier: GPL-2.0-or-later | ||
#pragma once | ||
|
||
#include <mutex> | ||
#include <memory> | ||
#include <TaskSchedulerDeclarations.h> | ||
#include <solarcharger/Provider.h> | ||
#include <solarcharger/mqtt/Stats.h> | ||
#include <VeDirectMpptController.h> | ||
#include <espMqttClient.h> | ||
|
||
namespace SolarChargers::Mqtt { | ||
|
||
class Provider : public ::SolarChargers::Provider { | ||
public: | ||
Provider() = default; | ||
~Provider() = default; | ||
|
||
bool init(bool verboseLogging) final; | ||
void deinit() final; | ||
void loop() final { return; } // this class is event-driven | ||
std::shared_ptr<::SolarChargers::Stats> getStats() const final { return _stats; } | ||
|
||
private: | ||
Provider(Provider const& other) = delete; | ||
Provider(Provider&& other) = delete; | ||
Provider& operator=(Provider const& other) = delete; | ||
Provider& operator=(Provider&& other) = delete; | ||
|
||
bool _verboseLogging = false; | ||
String _outputPowerTopic; | ||
String _outputVoltageTopic; | ||
String _outputCurrentTopic; | ||
std::vector<String> _subscribedTopics; | ||
std::shared_ptr<Stats> _stats = std::make_shared<Stats>(); | ||
|
||
void onMqttMessageOutputPower(espMqttClientTypes::MessageProperties const& properties, | ||
char const* topic, uint8_t const* payload, size_t len, size_t index, size_t total, | ||
char const* jsonPath) const; | ||
|
||
void onMqttMessageOutputVoltage(espMqttClientTypes::MessageProperties const& properties, | ||
char const* topic, uint8_t const* payload, size_t len, size_t index, size_t total, | ||
char const* jsonPath) const; | ||
|
||
void onMqttMessageOutputCurrent(espMqttClientTypes::MessageProperties const& properties, | ||
char const* topic, uint8_t const* payload, size_t len, size_t index, size_t total, | ||
char const* jsonPath) const; | ||
}; | ||
|
||
} // namespace SolarChargers::Mqtt |
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,56 @@ | ||
// SPDX-License-Identifier: GPL-2.0-or-later | ||
#pragma once | ||
|
||
#include <solarcharger/Stats.h> | ||
|
||
namespace SolarChargers::Mqtt { | ||
|
||
class Stats : public ::SolarChargers::Stats { | ||
friend class Provider; | ||
|
||
public: | ||
// the last time *any* data was updated | ||
uint32_t getAgeMillis() const final { return millis() - _lastUpdate; } | ||
|
||
std::optional<float> getOutputPowerWatts() const final; | ||
std::optional<float> getOutputVoltage() const final; | ||
std::optional<uint16_t> getPanelPowerWatts() const final { return std::nullopt; } | ||
std::optional<float> getYieldTotal() const final { return std::nullopt; } | ||
std::optional<float> getYieldDay() const final { return std::nullopt; } | ||
|
||
void getLiveViewData(JsonVariant& root, const boolean fullUpdate, const uint32_t lastPublish) const final; | ||
|
||
// no need to republish values received via mqtt | ||
void mqttPublish() const final {} | ||
|
||
// no need to republish values received via mqtt | ||
void mqttPublishSensors(const boolean forcePublish) const final {} | ||
|
||
protected: | ||
std::optional<float> getOutputCurrent() const; | ||
|
||
void setOutputPowerWatts(const float powerWatts) { | ||
_outputPowerWatts = powerWatts; | ||
_lastUpdateOutputPowerWatts = _lastUpdate = millis(); | ||
} | ||
|
||
void setOutputVoltage(const float voltage); | ||
|
||
void setOutputCurrent(const float current); | ||
|
||
private: | ||
uint32_t _lastUpdate = 0; | ||
|
||
float _outputPowerWatts = 0; | ||
uint32_t _lastUpdateOutputPowerWatts = 0; | ||
|
||
float _outputVoltage = 0; | ||
uint32_t _lastUpdateOutputVoltage = 0; | ||
|
||
float _outputCurrent = 0; | ||
uint32_t _lastUpdateOutputCurrent = 0; | ||
|
||
std::optional<float> getValueIfNotOutdated(const uint32_t lastUpdate, const float value) const; | ||
}; | ||
|
||
} // namespace SolarChargers::Mqtt |
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
Oops, something went wrong.