mirror of
https://github.com/jomjol/AI-on-the-edge-device.git
synced 2025-12-06 19:46:54 +03:00
Quick Fix for MQTT Init Problem
This commit is contained in:
@@ -189,6 +189,15 @@ string ClassFlowMQTT::GetMQTTMainTopic()
|
|||||||
|
|
||||||
bool ClassFlowMQTT::Start(float AutoIntervall) {
|
bool ClassFlowMQTT::Start(float AutoIntervall) {
|
||||||
|
|
||||||
|
// printf("URI: %s, MAINTOPIC: %s", uri.c_str(), maintopic.c_str());
|
||||||
|
|
||||||
|
if ((uri.length() == 0) || (maintopic.length() == 0))
|
||||||
|
{
|
||||||
|
LogFile.WriteToFile(ESP_LOG_INFO, TAG, "MQTT not started because URI or Maintopic is not set. MQTT will be disabled.");
|
||||||
|
MQTTdisable();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
roundInterval = AutoIntervall; // Minutes
|
roundInterval = AutoIntervall; // Minutes
|
||||||
keepAlive = roundInterval * 60 * 2.5; // Seconds, make sure it is greater thatn 2 rounds!
|
keepAlive = roundInterval * 60 * 2.5; // Seconds, make sure it is greater thatn 2 rounds!
|
||||||
|
|
||||||
|
|||||||
@@ -18,6 +18,8 @@ std::map<std::string, std::function<bool(std::string, char*, int)>>* subscribeFu
|
|||||||
|
|
||||||
int failedOnRound = -1;
|
int failedOnRound = -1;
|
||||||
|
|
||||||
|
bool MQTT_Enabled = true;
|
||||||
|
|
||||||
esp_mqtt_event_id_t esp_mmqtt_ID = MQTT_EVENT_ANY;
|
esp_mqtt_event_id_t esp_mmqtt_ID = MQTT_EVENT_ANY;
|
||||||
// ESP_EVENT_ANY_ID
|
// ESP_EVENT_ANY_ID
|
||||||
|
|
||||||
@@ -29,6 +31,11 @@ int keepalive, SetRetainFlag;
|
|||||||
void (*callbackOnConnected)(std::string, int) = NULL;
|
void (*callbackOnConnected)(std::string, int) = NULL;
|
||||||
|
|
||||||
|
|
||||||
|
void MQTTdisable()
|
||||||
|
{
|
||||||
|
MQTT_Enabled = false;
|
||||||
|
}
|
||||||
|
|
||||||
bool MQTTPublish(std::string _key, std::string _content, int retained_flag) {
|
bool MQTTPublish(std::string _key, std::string _content, int retained_flag) {
|
||||||
int msg_id;
|
int msg_id;
|
||||||
std::string zw;
|
std::string zw;
|
||||||
@@ -163,6 +170,16 @@ void MQTT_Configure(std::string _mqttURI, std::string _clientid, std::string _us
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool MQTT_Init() {
|
bool MQTT_Init() {
|
||||||
|
|
||||||
|
if (MQTT_Enabled == false)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if ((client_id.length() == 0) || (lwt_topic.length() == 0))
|
||||||
|
{
|
||||||
|
LogFile.WriteToFile(ESP_LOG_ERROR, TAG, std::string("Init with no Client_ID or Topic. Abort Init!"));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
esp_err_t ret;
|
esp_err_t ret;
|
||||||
LogFile.WriteToFile(ESP_LOG_INFO, TAG, std::string("Init"));
|
LogFile.WriteToFile(ESP_LOG_INFO, TAG, std::string("Init"));
|
||||||
|
|
||||||
|
|||||||
@@ -21,4 +21,6 @@ void MQTTregisterSubscribeFunction(std::string topic, std::function<bool(std::st
|
|||||||
void MQTTdestroySubscribeFunction();
|
void MQTTdestroySubscribeFunction();
|
||||||
void MQTTconnected();
|
void MQTTconnected();
|
||||||
|
|
||||||
|
void MQTTdisable();
|
||||||
|
|
||||||
#endif //INTERFACE_MQTT_H
|
#endif //INTERFACE_MQTT_H
|
||||||
@@ -1,2 +1,3 @@
|
|||||||
manifest_hash: 45994dbfed009907994c31f6d279c5861a1eacbf219ce8b58e74e39b3393816a
|
manifest_hash: 4e37bb0f9273c4de05f38688720fe32aa6e5b892452694a4f7a2ca1659f02cf6
|
||||||
|
target: esp32
|
||||||
version: 1.0.0
|
version: 1.0.0
|
||||||
|
|||||||
Reference in New Issue
Block a user