mirror of
https://github.com/letscontrolit/ESPEasy.git
synced 2026-07-28 04:07:47 +00:00
[MQTT-TLS] Improve stability of MQTT connection while serving JSON pages
This commit is contained in:
@@ -297,6 +297,18 @@ void WiFiClientSecure_light::flush(void) {
|
||||
#endif
|
||||
|
||||
#ifdef ESP32
|
||||
|
||||
int WiFiClientSecure_light::connect(IPAddress ip, uint16_t port)
|
||||
{
|
||||
return connect(ip, port, _timeout);
|
||||
}
|
||||
|
||||
int WiFiClientSecure_light::connect(const char* name, uint16_t port)
|
||||
{
|
||||
return connect(name, port, _timeout);
|
||||
}
|
||||
|
||||
|
||||
int WiFiClientSecure_light::connect(IPAddress ip, uint16_t port, int32_t timeout) {
|
||||
DEBUG_BSSL("connect(%s,%d)", ip.toString().c_str(), port);
|
||||
clearLastError();
|
||||
|
||||
@@ -45,8 +45,10 @@ class WiFiClientSecure_light : public NetworkClient {
|
||||
void allocateBuffers(void);
|
||||
|
||||
#ifdef ESP32 // the method to override in ESP32 has timeout argument default #define WIFI_CLIENT_DEF_CONN_TIMEOUT_MS (3000)
|
||||
int connect(IPAddress ip, uint16_t port, int32_t timeout = 3000) override;
|
||||
int connect(const char* name, uint16_t port, int32_t timeout = 3000) override;
|
||||
int connect(IPAddress ip, uint16_t port) override;
|
||||
int connect(const char* name, uint16_t port) override;
|
||||
int connect(IPAddress ip, uint16_t port, int32_t timeout);
|
||||
int connect(const char* name, uint16_t port, int32_t timeout);
|
||||
#else
|
||||
int connect(IPAddress ip, uint16_t port) override;
|
||||
int connect(const char* name, uint16_t port) override;
|
||||
|
||||
@@ -458,6 +458,7 @@ bool PubSubClient::loop_read() {
|
||||
}
|
||||
|
||||
boolean PubSubClient::loop() {
|
||||
delay(0);
|
||||
loop_read();
|
||||
if (connected()) {
|
||||
unsigned long t = millis();
|
||||
|
||||
@@ -11,7 +11,7 @@ boolean printToWebJSON = false;
|
||||
|
||||
|
||||
|
||||
unsigned long timermqtt_interval = 250;
|
||||
unsigned long timermqtt_interval = 100;
|
||||
unsigned long lastSend = 0;
|
||||
unsigned long lastWeb = 0;
|
||||
|
||||
|
||||
@@ -254,6 +254,8 @@ bool MQTTConnect(controllerIndex_t controller_idx)
|
||||
mqtt.setTimeout(timeout); // in msec as it should be!
|
||||
# endif // ifdef MUSTFIX_CLIENT_TIMEOUT_IN_SECONDS
|
||||
MQTTclient.setClient(mqtt);
|
||||
MQTTclient.setKeepAlive(10);
|
||||
MQTTclient.setSocketTimeout(timeout);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -357,6 +359,9 @@ bool MQTTConnect(controllerIndex_t controller_idx)
|
||||
mqtt_tls->setBufferSizes(1024, 1024);
|
||||
# endif // ifdef ESP8266
|
||||
MQTTclient.setClient(*mqtt_tls);
|
||||
MQTTclient.setKeepAlive(10);
|
||||
MQTTclient.setSocketTimeout(timeout);
|
||||
|
||||
|
||||
if (mqttPort == 1883) {
|
||||
mqttPort = 8883;
|
||||
|
||||
@@ -459,7 +459,7 @@ void ESPEasy_setup()
|
||||
}
|
||||
#endif
|
||||
|
||||
timermqtt_interval = 250; // Interval for checking MQTT
|
||||
timermqtt_interval = 100; // Interval for checking MQTT
|
||||
timerAwakeFromDeepSleep = millis();
|
||||
CPluginInit();
|
||||
#ifndef BUILD_NO_RAM_TRACKER
|
||||
|
||||
@@ -365,10 +365,10 @@ void updateMQTTclient_connected() {
|
||||
if (!MQTTclient_connected) {
|
||||
// As suggested here: https://github.com/letscontrolit/ESPEasy/issues/1356
|
||||
if (timermqtt_interval < 30000) {
|
||||
timermqtt_interval += 5000;
|
||||
timermqtt_interval += 500;
|
||||
}
|
||||
} else {
|
||||
timermqtt_interval = 250;
|
||||
timermqtt_interval = 100;
|
||||
}
|
||||
Scheduler.setIntervalTimer(SchedulerIntervalTimer_e::TIMER_MQTT);
|
||||
scheduleNextMQTTdelayQueue();
|
||||
|
||||
Reference in New Issue
Block a user