Skip to content

Make TCP connect timeout configurable (remove hardcoded 75s) #116

Description

@fmoreira-adpulse

Summary

When using a SSL Client over TinyGSM (eg. GovoroxSSLClient), the SSL wrapper calls client.connect(host, port) with no timeout parameter.
In TinyGSM, this path falls back to a hardcoded 75 second TCP connect timeout, which is far too long for embedded use and easily trips the Task Watchdog (TWDT) when a broker is unreachable or the network is poor.

This timeout is currently not configurable via compile-time or runtime, the base Client interface (which must work for both Wi-Fi and GSM clients) cannot pass a third “timeout” argument.

Expected behavior

  • The TCP connect timeout should not be hardcoded.
  • Library users should be able to customize the connect timeout:
    • at compile time via a #define
    • and at runtime via a setter on the client (so higher layers like SSL can configure it without changing call signatures).

Proposed solution

  1. Add a compile-time default:
// in TinyGsmClient.h (or common config)
#ifndef TINYGSM_TCP_CONNECT_TIMEOUT_MS
#define TINYGSM_TCP_CONNECT_TIMEOUT_MS 75000
#endif 
  1. Add a runtime-settable member + setter on the GsmClient class:
public:
  void setConnectTimeout(int seconds) { _connectTimeoutS = seconds; }
  int  getConnectTimeout() const { return _connectTimeoutS; }

private:
  int _connectTimeoutS = TINYGSM_DEFAULT_CONNECT_TIMEOUT_S;
  1. Replace the macro with a version that uses the member (falls back to the define):
#define TINY_GSM_CLIENT_CONNECT_OVERRIDES                             \
  int connect(IPAddress ip, uint16_t port, int timeout_s) {           \
    return connect(TinyGsmStringFromIp(ip).c_str(), port, timeout_s); \
  }                                                                   \
  int connect(const char* host, uint16_t port) override {             \
    /* prefer runtime value if present, else compile-time default */  \
    return connect(host, port, _connectTimeoutS);                     \
  }                                                                   \
  int connect(IPAddress ip, uint16_t port) override {                 \
    return connect(ip, port, _connectTimeoutS);                       \
  }

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions