Skip to content

Use timeout duration of connection attempt according to connection type #17

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 56 additions & 3 deletions src/Arduino_NetworkConfigurator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -112,7 +111,7 @@ NetworkConfiguratorStates NetworkConfiguratorClass::update() {

if(_state != nextState){
if(nextState == NetworkConfiguratorStates::CONNECTING){
_connectionTimeout.reload();
setConnectionTimeoutTimer();
}
_state = nextState;
}
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -462,7 +515,7 @@ NetworkConfiguratorStates NetworkConfiguratorClass::handleZeroTouchConfig() {
return NetworkConfiguratorStates::READ_STORED_CONFIG;
}
_connectionHandlerIstantiated = true;
_connectionTimeout.reload();
setConnectionTimeoutTimer();
}

StatusMessage err;
Expand Down
3 changes: 3 additions & 0 deletions src/Arduino_NetworkConfigurator.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Loading