mirror of
https://github.com/Laxilef/OTGateway.git
synced 2025-12-10 18:24:27 +05:00
refactor: improved work with opentherm on esp32
This commit is contained in:
@@ -7,7 +7,7 @@ public:
|
||||
typedef std::function<void(unsigned long, byte)> BeforeSendRequestCallback;
|
||||
typedef std::function<void(unsigned long, unsigned long, OpenThermResponseStatus, byte)> AfterSendRequestCallback;
|
||||
|
||||
CustomOpenTherm(int inPin = 4, int outPin = 5, bool isSlave = false) : OpenTherm(inPin, outPin, isSlave) {}
|
||||
CustomOpenTherm(int inPin = 4, int outPin = 5, bool isSlave = false, bool alwaysReceive = false) : OpenTherm(inPin, outPin, isSlave, alwaysReceive) {}
|
||||
~CustomOpenTherm() {}
|
||||
|
||||
CustomOpenTherm* setDelayCallback(DelayCallback callback = nullptr) {
|
||||
@@ -28,8 +28,8 @@ public:
|
||||
return this;
|
||||
}
|
||||
|
||||
unsigned long sendRequest(unsigned long request, byte attempts = 5, byte _attempt = 0) {
|
||||
_attempt++;
|
||||
unsigned long sendRequest(unsigned long request) override {
|
||||
this->sendRequestAttempt++;
|
||||
|
||||
while (!this->isReady()) {
|
||||
if (this->delayCallback) {
|
||||
@@ -40,15 +40,10 @@ public:
|
||||
}
|
||||
|
||||
if (this->beforeSendRequestCallback) {
|
||||
this->beforeSendRequestCallback(request, _attempt);
|
||||
this->beforeSendRequestCallback(request, this->sendRequestAttempt);
|
||||
}
|
||||
|
||||
unsigned long _response;
|
||||
OpenThermResponseStatus _responseStatus = OpenThermResponseStatus::NONE;
|
||||
if (!this->sendRequestAsync(request)) {
|
||||
_response = 0;
|
||||
|
||||
} else {
|
||||
if (this->sendRequestAsync(request)) {
|
||||
do {
|
||||
if (this->delayCallback) {
|
||||
this->delayCallback(150);
|
||||
@@ -56,42 +51,25 @@ public:
|
||||
|
||||
this->process();
|
||||
} while (this->status != OpenThermStatus::READY && this->status != OpenThermStatus::DELAY);
|
||||
|
||||
_response = this->getLastResponse();
|
||||
_responseStatus = this->getLastResponseStatus();
|
||||
}
|
||||
|
||||
if (this->afterSendRequestCallback) {
|
||||
this->afterSendRequestCallback(request, _response, _responseStatus, _attempt);
|
||||
this->afterSendRequestCallback(request, this->response, this->responseStatus, this->sendRequestAttempt);
|
||||
}
|
||||
|
||||
if (_responseStatus == OpenThermResponseStatus::SUCCESS || _responseStatus == OpenThermResponseStatus::INVALID || _attempt >= attempts) {
|
||||
return _response;
|
||||
if (this->responseStatus == OpenThermResponseStatus::SUCCESS || this->responseStatus == OpenThermResponseStatus::INVALID) {
|
||||
this->sendRequestAttempt = 0;
|
||||
return this->response;
|
||||
|
||||
} else if (this->sendRequestAttempt >= this->sendRequestMaxAttempts) {
|
||||
this->sendRequestAttempt = 0;
|
||||
return this->response;
|
||||
|
||||
} else {
|
||||
return this->sendRequest(request, attempts, _attempt);
|
||||
return this->sendRequest(request);
|
||||
}
|
||||
}
|
||||
|
||||
unsigned long setBoilerStatus(bool enableCentralHeating, bool enableHotWater, bool enableCooling, bool enableOutsideTemperatureCompensation, bool enableCentralHeating2, bool summerWinterMode, bool dhwBlocking, uint8_t lb = 0) {
|
||||
unsigned int data = enableCentralHeating
|
||||
| (enableHotWater << 1)
|
||||
| (enableCooling << 2)
|
||||
| (enableOutsideTemperatureCompensation << 3)
|
||||
| (enableCentralHeating2 << 4)
|
||||
| (summerWinterMode << 5)
|
||||
| (dhwBlocking << 6);
|
||||
|
||||
data <<= 8;
|
||||
data |= lb;
|
||||
|
||||
return this->sendRequest(buildRequest(
|
||||
OpenThermMessageType::READ_DATA,
|
||||
OpenThermMessageID::Status,
|
||||
data
|
||||
));
|
||||
}
|
||||
|
||||
bool sendBoilerReset() {
|
||||
unsigned int data = 1;
|
||||
data <<= 8;
|
||||
@@ -145,6 +123,8 @@ public:
|
||||
}
|
||||
|
||||
protected:
|
||||
const uint8_t sendRequestMaxAttempts = 5;
|
||||
uint8_t sendRequestAttempt = 0;
|
||||
DelayCallback delayCallback;
|
||||
BeforeSendRequestCallback beforeSendRequestCallback;
|
||||
AfterSendRequestCallback afterSendRequestCallback;
|
||||
|
||||
@@ -19,7 +19,7 @@ framework = arduino
|
||||
lib_deps =
|
||||
bblanchon/ArduinoJson@^7.3.0
|
||||
;ihormelnyk/OpenTherm Library@^1.1.5
|
||||
https://github.com/ihormelnyk/opentherm_library#master
|
||||
https://github.com/Laxilef/opentherm_library#esp32_timer
|
||||
arduino-libraries/ArduinoMqttClient@^0.1.8
|
||||
lennarthennigs/ESP Telnet@^2.2
|
||||
gyverlibs/FileData@^1.0.2
|
||||
|
||||
@@ -138,7 +138,12 @@ protected:
|
||||
return;
|
||||
|
||||
} else if (this->instance->status == OpenThermStatus::NOT_INITIALIZED) {
|
||||
this->instance->begin();
|
||||
if (!this->instance->begin()) {
|
||||
Log.swarningln(FPSTR(L_OT), F("Failed begin"));
|
||||
|
||||
this->delay(5000);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// RX LED GPIO setup
|
||||
@@ -212,6 +217,20 @@ protected:
|
||||
F("Failed receive boiler status: %s"),
|
||||
CustomOpenTherm::statusToString(this->instance->getLastResponseStatus())
|
||||
);
|
||||
|
||||
} else {
|
||||
vars.slave.heating.active = CustomOpenTherm::isCentralHeatingActive(response);
|
||||
vars.slave.dhw.active = settings.opentherm.options.dhwSupport ? CustomOpenTherm::isHotWaterActive(response) : false;
|
||||
vars.slave.flame = CustomOpenTherm::isFlameOn(response);
|
||||
vars.slave.cooling = CustomOpenTherm::isCoolingActive(response);
|
||||
vars.slave.fault.active = CustomOpenTherm::isFault(response);
|
||||
vars.slave.diag.active = CustomOpenTherm::isDiagnostic(response);
|
||||
|
||||
Log.snoticeln(
|
||||
FPSTR(L_OT), F("Received boiler status. Heating: %hhu; DHW: %hhu; flame: %hhu; cooling: %hhu; fault: %hhu; diag: %hhu"),
|
||||
vars.slave.heating.active, vars.slave.dhw.active,
|
||||
vars.slave.flame, vars.slave.cooling, vars.slave.fault.active, vars.slave.diag.active
|
||||
);
|
||||
}
|
||||
|
||||
// 5 request retries
|
||||
@@ -310,19 +329,6 @@ protected:
|
||||
Log.sinfoln(FPSTR(L_OT_DHW), vars.master.dhw.enabled ? F("Enabled") : F("Disabled"));
|
||||
}
|
||||
|
||||
vars.slave.heating.active = CustomOpenTherm::isCentralHeatingActive(response);
|
||||
vars.slave.dhw.active = settings.opentherm.options.dhwSupport ? CustomOpenTherm::isHotWaterActive(response) : false;
|
||||
vars.slave.flame = CustomOpenTherm::isFlameOn(response);
|
||||
vars.slave.cooling = CustomOpenTherm::isCoolingActive(response);
|
||||
vars.slave.fault.active = CustomOpenTherm::isFault(response);
|
||||
vars.slave.diag.active = CustomOpenTherm::isDiagnostic(response);
|
||||
|
||||
Log.snoticeln(
|
||||
FPSTR(L_OT), F("Received boiler status. Heating: %hhu; DHW: %hhu; flame: %hhu; cooling: %hhu; fault: %hhu; diag: %hhu"),
|
||||
vars.slave.heating.active, vars.slave.dhw.active,
|
||||
vars.slave.flame, vars.slave.cooling, vars.slave.fault.active, vars.slave.diag.active
|
||||
);
|
||||
|
||||
// These parameters will be updated every minute
|
||||
if (millis() - this->prevUpdateNonEssentialVars > 60000) {
|
||||
if (this->updateMinModulationLevel()) {
|
||||
|
||||
Reference in New Issue
Block a user