This commit is contained in:
CaCO3
2022-10-27 10:03:05 +02:00
parent 8f66fcf2a6
commit ca45d0a278
3 changed files with 21 additions and 10 deletions

View File

@@ -15,6 +15,9 @@
static const char *TAG = "class_flow_MQTT";
extern ClassFlowControll tfliteflow;
void ClassFlowMQTT::SetInitialParameter(void)
{
uri = "";
@@ -37,6 +40,7 @@ void ClassFlowMQTT::SetInitialParameter(void)
previousElement = NULL;
ListFlowControll = NULL;
disabled = false;
keepAlive = 25*60;
}
ClassFlowMQTT::ClassFlowMQTT()
@@ -51,16 +55,20 @@ ClassFlowMQTT::ClassFlowMQTT(std::vector<ClassFlow*>* lfc)
ListFlowControll = lfc;
for (int i = 0; i < ListFlowControll->size(); ++i)
{
// ESP_LOGW(TAG, "LCF: %s", ((*ListFlowControll)[i])->name().c_str());
if (((*ListFlowControll)[i])->name().compare("ClassFlowPostProcessing") == 0)
{
flowpostprocessing = (ClassFlowPostProcessing*) (*ListFlowControll)[i];
}
if (((*ListFlowControll)[i])->name().compare("ClassFlowControll") == 0)
// TODO this does not work since ClassFlowControll is not in the list!
/* if (((*ListFlowControll)[i])->name().compare("ClassFlowControll") == 0)
{
ClassFlowControll *cfc = (ClassFlowControll*) (*ListFlowControll)[i];
keepAlive = cfc->getAutoInterval()* 2.5; // Allow at least than 2 failed rounds before we are threated as disconnected
}
this->keepAlive = cfc->getAutoInterval()* 2.5; // Allow at least than 2 failed rounds before we are threated as disconnected
ESP_LOGW(TAG, "KEEPALIVE: %d", this->keepAlive);
}*/
}
}
@@ -130,9 +138,8 @@ bool ClassFlowMQTT::ReadParameter(FILE* pfile, string& aktparamgraph)
}
}
MQTT_Configure(uri, clientname, user, password, maintopic + "/connection", keepAlive);
ESP_LOGD(TAG, "MQTT maintopic: %s", maintopic.c_str());
ESP_LOGW(TAG, "KEEPALIVE: %d", keepAlive);
MQTT_Configure(uri, clientname, user, password, maintopic, "/connection", keepAlive);
if (!MQTT_Init()) {
if (!MQTT_Init()) { // Retry

View File

@@ -115,15 +115,16 @@ static void mqtt_event_handler(void *handler_args, esp_event_base_t base, int32_
}
void MQTT_Configure(std::string _mqttURI, std::string _clientid, std::string _user, std::string _password, std::string _lwt, int _keepalive){
void MQTT_Configure(std::string _mqttURI, std::string _clientid, std::string _user, std::string _password, std::string _maintopic, std::string _lwt, int _keepalive){
#ifdef __HIDE_PASSWORD
LogFile.WriteToFile(ESP_LOG_INFO, "MQTT Configuration: uri: " + _mqttURI + ", clientname: " + _clientid +
", user: " + _user + ", password: XXXXXXXX, last-will-topic: " + _lwt + ", timeout: " + std::to_string(_keepalive));
", user: " + _user + ", password: XXXXXXXX, last-will-topic: " + _maintopic + _lwt + ", keepAlive: " + std::to_string(_keepalive));
#else
LogFile.WriteToFile(ESP_LOG_INFO, "MQTT Configuration: uri: " + _mqttURI + ", clientname: " + _clientid +
", user: " + _user + ", password: " + _password + ", last-will-topic: " + _lwt + ", timeout: " + std::to_string(_keepalive));
", user: " + _user + ", password: " + _password + ", last-will-topic: " + _maintopic + _lwt + ", keepAlive: " + std::to_string(_keepalive));
#endif
uri = _mqttURI;
client_id = _clientid;
lwt_topic = _lwt;
@@ -133,6 +134,9 @@ void MQTT_Configure(std::string _mqttURI, std::string _clientid, std::string _us
user = _user;
password = _password;
}
LogFile.WriteToFile(ESP_LOG_INFO, "MQTT maintopic: %s", _maintopic.c_str());
}
bool MQTT_Init() {

View File

@@ -5,7 +5,7 @@
#include <map>
#include <functional>
void MQTT_Configure(std::string _mqttURI, std::string _clientid, std::string _user, std::string _password, std::string _lwt, int _keepalive);
void MQTT_Configure(std::string _mqttURI, std::string _clientid, std::string _user, std::string _password, std::string _maintopic, std::string _lwt, int _keepalive);
bool MQTT_Init();
void MQTTdestroy_client();