Browse Source

Fix crash on SIM7000SSL

Signed-off-by: Sara Damiano <sdamiano@stroudcenter.org>
dependabot/github_actions/actions/checkout-4
Sara Damiano 3 years ago
parent
commit
6e10a3a009
4 changed files with 47 additions and 16 deletions
  1. +4
    -4
      examples/AllFunctions/AllFunctions.ino
  2. +35
    -12
      examples/MqttClient/MqttClient.ino
  3. +6
    -0
      src/TinyGsmClientSIM7000SSL.h
  4. +2
    -0
      src/TinyGsmClientSIM7080.h

+ 4
- 4
examples/AllFunctions/AllFunctions.ino View File

@ -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
*/


+ 35
- 12
examples/MqttClient/MqttClient.ino View File

@ -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


+ 6
- 0
src/TinyGsmClientSIM7000SSL.h View File

@ -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?"));


+ 2
- 0
src/TinyGsmClientSIM7080.h View File

@ -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?"));


Loading…
Cancel
Save