Skip to content

Commit 9779eb9

Browse files
committed
Retry connection to network for sandbox
1 parent 5bb4f13 commit 9779eb9

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

examples/sandbox/sandbox.ino

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,9 @@ void connectLTE() {
109109

110110
Lte.onConnectionStatusChange(connectedToNetwork, disconnectedFromNetwork);
111111

112-
// Start LTE modem and wait until we are connected to the operator
113-
Lte.begin();
112+
// Start LTE modem and wait until we are connected to the operator.
113+
// If initialization fails, we just retry in the loop
114+
while (!Lte.begin()) {}
114115
}
115116

116117
void startStreamTimer() {

src/lte.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ static void connectionStatus(char *buffer) {
7070
}
7171
}
7272

73-
void LteClass::begin(void) {
73+
bool LteClass::begin(void) {
7474

7575
// If low power is utilized, sequans controller will already been
7676
// initialized, so don't reset it by calling begin again
@@ -104,7 +104,7 @@ void LteClass::begin(void) {
104104
if (result != ResponseResult::OK) {
105105
Log.error("Checking SIM status failed, is the SIM card inserted?");
106106
SequansController.retryCommand(AT_COMMAND_DISCONNECT);
107-
return;
107+
return false;
108108
}
109109

110110
char sim_status[16] = "";
@@ -114,14 +114,14 @@ void LteClass::begin(void) {
114114

115115
Log.error("Failed to extract value from command response during SIM "
116116
"status check");
117-
return;
117+
return false;
118118
}
119119

120120
// strncmp returns 0 if the strings are equal
121121
if (strncmp(sim_status, "READY", 5)) {
122122
Log.errorf("SIM card is not ready, error: %s\r\n", sim_status);
123123
SequansController.retryCommand(AT_COMMAND_DISCONNECT);
124-
return;
124+
return false;
125125
}
126126

127127
// Enable the default callback
@@ -134,6 +134,8 @@ void LteClass::begin(void) {
134134
if (isConnected() && connected_callback != NULL) {
135135
connected_callback();
136136
}
137+
138+
return true;
137139
}
138140

139141
void LteClass::end(void) {

src/lte.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,10 @@ class LteClass {
2828
/**
2929
* @brief Initializes the LTE module and its controller interface. Starts
3030
* searching for operator.
31+
*
32+
* @return True if initialization was successful.
3133
*/
32-
void begin(void);
34+
bool begin(void);
3335

3436
/**
3537
* @brief Disables the interface with the LTE module. Disconnects from

0 commit comments

Comments
 (0)