Skip to content

Commit dcccae1

Browse files
committed
Add CELL LED blink during connection and fix a bug where some of the event flags in the sandbox where cleared before being processed
1 parent 17aa7db commit dcccae1

File tree

3 files changed

+18
-31
lines changed

3 files changed

+18
-31
lines changed

examples/sandbox/sandbox.ino

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@
2525
#define MQTT_SUB_TOPIC_FMT "$aws/things/%s/shadow/update/delta"
2626
#define MQTT_PUB_TOPIC_FMT "%s/sensors"
2727

28-
#define NETWORK_CONN_FLAG 1 << 0
29-
#define NETWORK_DISCONN_FLAG 1 << 1
30-
#define BROKER_CONN_FLAG 1 << 2
31-
#define BROKER_DISCONN_FLAG 1 << 3
32-
#define SEND_HEARTBEAT_FLAG 1 << 4
33-
#define STOP_PUBLISHING_SENSOR_DATA_FLAG 1 << 5
34-
#define START_PUBLISHING_SENSOR_DATA_FLAG 1 << 6
35-
#define SEND_SENSOR_DATA_FLAG 1 << 7
28+
#define NETWORK_CONN_FLAG (1 << 0)
29+
#define NETWORK_DISCONN_FLAG (1 << 1)
30+
#define BROKER_CONN_FLAG (1 << 2)
31+
#define BROKER_DISCONN_FLAG (1 << 3)
32+
#define SEND_HEARTBEAT_FLAG (1 << 4)
33+
#define STOP_PUBLISHING_SENSOR_DATA_FLAG (1 << 5)
34+
#define START_PUBLISHING_SENSOR_DATA_FLAG (1 << 6)
35+
#define SEND_SENSOR_DATA_FLAG (1 << 7)
3636

3737
typedef enum {
3838
NOT_CONNECTED,
@@ -322,8 +322,6 @@ void setup() {
322322
connectLTE();
323323
}
324324

325-
unsigned long timeLastCellToggle = millis() + 500;
326-
327325
void loop() {
328326
// See if there are any messages for the command handler
329327
if (Serial3.available()) {
@@ -332,13 +330,6 @@ void loop() {
332330
}
333331

334332
// ----------------------------------------------------------
335-
if (state == NOT_CONNECTED) {
336-
if ((millis() - timeLastCellToggle) > 500) {
337-
LedCtrl.toggle(Led::CELL);
338-
timeLastCellToggle = millis();
339-
}
340-
}
341-
342333
if (event_flags & NETWORK_CONN_FLAG) {
343334
switch (state) {
344335
case NOT_CONNECTED:
@@ -372,6 +363,7 @@ void loop() {
372363
}
373364

374365
event_flags &= ~NETWORK_DISCONN_FLAG;
366+
375367
} else if (event_flags & BROKER_CONN_FLAG) {
376368

377369
switch (state) {

src/lte.cpp

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ bool LteClass::begin(const bool print_messages) {
9898
if (!SequansController.isInitialized()) {
9999
SequansController.begin();
100100

101-
// Allow 500ms for boot
102-
delay(500);
101+
// Allow 50ms for boot
102+
delay(50);
103103
}
104104

105105
SequansController.clearReceiveBuffer();
@@ -159,6 +159,7 @@ bool LteClass::begin(const bool print_messages) {
159159
}
160160

161161
while (!isConnected()) {
162+
LedCtrl.toggle(Led::CELL, true);
162163
delay(500);
163164

164165
if (print_messages) {
@@ -171,7 +172,7 @@ bool LteClass::begin(const bool print_messages) {
171172
}
172173

173174
SequansController.clearReceiveBuffer();
174-
SequansController.writeCommand(AT_COMMAND_GET_CLOCK);
175+
SequansController.retryCommand(AT_COMMAND_GET_CLOCK);
175176

176177
char clock_response[48] = "";
177178
result =
@@ -210,21 +211,16 @@ bool LteClass::begin(const bool print_messages) {
210211
// Do manual sync with NTP server
211212

212213
if (print_messages) {
213-
Log.info("Did not get time synchronization from operator, "
214-
"doing NTP synchronization. This can take some time.");
214+
Log.infof("Did not get time synchronization from operator, "
215+
"doing NTP synchronization.");
215216
}
216217

217-
SequansController.clearReceiveBuffer();
218218
SequansController.registerCallback(NTP_CALLBACK, ntpCallback);
219219

220220
while (!got_ntp_sync) {
221221
SequansController.clearReceiveBuffer();
222222
SequansController.retryCommand(AT_COMMAND_SYNC_NTP);
223223

224-
if (print_messages) {
225-
Log.infof("Waiting for NTP sync");
226-
}
227-
228224
while (!got_ntp_callback) {
229225

230226
if (print_messages) {
@@ -237,10 +233,6 @@ bool LteClass::begin(const bool print_messages) {
237233
if (got_ntp_sync) {
238234
break;
239235
} else {
240-
if (print_messages) {
241-
Log.rawf("\r\n");
242-
Log.info("NTP synchronization timed out, retrying...");
243-
}
244236
got_ntp_callback = false;
245237
}
246238
}

src/sequans_controller.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,9 @@ bool SequansControllerClass::retryCommand(const char *command,
458458

459459
do {
460460
writeCommand(command);
461+
462+
// Allow some time for the response
463+
_delay_ms(100);
461464
response = SequansController.readResponse();
462465

463466
} while (response != ResponseResult::OK && retry_count++ < retries);

0 commit comments

Comments
 (0)