Update some example text and add new modems

Signed-off-by: Sara Damiano <sdamiano@stroudcenter.org>
This commit is contained in:
Sara Damiano
2021-05-14 11:04:56 -04:00
parent db756813d4
commit cad8f7a61a
8 changed files with 225 additions and 222 deletions

View File

@@ -15,6 +15,8 @@
// #define TINY_GSM_MODEM_SIM868
// #define TINY_GSM_MODEM_SIM900
// #define TINY_GSM_MODEM_SIM7000
// #define TINY_GSM_MODEM_SIM7000SSL
// #define TINY_GSM_MODEM_SIM7080
// #define TINY_GSM_MODEM_SIM5360
// #define TINY_GSM_MODEM_SIM7600
// #define TINY_GSM_MODEM_UBLOX
@@ -50,7 +52,13 @@ 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

View File

@@ -34,6 +34,8 @@
// #define TINY_GSM_MODEM_SIM868
// #define TINY_GSM_MODEM_SIM900
// #define TINY_GSM_MODEM_SIM7000
// #define TINY_GSM_MODEM_SIM7000SSL
// #define TINY_GSM_MODEM_SIM7080
// #define TINY_GSM_MODEM_SIM5360
// #define TINY_GSM_MODEM_SIM7600
// #define TINY_GSM_MODEM_UBLOX

View File

@@ -19,6 +19,8 @@
// #define TINY_GSM_MODEM_SIM868
// #define TINY_GSM_MODEM_SIM900
// #define TINY_GSM_MODEM_SIM7000
// #define TINY_GSM_MODEM_SIM7000SSL
// #define TINY_GSM_MODEM_SIM7080
// #define TINY_GSM_MODEM_SIM5360
// #define TINY_GSM_MODEM_SIM7600
// #define TINY_GSM_MODEM_UBLOX
@@ -63,10 +65,12 @@ SoftwareSerial SerialAT(2, 3); // RX, TX
#define TINY_GSM_DEBUG SerialMon
// #define LOGGING // <- Logging is for the HTTP library
// Add a reception delay - may be needed for a fast processor at a slow baud rate
// 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); }
// Define how you're planning to connect to the internet
// Define how you're planning to connect to the internet.
// This is only needed for this example, not in other code.
#define TINY_GSM_USE_GPRS true
#define TINY_GSM_USE_WIFI false
@@ -144,9 +148,7 @@ void setup() {
#if TINY_GSM_USE_GPRS
// Unlock your SIM card with a PIN if needed
if ( GSM_PIN && modem.getSimStatus() != 3 ) {
modem.simUnlock(GSM_PIN);
}
if (GSM_PIN && modem.getSimStatus() != 3) { modem.simUnlock(GSM_PIN); }
#endif
}
@@ -162,7 +164,6 @@ void printPercent(uint32_t readLength, uint32_t contentLength) {
}
void loop() {
#if TINY_GSM_USE_WIFI
// Wifi connection parameters must be set before waiting for the network
SerialMon.print(F("Setting SSID/password..."));
@@ -187,9 +188,7 @@ void loop() {
}
SerialMon.println(" success");
if (modem.isNetworkConnected()) {
SerialMon.println("Network connected");
}
if (modem.isNetworkConnected()) { SerialMon.println("Network connected"); }
#if TINY_GSM_USE_GPRS
// GPRS connection parameters are usually set after network registration
@@ -202,9 +201,7 @@ void loop() {
}
SerialMon.println(" success");
if (modem.isGprsConnected()) {
SerialMon.println("GPRS connected");
}
if (modem.isGprsConnected()) { SerialMon.println("GPRS connected"); }
#endif
SerialMon.print(F("Connecting to "));
@@ -226,9 +223,10 @@ void loop() {
SerialMon.println(F("Waiting for response header"));
// While we are still looking for the end of the header (i.e. empty line FOLLOWED by a newline),
// continue to read data into the buffer, parsing each line (data FOLLOWED by a newline).
// If it takes too long to get data from the client, we need to exit.
// While we are still looking for the end of the header (i.e. empty line
// FOLLOWED by a newline), continue to read data into the buffer, parsing each
// line (data FOLLOWED by a newline). If it takes too long to get data from
// the client, we need to exit.
const uint32_t clientReadTimeout = 5000;
uint32_t clientReadStartTime = millis();
@@ -257,11 +255,9 @@ void loop() {
// SerialMon.print(' ');
// Let's exit and process if we find a new line
if (headerBuffer.indexOf(F("\r\n")) >= 0)
break;
if (headerBuffer.indexOf(F("\r\n")) >= 0) break;
}
}
else {
} else {
if (millis() - clientReadStartTime > clientReadTimeout) {
// Time-out waiting for data from client
SerialMon.println(F(">>> Client Timeout !"));
@@ -276,22 +272,25 @@ void loop() {
headerBuffer.toLowerCase();
// Check if line contains content-length
if (headerBuffer.startsWith(F("content-length:"))) {
contentLength = headerBuffer.substring(headerBuffer.indexOf(':') + 1).toInt();
contentLength =
headerBuffer.substring(headerBuffer.indexOf(':') + 1).toInt();
// SerialMon.print(F("Got Content Length: ")); // uncomment for
// SerialMon.println(contentLength); // confirmation
}
headerBuffer.remove(0, nlPos + 2); // remove the line
}
else if (nlPos == 0) {
// if the new line is empty (i.e. "\r\n" is at the beginning of the line), we are done with the header.
} else if (nlPos == 0) {
// if the new line is empty (i.e. "\r\n" is at the beginning of the line),
// we are done with the header.
finishedHeader = true;
}
}
// The two cases which are not managed properly are as follows:
// 1. The client doesn't provide data quickly enough to keep up with this loop.
// 2. If the client data is segmented in the middle of the 'Content-Length: ' header,
// 1. The client doesn't provide data quickly enough to keep up with this
// loop.
// 2. If the client data is segmented in the middle of the 'Content-Length: '
// header,
// then that header may be missed/damaged.
//
@@ -303,10 +302,12 @@ void loop() {
clientReadStartTime = millis();
printPercent(readLength, contentLength);
while (readLength < contentLength && client.connected() && millis() - clientReadStartTime < clientReadTimeout) {
while (readLength < contentLength && client.connected() &&
millis() - clientReadStartTime < clientReadTimeout) {
while (client.available()) {
uint8_t c = client.read();
//SerialMon.print(reinterpret_cast<char>c); // Uncomment this to show data
// SerialMon.print(reinterpret_cast<char>c); // Uncomment this to show
// data
crc.update(c);
readLength++;
if (readLength % (contentLength / 13) == 0) {
@@ -338,14 +339,18 @@ void loop() {
float duration = float(timeElapsed) / 1000;
SerialMon.println();
SerialMon.print("Content-Length: "); SerialMon.println(contentLength);
SerialMon.print("Actually read: "); SerialMon.println(readLength);
SerialMon.print("Calc. CRC32: 0x"); SerialMon.println(crc.finalize(), HEX);
SerialMon.print("Known CRC32: 0x"); SerialMon.println(knownCRC32, HEX);
SerialMon.print("Duration: "); SerialMon.print(duration); SerialMon.println("s");
SerialMon.print("Content-Length: ");
SerialMon.println(contentLength);
SerialMon.print("Actually read: ");
SerialMon.println(readLength);
SerialMon.print("Calc. CRC32: 0x");
SerialMon.println(crc.finalize(), HEX);
SerialMon.print("Known CRC32: 0x");
SerialMon.println(knownCRC32, HEX);
SerialMon.print("Duration: ");
SerialMon.print(duration);
SerialMon.println("s");
// Do nothing forevermore
while (true) {
delay(1000);
}
while (true) { delay(1000); }
}

View File

@@ -24,6 +24,8 @@
// #define TINY_GSM_MODEM_SIM868
// #define TINY_GSM_MODEM_SIM900
// #define TINY_GSM_MODEM_SIM7000
// #define TINY_GSM_MODEM_SIM7000SSL
// #define TINY_GSM_MODEM_SIM7080
// #define TINY_GSM_MODEM_SIM5360
// #define TINY_GSM_MODEM_SIM7600
// #define TINY_GSM_MODEM_UBLOX
@@ -69,13 +71,17 @@ SoftwareSerial SerialAT(2, 3); // RX, TX
// #define LOGGING // <- Logging is for the HTTP library
// 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 115200
// Add a reception delay - may be needed for a fast processor at a slow baud rate
// 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); }
// Define how you're planning to connect to the internet
// These defines are only for this example; they are not needed in other code.
#define TINY_GSM_USE_GPRS true
#define TINY_GSM_USE_WIFI false
@@ -152,14 +158,11 @@ void setup() {
#if TINY_GSM_USE_GPRS
// Unlock your SIM card with a PIN if needed
if ( GSM_PIN && modem.getSimStatus() != 3 ) {
modem.simUnlock(GSM_PIN);
}
if (GSM_PIN && modem.getSimStatus() != 3) { modem.simUnlock(GSM_PIN); }
#endif
}
void loop() {
#if TINY_GSM_USE_WIFI
// Wifi connection parameters must be set before waiting for the network
SerialMon.print(F("Setting SSID/password..."));
@@ -184,9 +187,7 @@ void loop() {
}
SerialMon.println(" success");
if (modem.isNetworkConnected()) {
SerialMon.println("Network connected");
}
if (modem.isNetworkConnected()) { SerialMon.println("Network connected"); }
#if TINY_GSM_USE_GPRS
// GPRS connection parameters are usually set after network registration
@@ -199,9 +200,7 @@ void loop() {
}
SerialMon.println(" success");
if (modem.isGprsConnected()) {
SerialMon.println("GPRS connected");
}
if (modem.isGprsConnected()) { SerialMon.println("GPRS connected"); }
#endif
SerialMon.print(F("Performing HTTP GET request... "));
@@ -258,7 +257,5 @@ void loop() {
#endif
// Do nothing forevermore
while (true) {
delay(1000);
}
while (true) { delay(1000); }
}

View File

@@ -25,7 +25,8 @@
#define TINY_GSM_MODEM_SIM800
// #define TINY_GSM_MODEM_SIM808
// #define TINY_GSM_MODEM_SIM868
// #define TINY_GSM_MODEM_SIM7000
// #define TINY_GSM_MODEM_SIM7000SSL
// #define TINY_GSM_MODEM_SIM7080
// #define TINY_GSM_MODEM_UBLOX
// #define TINY_GSM_MODEM_SARAR4
// #define TINY_GSM_MODEM_ESP8266
@@ -62,13 +63,17 @@ SoftwareSerial SerialAT(2, 3); // RX, TX
// #define LOGGING // <- Logging is for the HTTP library
// 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 115200
// Add a reception delay - may be needed for a fast processor at a slow baud rate
// 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); }
// Define how you're planning to connect to the internet
// Define how you're planning to connect to the internet.
// This is only needed for this example, not in other code.
#define TINY_GSM_USE_GPRS true
#define TINY_GSM_USE_WIFI false
@@ -148,14 +153,11 @@ void setup() {
#if TINY_GSM_USE_GPRS
// Unlock your SIM card with a PIN if needed
if ( GSM_PIN && modem.getSimStatus() != 3 ) {
modem.simUnlock(GSM_PIN);
}
if (GSM_PIN && modem.getSimStatus() != 3) { modem.simUnlock(GSM_PIN); }
#endif
}
void loop() {
#if TINY_GSM_USE_WIFI
// Wifi connection parameters must be set before waiting for the network
SerialMon.print(F("Setting SSID/password..."));
@@ -180,9 +182,7 @@ void loop() {
}
SerialMon.println(" success");
if (modem.isNetworkConnected()) {
SerialMon.println("Network connected");
}
if (modem.isNetworkConnected()) { SerialMon.println("Network connected"); }
#if TINY_GSM_USE_GPRS
// GPRS connection parameters are usually set after network registration
@@ -195,9 +195,7 @@ void loop() {
}
SerialMon.println(" success");
if (modem.isGprsConnected()) {
SerialMon.println("GPRS connected");
}
if (modem.isGprsConnected()) { SerialMon.println("GPRS connected"); }
#endif
SerialMon.print(F("Performing HTTPS GET request... "));
@@ -255,7 +253,5 @@ void loop() {
#endif
// Do nothing forevermore
while (true) {
delay(1000);
}
while (true) { delay(1000); }
}

View File

@@ -33,6 +33,8 @@
// #define TINY_GSM_MODEM_SIM868
// #define TINY_GSM_MODEM_SIM900
// #define TINY_GSM_MODEM_SIM7000
// #define TINY_GSM_MODEM_SIM7000SSL
// #define TINY_GSM_MODEM_SIM7080
// #define TINY_GSM_MODEM_SIM5360
// #define TINY_GSM_MODEM_SIM7600
// #define TINY_GSM_MODEM_UBLOX
@@ -69,13 +71,17 @@ SoftwareSerial SerialAT(2, 3); // RX, TX
#define TINY_GSM_DEBUG SerialMon
// 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 115200
// Add a reception delay - may be needed for a fast processor at a slow baud rate
// 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); }
// Define how you're planning to connect to the internet
// Define how you're planning to connect to the internet.
// This is only needed for this example, not in other code.
#define TINY_GSM_USE_GPRS true
#define TINY_GSM_USE_WIFI false
@@ -196,9 +202,7 @@ void setup() {
#if TINY_GSM_USE_GPRS
// Unlock your SIM card with a PIN if needed
if ( GSM_PIN && modem.getSimStatus() != 3 ) {
modem.simUnlock(GSM_PIN);
}
if (GSM_PIN && modem.getSimStatus() != 3) { modem.simUnlock(GSM_PIN); }
#endif
#if TINY_GSM_USE_WIFI
@@ -225,9 +229,7 @@ void setup() {
}
SerialMon.println(" success");
if (modem.isNetworkConnected()) {
SerialMon.println("Network connected");
}
if (modem.isNetworkConnected()) { SerialMon.println("Network connected"); }
#if TINY_GSM_USE_GPRS
// GPRS connection parameters are usually set after network registration
@@ -240,9 +242,7 @@ void setup() {
}
SerialMon.println(" success");
if (modem.isGprsConnected()) {
SerialMon.println("GPRS connected");
}
if (modem.isGprsConnected()) { SerialMon.println("GPRS connected"); }
#endif
// MQTT Broker setup
@@ -251,16 +251,13 @@ void setup() {
}
void loop() {
if (!mqtt.connected()) {
SerialMon.println("=== MQTT NOT CONNECTED ===");
// Reconnect every 10 seconds
uint32_t t = millis();
if (t - lastReconnectAttempt > 10000L) {
lastReconnectAttempt = t;
if (mqttConnect()) {
lastReconnectAttempt = 0;
}
if (mqttConnect()) { lastReconnectAttempt = 0; }
}
delay(100);
return;

View File

@@ -14,6 +14,8 @@
// #define TINY_GSM_MODEM_SIM868
// #define TINY_GSM_MODEM_SIM900
// #define TINY_GSM_MODEM_SIM7000
// #define TINY_GSM_MODEM_SIM7000SSL
// #define TINY_GSM_MODEM_SIM7080
// #define TINY_GSM_MODEM_SIM5360
// #define TINY_GSM_MODEM_SIM7600
// #define TINY_GSM_MODEM_UBLOX
@@ -58,16 +60,20 @@ SoftwareSerial SerialAT(2, 3); // RX, TX
#define TINY_GSM_DEBUG SerialMon
// 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 115200
// Add a reception delay - may be needed for a fast processor at a slow baud rate
// 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); }
// Uncomment this if you want to use SSL
// #define USE_SSL
// Define how you're planning to connect to the internet
// Define how you're planning to connect to the internet.
// This is only needed for this example, not in other code.
#define TINY_GSM_USE_GPRS true
#define TINY_GSM_USE_WIFI false
@@ -147,14 +153,11 @@ void setup() {
#if TINY_GSM_USE_GPRS
// Unlock your SIM card with a PIN if needed
if ( GSM_PIN && modem.getSimStatus() != 3 ) {
modem.simUnlock(GSM_PIN);
}
if (GSM_PIN && modem.getSimStatus() != 3) { modem.simUnlock(GSM_PIN); }
#endif
}
void loop() {
#if TINY_GSM_USE_WIFI
// Wifi connection parameters must be set before waiting for the network
SerialMon.print(F("Setting SSID/password..."));
@@ -179,9 +182,7 @@ void loop() {
}
SerialMon.println(" success");
if (modem.isNetworkConnected()) {
SerialMon.println("Network connected");
}
if (modem.isNetworkConnected()) { SerialMon.println("Network connected"); }
#if TINY_GSM_USE_GPRS
// GPRS connection parameters are usually set after network registration
@@ -194,9 +195,7 @@ void loop() {
}
SerialMon.println(" success");
if (modem.isGprsConnected()) {
SerialMon.println("GPRS connected");
}
if (modem.isGprsConnected()) { SerialMon.println("GPRS connected"); }
#endif
SerialMon.print("Connecting to ");
@@ -241,7 +240,5 @@ void loop() {
#endif
// Do nothing forevermore
while (true) {
delay(1000);
}
while (true) { delay(1000); }
}

View File

@@ -15,6 +15,8 @@
// #define TINY_GSM_MODEM_SIM868
// #define TINY_GSM_MODEM_SIM900
// #define TINY_GSM_MODEM_SIM7000
// #define TINY_GSM_MODEM_SIM7000SSL
// #define TINY_GSM_MODEM_SIM7080
// #define TINY_GSM_MODEM_SIM5360
// #define TINY_GSM_MODEM_SIM7600
// #define TINY_GSM_MODEM_UBLOX
@@ -59,11 +61,13 @@ SoftwareSerial SerialAT(2, 3); // RX, TX
#define TINY_GSM_DEBUG SerialMon
// 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 115200
// Add a reception delay - may be needed for a fast processor at a slow baud rate
// #define TINY_GSM_YIELD() { delay(2); }
// Add a reception delay - may be needed for a fast processor at a slow baud
// rate #define TINY_GSM_YIELD() { delay(2); }
// Uncomment this if you want to use SSL
// #define USE_SSL
@@ -148,7 +152,7 @@ void loop() {
SerialMon.println(F(" Is your serial speed (baud rate) correct?"));
SerialMon.println(F(" Is your modem powered on?"));
SerialMon.println(F(" Do you use a good, stable power source?"));
SerialMon.println(F(" Try useing File -> Examples -> TinyGSM -> tools -> AT_Debug to find correct configuration"));
SerialMon.println(F(" Try using File -> Examples -> TinyGSM -> tools -> AT_Debug to find correct configuration"));
SerialMon.println(F("************************"));
delay(10000);
return;
@@ -161,9 +165,7 @@ void loop() {
#if TINY_GSM_USE_GPRS
// Unlock your SIM card with a PIN if needed
if ( GSM_PIN && modem.getSimStatus() != 3 ) {
modem.simUnlock(GSM_PIN);
}
if (GSM_PIN && modem.getSimStatus() != 3) { modem.simUnlock(GSM_PIN); }
#endif
#if TINY_GSM_USE_WIFI
@@ -183,7 +185,8 @@ void loop() {
#endif
SerialMon.print("Waiting for network...");
if (!modem.waitForNetwork(600000L)) { // You may need lengthen this in poor service areas
if (!modem.waitForNetwork(
600000L)) { // You may need lengthen this in poor service areas
SerialMon.println(F(" [fail]"));
SerialMon.println(F("************************"));
SerialMon.println(F(" Is your sim card locked?"));
@@ -274,7 +277,5 @@ void loop() {
SerialMon.println(F("************************"));
// Do nothing forevermore
while (true) {
delay(1000);
}
while (true) { delay(1000); }
}