Skip to content

Commit c326e38

Browse files
mobrembskiMichał Obrembski
authored and
Michał Obrembski
committed
Add MY_MQTT_ETH_CLIENT_CONNECTION_TIMEOUT to config
MY_MQTT_ETH_CLIENT_CONNECTION_TIMEOUT is useful for adjusting default MQTT TCP/IP connection timeout by library user.
1 parent a090351 commit c326e38

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

MyConfig.h

+16
Original file line numberDiff line numberDiff line change
@@ -1562,6 +1562,21 @@
15621562
#ifndef MY_MQTT_ETH_INIT_DELAY
15631563
#define MY_MQTT_ETH_INIT_DELAY 1000
15641564
#endif
1565+
/**
1566+
* @def MY_MQTT_ETH_CLIENT_CONNECTION_TIMEOUT
1567+
* @brief Set a MQTT broker socket connection timeout time.
1568+
*
1569+
* This define is useful if you want to change default MQTT TCP/IP broker
1570+
* connection timeout. By default, it is 1000ms.
1571+
*
1572+
* Note that this is not supported in ESP8266 and ESP32 platforms, sorry.
1573+
*
1574+
* Example: @code #define MY_MQTT_ETH_CLIENT_CONNECTION_TIMEOUT 1000 @endcode
1575+
*/
1576+
#ifndef MY_MQTT_ETH_CLIENT_CONNECTION_TIMEOUT
1577+
#define MY_MQTT_ETH_CLIENT_CONNECTION_TIMEOUT 1000
1578+
#endif
1579+
15651580
/**
15661581
* @def MY_IP_ADDRESS
15671582
* @brief Static ip address of gateway. If not defined, DHCP will be used.
@@ -2335,6 +2350,7 @@
23352350
#define MY_MQTT_CLIENT_CERT
23362351
#define MY_MQTT_CLIENT_KEY
23372352
#define MY_MQTT_ETH_INIT_DELAY
2353+
#define MY_MQTT_ETH_CLIENT_CONNECTION_TIMEOUT
23382354
#define MY_SIGNAL_REPORT_ENABLED
23392355
// general
23402356
#define MY_WITH_LEDS_BLINKING_INVERSE

core/MyGatewayTransportMQTTClient.cpp

+8-1
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,11 @@ bool reconnectMQTT(void)
159159

160160
return true;
161161
}
162+
#if defined(MY_GATEWAY_ESP8266) || defined(MY_GATEWAY_ESP32)
162163
delay(1000);
164+
#else
165+
delay(MY_MQTT_ETH_CLIENT_CONNECTION_TIMEOUT);
166+
#endif
163167
GATEWAY_DEBUG(PSTR("!GWT:RMQ:FAIL\n"));
164168
return false;
165169
}
@@ -247,7 +251,10 @@ bool gatewayTransportInit(void)
247251
#else
248252
_MQTT_client.setServer(MY_CONTROLLER_URL_ADDRESS, MY_PORT);
249253
#endif /* End of MY_CONTROLLER_IP_ADDRESS */
250-
254+
// ESP platform doesn't support connection timeout
255+
#if !defined(MY_GATEWAY_ESP8266) && !defined(MY_GATEWAY_ESP32)
256+
_MQTT_ethClient.setConnectionTimeout(MY_MQTT_ETH_CLIENT_CONNECTION_TIMEOUT);
257+
#endif
251258
_MQTT_client.setCallback(incomingMQTT);
252259

253260
#if defined(MY_GATEWAY_ESP8266) || defined(MY_GATEWAY_ESP32)

keywords.txt

+2
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,8 @@ MY_MQTT_PASSWORD LITERAL1
258258
MY_MQTT_PUBLISH_TOPIC_PREFIX LITERAL1
259259
MY_MQTT_SUBSCRIBE_TOPIC_PREFIX LITERAL1
260260
MY_MQTT_USER LITERAL1
261+
MY_MQTT_ETH_CLIENT_CONNECTION_TIMEOUT LITERAL1
262+
MY_MQTT_ETH_INIT_DELAY LITERAL1
261263
MY_W5100_SPI_EN LITERAL1
262264
MY_WIFI_SSID LITERAL1
263265
MY_WIFI_BSSID LITERAL1

0 commit comments

Comments
 (0)