Skip to content

Commit

Permalink
Add MY_MQTT_ETH_CLIENT_CONNECTION_TIMEOUT to config
Browse files Browse the repository at this point in the history
MY_MQTT_ETH_CLIENT_CONNECTION_TIMEOUT is useful for adjusting default
MQTT TCP/IP connection timeout by library user.
  • Loading branch information
mobrembski authored and Michał Obrembski committed Nov 20, 2020
1 parent a090351 commit 6b5f47c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
16 changes: 16 additions & 0 deletions MyConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -1562,6 +1562,21 @@
#ifndef MY_MQTT_ETH_INIT_DELAY
#define MY_MQTT_ETH_INIT_DELAY 1000
#endif
/**
* @def MY_MQTT_ETH_CLIENT_CONNECTION_TIMEOUT
* @brief Set a MQTT broker socket connection timeout time.
*
* This define is useful if you want to change default MQTT TCP/IP broker
* connection timeout. By default, it is 1000ms.
*
* Note that this is not supported in ESP8266 and ESP32 platforms, sorry.
*
* Example: @code #define MY_MQTT_ETH_CLIENT_CONNECTION_TIMEOUT 1000 @endcode
*/
#ifndef MY_MQTT_ETH_CLIENT_CONNECTION_TIMEOUT
#define MY_MQTT_ETH_CLIENT_CONNECTION_TIMEOUT 1000
#endif

/**
* @def MY_IP_ADDRESS
* @brief Static ip address of gateway. If not defined, DHCP will be used.
Expand Down Expand Up @@ -2335,6 +2350,7 @@
#define MY_MQTT_CLIENT_CERT
#define MY_MQTT_CLIENT_KEY
#define MY_MQTT_ETH_INIT_DELAY
#define MY_MQTT_ETH_CLIENT_CONNECTION_TIMEOUT
#define MY_SIGNAL_REPORT_ENABLED
// general
#define MY_WITH_LEDS_BLINKING_INVERSE
Expand Down
11 changes: 9 additions & 2 deletions core/MyGatewayTransportMQTTClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,11 @@ bool reconnectMQTT(void)

return true;
}
delay(1000);
#if defined(MY_GATEWAY_ESP8266) || defined(MY_GATEWAY_ESP32)
delay(1000)
#else
delay(MY_MQTT_ETH_CLIENT_CONNECTION_TIMEOUT);
#endif
GATEWAY_DEBUG(PSTR("!GWT:RMQ:FAIL\n"));
return false;
}
Expand Down Expand Up @@ -247,7 +251,10 @@ bool gatewayTransportInit(void)
#else
_MQTT_client.setServer(MY_CONTROLLER_URL_ADDRESS, MY_PORT);
#endif /* End of MY_CONTROLLER_IP_ADDRESS */

// ESP platform doesn't support connection timeout
#if !defined(MY_GATEWAY_ESP8266) && !defined(MY_GATEWAY_ESP32)
_MQTT_ethClient.setConnectionTimeout(MY_MQTT_ETH_CLIENT_CONNECTION_TIMEOUT);
#endif
_MQTT_client.setCallback(incomingMQTT);

#if defined(MY_GATEWAY_ESP8266) || defined(MY_GATEWAY_ESP32)
Expand Down
2 changes: 2 additions & 0 deletions keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,8 @@ MY_MQTT_PASSWORD LITERAL1
MY_MQTT_PUBLISH_TOPIC_PREFIX LITERAL1
MY_MQTT_SUBSCRIBE_TOPIC_PREFIX LITERAL1
MY_MQTT_USER LITERAL1
MY_MQTT_ETH_CLIENT_CONNECTION_TIMEOUT LITERAL1
MY_MQTT_ETH_INIT_DELAY LITERAL1
MY_W5100_SPI_EN LITERAL1
MY_WIFI_SSID LITERAL1
MY_WIFI_BSSID LITERAL1
Expand Down

0 comments on commit 6b5f47c

Please sign in to comment.