@@ -37,12 +37,15 @@ CatM1ConnectionHandler::CatM1ConnectionHandler(
37
37
: ConnectionHandler{keep_alive, NetworkAdapter::CATM1}
38
38
{
39
39
_settings.type = NetworkAdapter::CATM1;
40
+ // To keep the backward compatibility, the user can call enableCheckInternetAvailability(false) for disabling the check
41
+ _check_internet_availability = true ;
40
42
strncpy (_settings.catm1 .pin , pin, sizeof (_settings.catm1 .pin )-1 );
41
43
strncpy (_settings.catm1 .apn , apn, sizeof (_settings.catm1 .apn )-1 );
42
44
strncpy (_settings.catm1 .login , login, sizeof (_settings.catm1 .login )-1 );
43
45
strncpy (_settings.catm1 .pass , pass, sizeof (_settings.catm1 .pass )-1 );
44
46
_settings.catm1 .rat = static_cast <uint8_t >(rat);
45
47
_settings.catm1 .band = band;
48
+ _reset = false ;
46
49
}
47
50
48
51
/* *****************************************************************************
@@ -51,7 +54,10 @@ CatM1ConnectionHandler::CatM1ConnectionHandler(
51
54
52
55
unsigned long CatM1ConnectionHandler::getTime ()
53
56
{
54
- return GSM.getTime ();
57
+ /* It is not safe to call GSM.getTime() since we don't know if modem internal
58
+ * RTC is in sync with current time.
59
+ */
60
+ return 0 ;
55
61
}
56
62
57
63
/* *****************************************************************************
@@ -61,6 +67,7 @@ unsigned long CatM1ConnectionHandler::getTime()
61
67
NetworkConnectionState CatM1ConnectionHandler::update_handleInit ()
62
68
{
63
69
#if defined (ARDUINO_EDGE_CONTROL)
70
+ /* Power on module */
64
71
pinMode (ON_MKR2, OUTPUT);
65
72
digitalWrite (ON_MKR2, HIGH);
66
73
#endif
@@ -71,31 +78,36 @@ NetworkConnectionState CatM1ConnectionHandler::update_handleInit()
71
78
_settings.catm1 .login ,
72
79
_settings.catm1 .pass ,
73
80
static_cast <RadioAccessTechnologyType>(_settings.catm1 .rat ) ,
74
- _settings.catm1 .band ))
81
+ _settings.catm1 .band ,
82
+ _reset))
75
83
{
76
84
Debug.print (DBG_ERROR, F (" The board was not able to register to the network..." ));
77
- return NetworkConnectionState::ERROR;
85
+ _reset = true ;
86
+ return NetworkConnectionState::DISCONNECTED;
78
87
}
88
+ _reset = false ;
79
89
return NetworkConnectionState::CONNECTING;
80
90
}
81
91
82
92
NetworkConnectionState CatM1ConnectionHandler::update_handleConnecting ()
83
93
{
84
94
if (!GSM.isConnected ())
85
95
{
86
- return NetworkConnectionState::INIT;
96
+ Debug.print (DBG_ERROR, F (" GSM connection not alive... disconnecting" ));
97
+ return NetworkConnectionState::DISCONNECTED;
87
98
}
88
99
89
100
if (!_check_internet_availability){
90
101
return NetworkConnectionState::CONNECTED;
91
102
}
92
103
93
- int ping_result = GSM.ping (" time.arduino.cc" );
104
+ Debug.print (DBG_INFO, F (" Sending PING to outer space..." ));
105
+ int const ping_result = GSM.ping (" time.arduino.cc" );
94
106
Debug.print (DBG_INFO, F (" GSM.ping(): %d" ), ping_result);
95
107
if (ping_result < 0 )
96
108
{
97
109
Debug.print (DBG_ERROR, F (" Internet check failed" ));
98
- Debug.print (DBG_INFO, F (" Retrying in \" %d\" milliseconds" ), CHECK_INTERVAL_TABLE[static_cast <unsigned int >(NetworkConnectionState::CONNECTING)]);
110
+ Debug.print (DBG_INFO, F (" Retrying in \" %d\" milliseconds" ), 2 * CHECK_INTERVAL_TABLE[static_cast <unsigned int >(NetworkConnectionState::CONNECTING)]);
99
111
return NetworkConnectionState::CONNECTING;
100
112
}
101
113
else
@@ -110,6 +122,7 @@ NetworkConnectionState CatM1ConnectionHandler::update_handleConnected()
110
122
int const is_gsm_access_alive = GSM.isConnected ();
111
123
if (is_gsm_access_alive != 1 )
112
124
{
125
+ Debug.print (DBG_ERROR, F (" GSM connection not alive... disconnecting" ));
113
126
return NetworkConnectionState::DISCONNECTED;
114
127
}
115
128
return NetworkConnectionState::CONNECTED;
@@ -123,6 +136,7 @@ NetworkConnectionState CatM1ConnectionHandler::update_handleDisconnecting()
123
136
124
137
NetworkConnectionState CatM1ConnectionHandler::update_handleDisconnected ()
125
138
{
139
+ GSM.end ();
126
140
if (_keep_alive)
127
141
{
128
142
return NetworkConnectionState::INIT;
0 commit comments