Fix crash on SIM7000SSL
Signed-off-by: Sara Damiano <sdamiano@stroudcenter.org>
This commit is contained in:
@@ -52,16 +52,16 @@ SoftwareSerial SerialAT(2, 3); // RX, TX
|
||||
// Define the serial console for debug prints, if needed
|
||||
#define TINY_GSM_DEBUG SerialMon
|
||||
|
||||
// Add a reception delay, if needed.
|
||||
// This may be needed for a fast processor at a slow baud rate.
|
||||
// #define TINY_GSM_YIELD() { delay(2); }
|
||||
|
||||
// Range to attempt to autobaud
|
||||
// NOTE: DO NOT AUTOBAUD in production code. Once you've established
|
||||
// communication, set a fixed baud rate using modem.setBaud(#).
|
||||
#define GSM_AUTOBAUD_MIN 9600
|
||||
#define GSM_AUTOBAUD_MAX 57600
|
||||
|
||||
// Add a reception delay, if needed.
|
||||
// This may be needed for a fast processor at a slow baud rate.
|
||||
// #define TINY_GSM_YIELD() { delay(2); }
|
||||
|
||||
/*
|
||||
* Tests enabled
|
||||
*/
|
||||
|
@@ -10,20 +10,15 @@
|
||||
* For more MQTT examples, see PubSubClient library
|
||||
*
|
||||
**************************************************************
|
||||
* Use Mosquitto client tools to work with MQTT
|
||||
* Ubuntu/Linux: sudo apt-get install mosquitto-clients
|
||||
* Windows: https://mosquitto.org/download/
|
||||
* This example connects to HiveMQ's showcase broker.
|
||||
*
|
||||
* Subscribe for messages:
|
||||
* mosquitto_sub -h test.mosquitto.org -t GsmClientTest/init -t GsmClientTest/ledStatus -q 1
|
||||
* Toggle led:
|
||||
* mosquitto_pub -h test.mosquitto.org -t GsmClientTest/led -q 1 -m "toggle"
|
||||
* You can quickly test sending and receiving messages from the HiveMQ webclient
|
||||
* available at http://www.hivemq.com/demos/websocket-client/.
|
||||
*
|
||||
* You can use Node-RED for wiring together MQTT-enabled devices
|
||||
* https://nodered.org/
|
||||
* Also, take a look at these additional Node-RED modules:
|
||||
* node-red-contrib-blynk-ws
|
||||
* node-red-dashboard
|
||||
* Subscribe to the topic GsmClientTest/ledStatus
|
||||
* Publish "toggle" to the topic GsmClientTest/led and the LED on your board
|
||||
* should toggle and you should see a new message published to
|
||||
* GsmClientTest/ledStatus with the newest LED status.
|
||||
*
|
||||
**************************************************************/
|
||||
|
||||
@@ -251,6 +246,34 @@ void setup() {
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// Make sure we're still registered on the network
|
||||
if (!modem.isNetworkConnected()) {
|
||||
SerialMon.println("Network disconnected");
|
||||
if (!modem.waitForNetwork(180000L, true)) {
|
||||
SerialMon.println(" fail");
|
||||
delay(10000);
|
||||
return;
|
||||
}
|
||||
if (modem.isNetworkConnected()) {
|
||||
SerialMon.println("Network re-connected");
|
||||
}
|
||||
|
||||
#if TINY_GSM_USE_GPRS
|
||||
// and make sure GPRS/EPS is still connected
|
||||
if (!modem.isGprsConnected()) {
|
||||
SerialMon.println("GPRS disconnected!");
|
||||
SerialMon.print(F("Connecting to "));
|
||||
SerialMon.print(apn);
|
||||
if (!modem.gprsConnect(apn, gprsUser, gprsPass)) {
|
||||
SerialMon.println(" fail");
|
||||
delay(10000);
|
||||
return;
|
||||
}
|
||||
if (modem.isGprsConnected()) { SerialMon.println("GPRS reconnected"); }
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
if (!mqtt.connected()) {
|
||||
SerialMon.println("=== MQTT NOT CONNECTED ===");
|
||||
// Reconnect every 10 seconds
|
||||
|
@@ -485,6 +485,12 @@ class TinyGsmSim7000SSL
|
||||
}
|
||||
|
||||
size_t modemGetAvailable(uint8_t mux) {
|
||||
// If the socket doesn't exist, just return
|
||||
if (!sockets[mux]) { return 0; }
|
||||
// We need to check if there are any connections open *before* checking for
|
||||
// available characters. The SIM7000 *will crash* if you ask about data
|
||||
// when there are no open connections.
|
||||
if (!modemGetConnected(mux)) { return 0; }
|
||||
// NOTE: This gets how many characters are available on all connections that
|
||||
// have data. It does not return all the connections, just those with data.
|
||||
sendAT(GF("+CARECV?"));
|
||||
|
@@ -488,6 +488,8 @@ class TinyGsmSim7080 : public TinyGsmSim70xx<TinyGsmSim7080>,
|
||||
}
|
||||
|
||||
size_t modemGetAvailable(uint8_t mux) {
|
||||
// If the socket doesn't exist, just return
|
||||
if (!sockets[mux]) { return 0; }
|
||||
// NOTE: This gets how many characters are available on all connections that
|
||||
// have data. It does not return all the connections, just those with data.
|
||||
sendAT(GF("+CARECV?"));
|
||||
|
Reference in New Issue
Block a user