2727 CONSTANTS
2828 ******************************************************************************/
2929
30- static const unsigned long NETWORK_CONNECTION_INTERVAL = 30000 ; /* NOT USED */
30+ static unsigned int const CHECK_INTERVAL_TABLE[] =
31+ {
32+ /* INIT */ 100 ,
33+ /* CONNECTING */ 500 ,
34+ /* CONNECTED */ 10000 ,
35+ /* GETTIME */ 100 ,
36+ /* DISCONNECTING */ 100 ,
37+ /* DISCONNECTED */ 1000 ,
38+ /* CLOSED */ 1000 ,
39+ /* ERROR */ 1000
40+ };
3141
3242/* *****************************************************************************
3343 CTOR/DTOR
@@ -39,7 +49,6 @@ LoRaConnectionHandler::LoRaConnectionHandler(char const * appeui, char const * a
3949, _band(band)
4050, _device_class(device_class)
4151, _lastConnectionTickTime(millis())
42- , _connectionTickTimeInterval(CHECK_INTERVAL_IDLE)
4352, _keep_alive(false )
4453{
4554
@@ -101,11 +110,14 @@ bool LoRaConnectionHandler::available() {
101110NetworkConnectionState LoRaConnectionHandler::check () {
102111
103112 unsigned long const now = millis ();
104- int networkStatus = 0 ;
105- if (now - _lastConnectionTickTime > _connectionTickTimeInterval) { /* time bracket */
113+ unsigned int const connectionTickTimeInterval = CHECK_INTERVAL_TABLE[static_cast <unsigned int >(netConnectionState)];
106114
115+ if ((now - _lastConnectionTickTime) > connectionTickTimeInterval)
116+ {
107117 _lastConnectionTickTime = now;
108- switch (netConnectionState) {
118+
119+ switch (netConnectionState)
120+ {
109121 case NetworkConnectionState::INIT: netConnectionState = update_handleInit (); break ;
110122 case NetworkConnectionState::CONNECTING: netConnectionState = update_handleConnecting (); break ;
111123 case NetworkConnectionState::CONNECTED: netConnectionState = update_handleConnected (); break ;
@@ -148,7 +160,6 @@ NetworkConnectionState LoRaConnectionHandler::update_handleInit() {
148160 _modem.configureClass (_device_class);
149161 delay (100 );
150162 Debug.print (DBG_INFO, " Connecting to the network" );
151- _connectionTickTimeInterval = CHECK_INTERVAL_CONNECTING;
152163 return NetworkConnectionState::CONNECTING;
153164}
154165
@@ -162,7 +173,6 @@ NetworkConnectionState LoRaConnectionHandler::update_handleConnecting() {
162173 }
163174
164175 Debug.print (DBG_INFO, " Connected to the network" );
165- _connectionTickTimeInterval = CHECK_INTERVAL_CONNECTED;
166176 execCallback (NetworkConnectionEvent::CONNECTED, 0 );
167177 return NetworkConnectionState::CONNECTED;
168178}
@@ -178,7 +188,6 @@ NetworkConnectionState LoRaConnectionHandler::update_handleConnected() {
178188 if (_keep_alive) {
179189 Debug.print (DBG_ERROR, " Attempting reconnection" );
180190 }
181- _connectionTickTimeInterval = CHECK_INTERVAL_DISCONNECTED;
182191 return NetworkConnectionState::DISCONNECTED;
183192 }
184193 Debug.print (DBG_VERBOSE, " Connected to the network" );
@@ -193,20 +202,17 @@ NetworkConnectionState LoRaConnectionHandler::update_handleDisconnecting() {
193202 if (_keep_alive) {
194203 Debug.print (DBG_ERROR, " Attempting reconnection" );
195204 }
196- _connectionTickTimeInterval = CHECK_INTERVAL_DISCONNECTED;
197205 return NetworkConnectionState::DISCONNECTED;
198206}
199207
200208NetworkConnectionState LoRaConnectionHandler::update_handleDisconnected () {
201209 if (_keep_alive) {
202210 Debug.print (DBG_VERBOSE, " CHANGING STATE TO ::INIT" );
203- _connectionTickTimeInterval = CHECK_INTERVAL_INIT;
204211 return NetworkConnectionState::INIT;
205212 } else {
206213 Debug.print (DBG_VERBOSE, " Connection to the network terminated" );
207214 return NetworkConnectionState::CLOSED;
208215 }
209-
210216}
211217
212218#endif
0 commit comments