Skip to content

Commit e5b44d2

Browse files
committed
add function for setting connection timeout accroding to network type
1 parent bd82bd6 commit e5b44d2

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
@@ -86,7 +86,6 @@ bool NetworkConfiguratorClass::begin() {
8686
DEBUG_ERROR("NetworkConfiguratorClass::%s Failed to initialize the AgentsManagerClass", __FUNCTION__);
8787
}
8888

89-
_connectionTimeout.begin(NC_CONNECTION_TIMEOUT_ms);
9089
_connectionRetryTimer.begin(NC_CONNECTION_RETRY_TIMER_ms);
9190
_resetInput->begin();
9291

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

113112
if(_state != nextState){
114113
if(nextState == NetworkConfiguratorStates::CONNECTING){
115-
_connectionTimeout.reload();
114+
setConnectionTimeoutTimer();
116115
}
117116
_state = nextState;
118117
}
@@ -395,6 +394,60 @@ bool NetworkConfiguratorClass::handleConnectRequest() {
395394
return true;
396395
}
397396

397+
void NetworkConfiguratorClass::setConnectionTimeoutTimer() {
398+
uint32_t timeout = 0;
399+
switch (_networkSetting.type) {
400+
#if defined(BOARD_HAS_WIFI)
401+
case NetworkAdapter::WIFI:
402+
timeout = 15000; // 15 seconds
403+
break;
404+
#endif
405+
406+
#if defined(BOARD_HAS_ETHERNET)
407+
case NetworkAdapter::ETHERNET:
408+
timeout = 15000; // 15 seconds
409+
break;
410+
#endif
411+
412+
#if defined(BOARD_HAS_NB)
413+
case NetworkAdapter::NB:
414+
timeout = 25000; // 25 seconds
415+
break;
416+
#endif
417+
418+
#if defined(BOARD_HAS_GSM)
419+
case NetworkAdapter::GSM:
420+
timeout = 25000; // 25 seconds
421+
break;
422+
#endif
423+
424+
#if defined(BOARD_HAS_CATM1_NBIOT)
425+
case NetworkAdapter::CATM1:
426+
timeout = 25000; // 25 seconds
427+
break;
428+
#endif
429+
430+
#if defined(BOARD_HAS_CELLULAR)
431+
case NetworkAdapter::CELL:
432+
timeout = 25000; // 25 seconds
433+
break;
434+
#endif
435+
436+
#if defined(BOARD_HAS_LORA)
437+
case NetworkAdapter::LORA:
438+
timeout 15000; // 15 seconds
439+
break;
440+
#endif
441+
default:
442+
timeout = 15000; // Default to 15 seconds for other adapters
443+
break;
444+
}
445+
446+
_connectionTimeout.begin(timeout);
447+
_connectionTimeout.reload();
448+
return;
449+
}
450+
398451
String NetworkConfiguratorClass::decodeConnectionErrorMessage(NetworkConnectionState err, StatusMessage *errorCode) {
399452
switch (err) {
400453
case NetworkConnectionState::ERROR:
@@ -462,7 +515,7 @@ NetworkConfiguratorStates NetworkConfiguratorClass::handleZeroTouchConfig() {
462515
return NetworkConfiguratorStates::READ_STORED_CONFIG;
463516
}
464517
_connectionHandlerIstantiated = true;
465-
_connectionTimeout.reload();
518+
setConnectionTimeoutTimer();
466519
}
467520

468521
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)