mirror of
https://github.com/Laxilef/OTGateway.git
synced 2025-12-11 18:54:28 +05:00
fix exception due to mqtt client
This commit is contained in:
@@ -8,6 +8,16 @@ public:
|
|||||||
this->client = &client;
|
this->client = &client;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setYieldCallback(void(*yieldCallback)(void*)) {
|
||||||
|
this->yieldCallback = yieldCallback;
|
||||||
|
this->yieldArg = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setYieldCallback(void(*yieldCallback)(void*), void* arg) {
|
||||||
|
this->yieldCallback = yieldCallback;
|
||||||
|
this->yieldArg = arg;
|
||||||
|
}
|
||||||
|
|
||||||
void setBufferedClient() {
|
void setBufferedClient() {
|
||||||
this->bClient = nullptr;
|
this->bClient = nullptr;
|
||||||
}
|
}
|
||||||
@@ -68,7 +78,13 @@ public:
|
|||||||
} else {
|
} else {
|
||||||
serializeJson(doc, *client);
|
serializeJson(doc, *client);
|
||||||
}
|
}
|
||||||
return client->endPublish();
|
|
||||||
|
int pubResult = client->endPublish();
|
||||||
|
if (this->yieldCallback != nullptr) {
|
||||||
|
this->yieldCallback(yieldArg);
|
||||||
|
}
|
||||||
|
|
||||||
|
return pubResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool publish(const char* topic) {
|
bool publish(const char* topic) {
|
||||||
@@ -89,6 +105,8 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
void(*yieldCallback)(void*) = nullptr;
|
||||||
|
void* yieldArg = nullptr;
|
||||||
PubSubClient* client;
|
PubSubClient* client;
|
||||||
BufferingPrint* bClient = nullptr;
|
BufferingPrint* bClient = nullptr;
|
||||||
String prefix = "homeassistant";
|
String prefix = "homeassistant";
|
||||||
|
|||||||
@@ -43,6 +43,14 @@ protected:
|
|||||||
client.setCallback(std::bind(&MqttTask::__callback, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
|
client.setCallback(std::bind(&MqttTask::__callback, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
|
||||||
client.setBufferSize(1024);
|
client.setBufferSize(1024);
|
||||||
|
|
||||||
|
haHelper.setYieldCallback([](void* self) {
|
||||||
|
MqttTask* task = static_cast<MqttTask*>(self);
|
||||||
|
task->delay(10);
|
||||||
|
|
||||||
|
if (client.connected()) {
|
||||||
|
client.loop();
|
||||||
|
}
|
||||||
|
}, this);
|
||||||
haHelper.setBufferedClient(this->bClient);
|
haHelper.setBufferedClient(this->bClient);
|
||||||
haHelper.setDevicePrefix(settings.mqtt.prefix);
|
haHelper.setDevicePrefix(settings.mqtt.prefix);
|
||||||
haHelper.setDeviceVersion(PROJECT_VERSION);
|
haHelper.setDeviceVersion(PROJECT_VERSION);
|
||||||
@@ -64,7 +72,6 @@ protected:
|
|||||||
client.subscribe(getTopicPath("settings/set").c_str());
|
client.subscribe(getTopicPath("settings/set").c_str());
|
||||||
client.subscribe(getTopicPath("state/set").c_str());
|
client.subscribe(getTopicPath("state/set").c_str());
|
||||||
publishHaEntities();
|
publishHaEntities();
|
||||||
publishNonStaticHaEntities(true);
|
|
||||||
|
|
||||||
firstFailConnect = 0;
|
firstFailConnect = 0;
|
||||||
lastReconnectAttempt = 0;
|
lastReconnectAttempt = 0;
|
||||||
@@ -85,6 +92,7 @@ protected:
|
|||||||
|
|
||||||
lastReconnectAttempt = millis();
|
lastReconnectAttempt = millis();
|
||||||
}
|
}
|
||||||
|
delay(100);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -399,13 +407,11 @@ protected:
|
|||||||
haHelper.publishNumberOutdoorSensorOffset(false);
|
haHelper.publishNumberOutdoorSensorOffset(false);
|
||||||
haHelper.publishNumberIndoorSensorOffset(false);
|
haHelper.publishNumberIndoorSensorOffset(false);
|
||||||
haHelper.publishSwitchDebug(false);
|
haHelper.publishSwitchDebug(false);
|
||||||
yield();
|
|
||||||
|
|
||||||
// emergency
|
// emergency
|
||||||
haHelper.publishSwitchEmergency();
|
haHelper.publishSwitchEmergency();
|
||||||
haHelper.publishNumberEmergencyTarget();
|
haHelper.publishNumberEmergencyTarget();
|
||||||
haHelper.publishSwitchEmergencyUseEquitherm();
|
haHelper.publishSwitchEmergencyUseEquitherm();
|
||||||
yield();
|
|
||||||
|
|
||||||
// heating
|
// heating
|
||||||
haHelper.publishSwitchHeating(false);
|
haHelper.publishSwitchHeating(false);
|
||||||
@@ -413,12 +419,10 @@ protected:
|
|||||||
haHelper.publishNumberHeatingHysteresis();
|
haHelper.publishNumberHeatingHysteresis();
|
||||||
haHelper.publishSensorHeatingSetpoint(false);
|
haHelper.publishSensorHeatingSetpoint(false);
|
||||||
haHelper.publishSensorCurrentHeatingMinTemp(false);
|
haHelper.publishSensorCurrentHeatingMinTemp(false);
|
||||||
yield();
|
|
||||||
haHelper.publishSensorCurrentHeatingMaxTemp(false);
|
haHelper.publishSensorCurrentHeatingMaxTemp(false);
|
||||||
haHelper.publishNumberHeatingMinTemp(false);
|
haHelper.publishNumberHeatingMinTemp(false);
|
||||||
haHelper.publishNumberHeatingMaxTemp(false);
|
haHelper.publishNumberHeatingMaxTemp(false);
|
||||||
haHelper.publishNumberHeatingMaxModulation(false);
|
haHelper.publishNumberHeatingMaxModulation(false);
|
||||||
yield();
|
|
||||||
|
|
||||||
// pid
|
// pid
|
||||||
haHelper.publishSwitchPID();
|
haHelper.publishSwitchPID();
|
||||||
@@ -427,19 +431,16 @@ protected:
|
|||||||
haHelper.publishNumberPIDFactorD();
|
haHelper.publishNumberPIDFactorD();
|
||||||
haHelper.publishNumberPIDMinTemp(false);
|
haHelper.publishNumberPIDMinTemp(false);
|
||||||
haHelper.publishNumberPIDMaxTemp(false);
|
haHelper.publishNumberPIDMaxTemp(false);
|
||||||
yield();
|
|
||||||
|
|
||||||
// equitherm
|
// equitherm
|
||||||
haHelper.publishSwitchEquitherm();
|
haHelper.publishSwitchEquitherm();
|
||||||
haHelper.publishNumberEquithermFactorN();
|
haHelper.publishNumberEquithermFactorN();
|
||||||
haHelper.publishNumberEquithermFactorK();
|
haHelper.publishNumberEquithermFactorK();
|
||||||
haHelper.publishNumberEquithermFactorT();
|
haHelper.publishNumberEquithermFactorT();
|
||||||
yield();
|
|
||||||
|
|
||||||
// tuning
|
// tuning
|
||||||
haHelper.publishSwitchTuning();
|
haHelper.publishSwitchTuning();
|
||||||
haHelper.publishSelectTuningRegulator();
|
haHelper.publishSelectTuningRegulator();
|
||||||
yield();
|
|
||||||
|
|
||||||
// states
|
// states
|
||||||
haHelper.publishBinSensorStatus();
|
haHelper.publishBinSensorStatus();
|
||||||
@@ -448,7 +449,6 @@ protected:
|
|||||||
haHelper.publishBinSensorFlame();
|
haHelper.publishBinSensorFlame();
|
||||||
haHelper.publishBinSensorFault();
|
haHelper.publishBinSensorFault();
|
||||||
haHelper.publishBinSensorDiagnostic();
|
haHelper.publishBinSensorDiagnostic();
|
||||||
yield();
|
|
||||||
|
|
||||||
// sensors
|
// sensors
|
||||||
haHelper.publishSensorModulation(false);
|
haHelper.publishSensorModulation(false);
|
||||||
@@ -456,12 +456,10 @@ protected:
|
|||||||
haHelper.publishSensorFaultCode();
|
haHelper.publishSensorFaultCode();
|
||||||
haHelper.publishSensorRssi(false);
|
haHelper.publishSensorRssi(false);
|
||||||
haHelper.publishSensorUptime(false);
|
haHelper.publishSensorUptime(false);
|
||||||
yield();
|
|
||||||
|
|
||||||
// temperatures
|
// temperatures
|
||||||
haHelper.publishNumberIndoorTemp();
|
haHelper.publishNumberIndoorTemp();
|
||||||
haHelper.publishSensorHeatingTemp();
|
haHelper.publishSensorHeatingTemp();
|
||||||
yield();
|
|
||||||
|
|
||||||
// buttons
|
// buttons
|
||||||
haHelper.publishButtonRestart(false);
|
haHelper.publishButtonRestart(false);
|
||||||
@@ -507,7 +505,6 @@ protected:
|
|||||||
}
|
}
|
||||||
|
|
||||||
published = true;
|
published = true;
|
||||||
yield();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (force || _heatingMinTemp != heatingMinTemp || _heatingMaxTemp != heatingMaxTemp) {
|
if (force || _heatingMinTemp != heatingMinTemp || _heatingMaxTemp != heatingMaxTemp) {
|
||||||
@@ -523,14 +520,12 @@ protected:
|
|||||||
haHelper.publishClimateHeating(heatingMinTemp, heatingMaxTemp, isStupidMode ? HaHelper::TEMP_SOURCE_HEATING : HaHelper::TEMP_SOURCE_INDOOR);
|
haHelper.publishClimateHeating(heatingMinTemp, heatingMaxTemp, isStupidMode ? HaHelper::TEMP_SOURCE_HEATING : HaHelper::TEMP_SOURCE_INDOOR);
|
||||||
|
|
||||||
published = true;
|
published = true;
|
||||||
yield();
|
|
||||||
|
|
||||||
} else if (_isStupidMode != isStupidMode) {
|
} else if (_isStupidMode != isStupidMode) {
|
||||||
_isStupidMode = isStupidMode;
|
_isStupidMode = isStupidMode;
|
||||||
haHelper.publishClimateHeating(heatingMinTemp, heatingMaxTemp, isStupidMode ? HaHelper::TEMP_SOURCE_HEATING : HaHelper::TEMP_SOURCE_INDOOR);
|
haHelper.publishClimateHeating(heatingMinTemp, heatingMaxTemp, isStupidMode ? HaHelper::TEMP_SOURCE_HEATING : HaHelper::TEMP_SOURCE_INDOOR);
|
||||||
|
|
||||||
published = true;
|
published = true;
|
||||||
yield();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_dhwPresent && (force || _dhwMinTemp != settings.dhw.minTemp || _dhwMaxTemp != settings.dhw.maxTemp)) {
|
if (_dhwPresent && (force || _dhwMinTemp != settings.dhw.minTemp || _dhwMaxTemp != settings.dhw.maxTemp)) {
|
||||||
@@ -541,7 +536,6 @@ protected:
|
|||||||
haHelper.publishClimateDhw(settings.dhw.minTemp, settings.dhw.maxTemp);
|
haHelper.publishClimateDhw(settings.dhw.minTemp, settings.dhw.maxTemp);
|
||||||
|
|
||||||
published = true;
|
published = true;
|
||||||
yield();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (force || _editableOutdoorTemp != editableOutdoorTemp) {
|
if (force || _editableOutdoorTemp != editableOutdoorTemp) {
|
||||||
@@ -556,7 +550,6 @@ protected:
|
|||||||
}
|
}
|
||||||
|
|
||||||
published = true;
|
published = true;
|
||||||
yield();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (force || _editableIndoorTemp != editableIndoorTemp) {
|
if (force || _editableIndoorTemp != editableIndoorTemp) {
|
||||||
|
|||||||
Reference in New Issue
Block a user