Skip to content

Commit 6e10a3a

Browse files
committed
Fix crash on SIM7000SSL
Signed-off-by: Sara Damiano <sdamiano@stroudcenter.org>
1 parent 60a88ef commit 6e10a3a

File tree

4 files changed

+47
-16
lines changed

4 files changed

+47
-16
lines changed

examples/AllFunctions/AllFunctions.ino

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,16 +52,16 @@ SoftwareSerial SerialAT(2, 3); // RX, TX
5252
// Define the serial console for debug prints, if needed
5353
#define TINY_GSM_DEBUG SerialMon
5454

55-
// Add a reception delay, if needed.
56-
// This may be needed for a fast processor at a slow baud rate.
57-
// #define TINY_GSM_YIELD() { delay(2); }
58-
5955
// Range to attempt to autobaud
6056
// NOTE: DO NOT AUTOBAUD in production code. Once you've established
6157
// communication, set a fixed baud rate using modem.setBaud(#).
6258
#define GSM_AUTOBAUD_MIN 9600
6359
#define GSM_AUTOBAUD_MAX 57600
6460

61+
// Add a reception delay, if needed.
62+
// This may be needed for a fast processor at a slow baud rate.
63+
// #define TINY_GSM_YIELD() { delay(2); }
64+
6565
/*
6666
* Tests enabled
6767
*/

examples/MqttClient/MqttClient.ino

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,15 @@
1010
* For more MQTT examples, see PubSubClient library
1111
*
1212
**************************************************************
13-
* Use Mosquitto client tools to work with MQTT
14-
* Ubuntu/Linux: sudo apt-get install mosquitto-clients
15-
* Windows: https://mosquitto.org/download/
13+
* This example connects to HiveMQ's showcase broker.
1614
*
17-
* Subscribe for messages:
18-
* mosquitto_sub -h test.mosquitto.org -t GsmClientTest/init -t GsmClientTest/ledStatus -q 1
19-
* Toggle led:
20-
* mosquitto_pub -h test.mosquitto.org -t GsmClientTest/led -q 1 -m "toggle"
15+
* You can quickly test sending and receiving messages from the HiveMQ webclient
16+
* available at http://www.hivemq.com/demos/websocket-client/.
2117
*
22-
* You can use Node-RED for wiring together MQTT-enabled devices
23-
* https://nodered.org/
24-
* Also, take a look at these additional Node-RED modules:
25-
* node-red-contrib-blynk-ws
26-
* node-red-dashboard
18+
* Subscribe to the topic GsmClientTest/ledStatus
19+
* Publish "toggle" to the topic GsmClientTest/led and the LED on your board
20+
* should toggle and you should see a new message published to
21+
* GsmClientTest/ledStatus with the newest LED status.
2722
*
2823
**************************************************************/
2924

@@ -251,6 +246,34 @@ void setup() {
251246
}
252247

253248
void loop() {
249+
// Make sure we're still registered on the network
250+
if (!modem.isNetworkConnected()) {
251+
SerialMon.println("Network disconnected");
252+
if (!modem.waitForNetwork(180000L, true)) {
253+
SerialMon.println(" fail");
254+
delay(10000);
255+
return;
256+
}
257+
if (modem.isNetworkConnected()) {
258+
SerialMon.println("Network re-connected");
259+
}
260+
261+
#if TINY_GSM_USE_GPRS
262+
// and make sure GPRS/EPS is still connected
263+
if (!modem.isGprsConnected()) {
264+
SerialMon.println("GPRS disconnected!");
265+
SerialMon.print(F("Connecting to "));
266+
SerialMon.print(apn);
267+
if (!modem.gprsConnect(apn, gprsUser, gprsPass)) {
268+
SerialMon.println(" fail");
269+
delay(10000);
270+
return;
271+
}
272+
if (modem.isGprsConnected()) { SerialMon.println("GPRS reconnected"); }
273+
}
274+
#endif
275+
}
276+
254277
if (!mqtt.connected()) {
255278
SerialMon.println("=== MQTT NOT CONNECTED ===");
256279
// Reconnect every 10 seconds

src/TinyGsmClientSIM7000SSL.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,12 @@ class TinyGsmSim7000SSL
485485
}
486486

487487
size_t modemGetAvailable(uint8_t mux) {
488+
// If the socket doesn't exist, just return
489+
if (!sockets[mux]) { return 0; }
490+
// We need to check if there are any connections open *before* checking for
491+
// available characters. The SIM7000 *will crash* if you ask about data
492+
// when there are no open connections.
493+
if (!modemGetConnected(mux)) { return 0; }
488494
// NOTE: This gets how many characters are available on all connections that
489495
// have data. It does not return all the connections, just those with data.
490496
sendAT(GF("+CARECV?"));

src/TinyGsmClientSIM7080.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,8 @@ class TinyGsmSim7080 : public TinyGsmSim70xx<TinyGsmSim7080>,
488488
}
489489

490490
size_t modemGetAvailable(uint8_t mux) {
491+
// If the socket doesn't exist, just return
492+
if (!sockets[mux]) { return 0; }
491493
// NOTE: This gets how many characters are available on all connections that
492494
// have data. It does not return all the connections, just those with data.
493495
sendAT(GF("+CARECV?"));

0 commit comments

Comments
 (0)