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 17, 2020
1 parent e5f2e09 commit 169c309
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
15 changes: 15 additions & 0 deletions MyConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -1564,6 +1564,20 @@
#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.
* Example: @code #define MY_MQTT_ETH_CLIENT_CONNECTION_TIMEOUT 1000 @endcode
*
* @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 @@ -2337,6 +2351,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
4 changes: 2 additions & 2 deletions core/MyGatewayTransportMQTTClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ bool reconnectMQTT(void)

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

_MQTT_ethClient.setConnectionTimeout(MY_MQTT_ETH_CLIENT_CONNECTION_TIMEOUT);
_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 169c309

Please sign in to comment.