mirror of
https://gitlab.com/wirelos/sprocket-plugin-mqtt.git
synced 2025-12-17 23:06:39 +01:00
max tries
This commit is contained in:
@@ -70,10 +70,15 @@ void MqttPlugin::connect()
|
|||||||
}
|
}
|
||||||
subscribed = true;
|
subscribed = true;
|
||||||
}
|
}
|
||||||
|
connectTries = 0;
|
||||||
publish("mqtt/connect", clientName);
|
publish("mqtt/connect", clientName);
|
||||||
PRINT_MSG(Serial, "MQTT", "connected");
|
PRINT_MSG(Serial, "MQTT", "connected");
|
||||||
} else {
|
} else {
|
||||||
PRINT_MSG(Serial, "MQTT", "connect failed");
|
PRINT_MSG(Serial, "MQTT", "connect failed");
|
||||||
|
connectTries++;
|
||||||
|
if(connectTries == maxConnectTries){
|
||||||
|
connectTask.disable();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ using namespace std::placeholders;
|
|||||||
|
|
||||||
class MqttPlugin : public Plugin
|
class MqttPlugin : public Plugin
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
PubSubClient *client;
|
PubSubClient *client;
|
||||||
|
|
||||||
MqttPlugin(MqttConfig cfg, bool bindUp = true, bool bindDown = true);
|
MqttPlugin(MqttConfig cfg, bool bindUp = true, bool bindDown = true);
|
||||||
@@ -26,7 +26,7 @@ class MqttPlugin : public Plugin
|
|||||||
*/
|
*/
|
||||||
void activate(Scheduler *scheduler);
|
void activate(Scheduler *scheduler);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
WiFiClient wifiClient;
|
WiFiClient wifiClient;
|
||||||
Task connectTask;
|
Task connectTask;
|
||||||
Task processTask;
|
Task processTask;
|
||||||
@@ -37,9 +37,11 @@ class MqttPlugin : public Plugin
|
|||||||
int brokerPort;
|
int brokerPort;
|
||||||
String clientName;
|
String clientName;
|
||||||
String topicRoot;
|
String topicRoot;
|
||||||
|
int connectTries = 0;
|
||||||
|
int maxConnectTries = 5; // TODO add to config
|
||||||
|
|
||||||
void applyConfig(MqttConfig cfg);
|
void applyConfig(MqttConfig cfg);
|
||||||
void applyConfigFromFile(const char* fileName);
|
void applyConfigFromFile(const char *fileName);
|
||||||
void enableConnectTask(Scheduler *scheduler);
|
void enableConnectTask(Scheduler *scheduler);
|
||||||
void enableProcessTask(Scheduler *scheduler);
|
void enableProcessTask(Scheduler *scheduler);
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user