20
20
******************************************************************************/
21
21
22
22
/*
23
- static int const DBG_NONE = -1;
24
- static int const DBG_ERROR = 0;
25
- static int const DBG_WARNING = 1;
26
- static int const DBG_INFO = 2;
27
- static int const DBG_DEBUG = 3;
28
- static int const DBG_VERBOSE = 4;
23
+ static int const DBG_NONE = -1;
24
+ static int const DBG_ERROR = 0;
25
+ static int const DBG_WARNING = 1;
26
+ static int const DBG_INFO = 2;
27
+ static int const DBG_DEBUG = 3;
28
+ static int const DBG_VERBOSE = 4;
29
29
*/
30
30
31
31
#include " Arduino_GSMConnectionHandler.h"
@@ -73,13 +73,13 @@ void GSMConnectionHandler::init() {
73
73
74
74
void GSMConnectionHandler::addCallback (NetworkConnectionEvent const event, OnNetworkEventCallback callback) {
75
75
switch (event) {
76
- case NetworkConnectionEvent::CONNECTED: _on_connect_event_callback = callback; break ;
77
- case NetworkConnectionEvent::DISCONNECTED: _on_disconnect_event_callback = callback; break ;
78
- case NetworkConnectionEvent::ERROR: _on_error_event_callback = callback; break ;
79
- case NetworkConnectionEvent::INIT: ; break ;
80
- case NetworkConnectionEvent::CONNECTING: ; break ;
81
- case NetworkConnectionEvent::DISCONNECTING: ; break ;
82
- case NetworkConnectionEvent::CLOSED: ; break ;
76
+ case NetworkConnectionEvent::CONNECTED: _on_connect_event_callback = callback; break ;
77
+ case NetworkConnectionEvent::DISCONNECTED: _on_disconnect_event_callback = callback; break ;
78
+ case NetworkConnectionEvent::ERROR: _on_error_event_callback = callback; break ;
79
+ case NetworkConnectionEvent::INIT: ; break ;
80
+ case NetworkConnectionEvent::CONNECTING: ; break ;
81
+ case NetworkConnectionEvent::DISCONNECTING: ; break ;
82
+ case NetworkConnectionEvent::CLOSED: ; break ;
83
83
}
84
84
}
85
85
@@ -108,57 +108,57 @@ void GSMConnectionHandler::update() {
108
108
int gsmAccessAlive;
109
109
if (now - lastConnectionTickTime > connectionTickTimeInterval) {
110
110
switch (netConnectionState) {
111
- case NetworkConnectionState::INIT: {
112
- init ();
113
- }
114
- break ;
115
-
116
- case NetworkConnectionState::CONNECTING: {
117
- // NOTE: Blocking Call when 4th parameter == true
118
- GSM3_NetworkStatus_t networkStatus;
119
- networkStatus = gprs.attachGPRS (apn, login, pass, true );
120
- Debug.print (DBG_DEBUG, " GPRS.attachGPRS(): %d" , networkStatus);
121
- if (networkStatus == GSM3_NetworkStatus_t::ERROR) {
122
- // NO FURTHER ACTION WILL FOLLOW THIS
123
- changeConnectionState (NetworkConnectionState::ERROR);
124
- return ;
125
- }
126
- Debug.print (DBG_INFO, " Sending PING to outer space..." );
127
- int pingResult;
128
- pingResult = gprs.ping (" time.arduino.cc" );
129
- Debug.print (DBG_INFO, " GSM.ping(): %d" , pingResult);
130
- if (pingResult < 0 ) {
131
- Debug.print (DBG_ERROR, " PING failed" );
132
- Debug.print (DBG_INFO, " Retrying in \" %d\" milliseconds" , connectionTickTimeInterval);
133
- return ;
134
- } else {
135
- Debug.print (DBG_INFO, " Connected to GPRS Network" );
136
- changeConnectionState (NetworkConnectionState::CONNECTED);
137
- return ;
138
- }
139
- }
140
- break ;
141
- case NetworkConnectionState::CONNECTED: {
142
- gsmAccessAlive = gsmAccess.isAccessAlive ();
143
- Debug.print (DBG_VERBOSE, " GPRS.isAccessAlive(): %d" , gsmAccessAlive);
144
- if (gsmAccessAlive != 1 ) {
145
- changeConnectionState (NetworkConnectionState::DISCONNECTED);
146
- return ;
147
- }
148
- Debug.print (DBG_VERBOSE, " Connected to Cellular Network" );
149
- }
150
- break ;
151
- case NetworkConnectionState::DISCONNECTED: {
152
- // gprs.detachGPRS();
153
- if (keepAlive) {
154
- Debug.print (DBG_VERBOSE, " keep alive > INIT" );
155
- changeConnectionState (NetworkConnectionState::INIT);
156
- } else {
157
- changeConnectionState (NetworkConnectionState::CLOSED);
158
- }
159
- // changeConnectionState(NetworkConnectionState::CONNECTING);
160
- }
161
- break ;
111
+ case NetworkConnectionState::INIT: {
112
+ init ();
113
+ }
114
+ break ;
115
+
116
+ case NetworkConnectionState::CONNECTING: {
117
+ // NOTE: Blocking Call when 4th parameter == true
118
+ GSM3_NetworkStatus_t networkStatus;
119
+ networkStatus = gprs.attachGPRS (apn, login, pass, true );
120
+ Debug.print (DBG_DEBUG, " GPRS.attachGPRS(): %d" , networkStatus);
121
+ if (networkStatus == GSM3_NetworkStatus_t::ERROR) {
122
+ // NO FURTHER ACTION WILL FOLLOW THIS
123
+ changeConnectionState (NetworkConnectionState::ERROR);
124
+ return ;
125
+ }
126
+ Debug.print (DBG_INFO, " Sending PING to outer space..." );
127
+ int pingResult;
128
+ pingResult = gprs.ping (" time.arduino.cc" );
129
+ Debug.print (DBG_INFO, " GSM.ping(): %d" , pingResult);
130
+ if (pingResult < 0 ) {
131
+ Debug.print (DBG_ERROR, " PING failed" );
132
+ Debug.print (DBG_INFO, " Retrying in \" %d\" milliseconds" , connectionTickTimeInterval);
133
+ return ;
134
+ } else {
135
+ Debug.print (DBG_INFO, " Connected to GPRS Network" );
136
+ changeConnectionState (NetworkConnectionState::CONNECTED);
137
+ return ;
138
+ }
139
+ }
140
+ break ;
141
+ case NetworkConnectionState::CONNECTED: {
142
+ gsmAccessAlive = gsmAccess.isAccessAlive ();
143
+ Debug.print (DBG_VERBOSE, " GPRS.isAccessAlive(): %d" , gsmAccessAlive);
144
+ if (gsmAccessAlive != 1 ) {
145
+ changeConnectionState (NetworkConnectionState::DISCONNECTED);
146
+ return ;
147
+ }
148
+ Debug.print (DBG_VERBOSE, " Connected to Cellular Network" );
149
+ }
150
+ break ;
151
+ case NetworkConnectionState::DISCONNECTED: {
152
+ // gprs.detachGPRS();
153
+ if (keepAlive) {
154
+ Debug.print (DBG_VERBOSE, " keep alive > INIT" );
155
+ changeConnectionState (NetworkConnectionState::INIT);
156
+ } else {
157
+ changeConnectionState (NetworkConnectionState::CLOSED);
158
+ }
159
+ // changeConnectionState(NetworkConnectionState::CONNECTING);
160
+ }
161
+ break ;
162
162
}
163
163
lastConnectionTickTime = now;
164
164
}
@@ -171,44 +171,44 @@ void GSMConnectionHandler::update() {
171
171
void GSMConnectionHandler::changeConnectionState (NetworkConnectionState _newState) {
172
172
int newInterval = CHECK_INTERVAL_IDLE;
173
173
switch (_newState) {
174
- case NetworkConnectionState::INIT: {
175
- newInterval = CHECK_INTERVAL_INIT;
176
- }
177
- break ;
178
- case NetworkConnectionState::CONNECTING: {
179
- Debug.print (DBG_INFO, " Connecting to Cellular Network" );
180
- newInterval = CHECK_INTERVAL_CONNECTING;
181
- }
182
- break ;
183
- case NetworkConnectionState::CONNECTED: {
184
- execNetworkEventCallback (_on_connect_event_callback, 0 );
185
- newInterval = CHECK_INTERVAL_CONNECTED;
186
- }
187
- break ;
188
- case NetworkConnectionState::GETTIME: {
189
- }
190
- break ;
191
- case NetworkConnectionState::DISCONNECTING: {
192
- Debug.print (DBG_VERBOSE, " Disconnecting from Cellular Network" );
193
- gsmAccess.shutdown ();
194
- }
195
- case NetworkConnectionState::DISCONNECTED: {
196
- if (netConnectionState == NetworkConnectionState::CONNECTED) {
197
- execNetworkEventCallback (_on_disconnect_event_callback, 0 );
198
- Debug.print (DBG_ERROR, " Disconnected from Cellular Network" );
199
- Debug.print (DBG_ERROR, " Attempting reconnection" );
200
- if (keepAlive) {
201
- Debug.print (DBG_ERROR, " Attempting reconnection" );
174
+ case NetworkConnectionState::INIT: {
175
+ newInterval = CHECK_INTERVAL_INIT;
202
176
}
203
- }
204
- newInterval = CHECK_INTERVAL_DISCONNECTED;
205
- }
206
- break ;
207
- case NetworkConnectionState::ERROR: {
208
- execNetworkEventCallback (_on_error_event_callback, 0 );
209
- Debug.print (DBG_ERROR, " GPRS attach failed\n\r Make sure the antenna is connected and reset your board." );
210
- }
211
- break ;
177
+ break ;
178
+ case NetworkConnectionState::CONNECTING: {
179
+ Debug.print (DBG_INFO, " Connecting to Cellular Network" );
180
+ newInterval = CHECK_INTERVAL_CONNECTING;
181
+ }
182
+ break ;
183
+ case NetworkConnectionState::CONNECTED: {
184
+ execNetworkEventCallback (_on_connect_event_callback, 0 );
185
+ newInterval = CHECK_INTERVAL_CONNECTED;
186
+ }
187
+ break ;
188
+ case NetworkConnectionState::GETTIME: {
189
+ }
190
+ break ;
191
+ case NetworkConnectionState::DISCONNECTING: {
192
+ Debug.print (DBG_VERBOSE, " Disconnecting from Cellular Network" );
193
+ gsmAccess.shutdown ();
194
+ }
195
+ case NetworkConnectionState::DISCONNECTED: {
196
+ if (netConnectionState == NetworkConnectionState::CONNECTED) {
197
+ execNetworkEventCallback (_on_disconnect_event_callback, 0 );
198
+ Debug.print (DBG_ERROR, " Disconnected from Cellular Network" );
199
+ Debug.print (DBG_ERROR, " Attempting reconnection" );
200
+ if (keepAlive) {
201
+ Debug.print (DBG_ERROR, " Attempting reconnection" );
202
+ }
203
+ }
204
+ newInterval = CHECK_INTERVAL_DISCONNECTED;
205
+ }
206
+ break ;
207
+ case NetworkConnectionState::ERROR: {
208
+ execNetworkEventCallback (_on_error_event_callback, 0 );
209
+ Debug.print (DBG_ERROR, " GPRS attach failed\n\r Make sure the antenna is connected and reset your board." );
210
+ }
211
+ break ;
212
212
}
213
213
connectionTickTimeInterval = newInterval;
214
214
lastConnectionTickTime = millis ();
0 commit comments