Skip to content

Commit 315b031

Browse files
authored
Use timeout duration of connection attempt according to connection type (#17)
1 parent 82b1057 commit 315b031

File tree

2 files changed

+59
-3
lines changed

2 files changed

+59
-3
lines changed

src/Arduino_NetworkConfigurator.cpp

Lines changed: 56 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ bool NetworkConfiguratorClass::begin() {
7676
DEBUG_ERROR("NetworkConfiguratorClass::%s Failed to initialize the AgentsManagerClass", __FUNCTION__);
7777
}
7878

79-
_connectionTimeout.begin(NC_CONNECTION_TIMEOUT_ms);
8079
_connectionRetryTimer.begin(NC_CONNECTION_RETRY_TIMER_ms);
8180
_resetInput->begin();
8281

@@ -102,7 +101,7 @@ NetworkConfiguratorStates NetworkConfiguratorClass::update() {
102101

103102
if(_state != nextState){
104103
if(nextState == NetworkConfiguratorStates::CONNECTING){
105-
_connectionTimeout.reload();
104+
setConnectionTimeoutTimer();
106105
}
107106
_state = nextState;
108107
}
@@ -385,6 +384,60 @@ bool NetworkConfiguratorClass::handleConnectRequest() {
385384
return true;
386385
}
387386

387+
void NetworkConfiguratorClass::setConnectionTimeoutTimer() {
388+
uint32_t timeout = 0;
389+
switch (_networkSetting.type) {
390+
#if defined(BOARD_HAS_WIFI)
391+
case NetworkAdapter::WIFI:
392+
timeout = NC_CONNECTION_TIMEOUT_ms; // 15 seconds
393+
break;
394+
#endif
395+
396+
#if defined(BOARD_HAS_ETHERNET)
397+
case NetworkAdapter::ETHERNET:
398+
timeout = NC_CONNECTION_TIMEOUT_ms; // 15 seconds
399+
break;
400+
#endif
401+
402+
#if defined(BOARD_HAS_NB)
403+
case NetworkAdapter::NB:
404+
timeout = 2 * NC_CONNECTION_TIMEOUT_ms; // 30 seconds
405+
break;
406+
#endif
407+
408+
#if defined(BOARD_HAS_GSM)
409+
case NetworkAdapter::GSM:
410+
timeout = 2 * NC_CONNECTION_TIMEOUT_ms; // 30 seconds
411+
break;
412+
#endif
413+
414+
#if defined(BOARD_HAS_CATM1_NBIOT)
415+
case NetworkAdapter::CATM1:
416+
timeout = 2 * NC_CONNECTION_TIMEOUT_ms; // 30 seconds
417+
break;
418+
#endif
419+
420+
#if defined(BOARD_HAS_CELLULAR)
421+
case NetworkAdapter::CELL:
422+
timeout = 2 * NC_CONNECTION_TIMEOUT_ms; // 30 seconds
423+
break;
424+
#endif
425+
426+
#if defined(BOARD_HAS_LORA)
427+
case NetworkAdapter::LORA:
428+
timeout = NC_CONNECTION_TIMEOUT_ms; // 15 seconds
429+
break;
430+
#endif
431+
default:
432+
timeout = NC_CONNECTION_TIMEOUT_ms; // Default to 15 seconds for other adapters
433+
break;
434+
}
435+
436+
_connectionTimeout.begin(timeout);
437+
_connectionTimeout.reload();
438+
return;
439+
}
440+
388441
String NetworkConfiguratorClass::decodeConnectionErrorMessage(NetworkConnectionState err, StatusMessage *errorCode) {
389442
switch (err) {
390443
case NetworkConnectionState::ERROR:
@@ -452,7 +505,7 @@ NetworkConfiguratorStates NetworkConfiguratorClass::handleZeroTouchConfig() {
452505
return NetworkConfiguratorStates::WAITING_FOR_CONFIG;
453506
}
454507
_connectionHandlerIstantiated = true;
455-
_connectionTimeout.reload();
508+
setConnectionTimeoutTimer();
456509
}
457510

458511
StatusMessage err;

src/Arduino_NetworkConfigurator.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,9 @@ class NetworkConfiguratorClass {
207207

208208
void startReconfigureProcedure();
209209

210+
// Returns the connection timeout in milliseconds according to the set network type
211+
void setConnectionTimeoutTimer();
212+
210213
String decodeConnectionErrorMessage(NetworkConnectionState err, StatusMessage *errorCode);
211214
ConnectionResult connectToNetwork(StatusMessage *err);
212215
ConnectionResult disconnectFromNetwork();

0 commit comments

Comments
 (0)