diff --git a/src/Arduino_NetworkConfigurator.cpp b/src/Arduino_NetworkConfigurator.cpp index 40c33c4..cd16080 100644 --- a/src/Arduino_NetworkConfigurator.cpp +++ b/src/Arduino_NetworkConfigurator.cpp @@ -86,7 +86,6 @@ bool NetworkConfiguratorClass::begin() { DEBUG_ERROR("NetworkConfiguratorClass::%s Failed to initialize the AgentsManagerClass", __FUNCTION__); } - _connectionTimeout.begin(NC_CONNECTION_TIMEOUT_ms); _connectionRetryTimer.begin(NC_CONNECTION_RETRY_TIMER_ms); _resetInput->begin(); @@ -112,7 +111,7 @@ NetworkConfiguratorStates NetworkConfiguratorClass::update() { if(_state != nextState){ if(nextState == NetworkConfiguratorStates::CONNECTING){ - _connectionTimeout.reload(); + setConnectionTimeoutTimer(); } _state = nextState; } @@ -395,6 +394,60 @@ bool NetworkConfiguratorClass::handleConnectRequest() { return true; } +void NetworkConfiguratorClass::setConnectionTimeoutTimer() { + uint32_t timeout = 0; + switch (_networkSetting.type) { +#if defined(BOARD_HAS_WIFI) + case NetworkAdapter::WIFI: + timeout = NC_CONNECTION_TIMEOUT_ms; // 15 seconds + break; +#endif + +#if defined(BOARD_HAS_ETHERNET) + case NetworkAdapter::ETHERNET: + timeout = NC_CONNECTION_TIMEOUT_ms; // 15 seconds + break; +#endif + +#if defined(BOARD_HAS_NB) + case NetworkAdapter::NB: + timeout = 2 * NC_CONNECTION_TIMEOUT_ms; // 30 seconds + break; +#endif + +#if defined(BOARD_HAS_GSM) + case NetworkAdapter::GSM: + timeout = 2 * NC_CONNECTION_TIMEOUT_ms; // 30 seconds + break; +#endif + +#if defined(BOARD_HAS_CATM1_NBIOT) + case NetworkAdapter::CATM1: + timeout = 2 * NC_CONNECTION_TIMEOUT_ms; // 30 seconds + break; +#endif + +#if defined(BOARD_HAS_CELLULAR) + case NetworkAdapter::CELL: + timeout = 2 * NC_CONNECTION_TIMEOUT_ms; // 30 seconds + break; +#endif + +#if defined(BOARD_HAS_LORA) + case NetworkAdapter::LORA: + timeout = NC_CONNECTION_TIMEOUT_ms; // 15 seconds + break; +#endif + default: + timeout = NC_CONNECTION_TIMEOUT_ms; // Default to 15 seconds for other adapters + break; + } + + _connectionTimeout.begin(timeout); + _connectionTimeout.reload(); + return; +} + String NetworkConfiguratorClass::decodeConnectionErrorMessage(NetworkConnectionState err, StatusMessage *errorCode) { switch (err) { case NetworkConnectionState::ERROR: @@ -462,7 +515,7 @@ NetworkConfiguratorStates NetworkConfiguratorClass::handleZeroTouchConfig() { return NetworkConfiguratorStates::READ_STORED_CONFIG; } _connectionHandlerIstantiated = true; - _connectionTimeout.reload(); + setConnectionTimeoutTimer(); } StatusMessage err; diff --git a/src/Arduino_NetworkConfigurator.h b/src/Arduino_NetworkConfigurator.h index fafe125..207e5ea 100644 --- a/src/Arduino_NetworkConfigurator.h +++ b/src/Arduino_NetworkConfigurator.h @@ -207,6 +207,9 @@ class NetworkConfiguratorClass { void startReconfigureProcedure(); + // Returns the connection timeout in milliseconds according to the set network type + void setConnectionTimeoutTimer(); + String decodeConnectionErrorMessage(NetworkConnectionState err, StatusMessage *errorCode); ConnectionResult connectToNetwork(StatusMessage *err); ConnectionResult disconnectFromNetwork();