Update some example text and add new modems
Signed-off-by: Sara Damiano <sdamiano@stroudcenter.org>
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -110,11 +118,11 @@ const char resource[] = "/TinyGSM/logo.txt";
|
||||
#endif
|
||||
|
||||
#ifdef DUMP_AT_COMMANDS
|
||||
#include <StreamDebugger.h>
|
||||
StreamDebugger debugger(SerialAT, SerialMon);
|
||||
TinyGsm modem(debugger);
|
||||
#include <StreamDebugger.h>
|
||||
StreamDebugger debugger(SerialAT, SerialMon);
|
||||
TinyGsm modem(debugger);
|
||||
#else
|
||||
TinyGsm modem(SerialAT);
|
||||
TinyGsm modem(SerialAT);
|
||||
#endif
|
||||
|
||||
void setup() {
|
||||
|
@@ -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
|
||||
|
@@ -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
|
||||
|
||||
@@ -74,17 +78,17 @@ SoftwareSerial SerialAT(2, 3); // RX, TX
|
||||
#define GSM_PIN ""
|
||||
|
||||
// Your GPRS credentials, if any
|
||||
const char apn[] = "YourAPN";
|
||||
const char apn[] = "YourAPN";
|
||||
const char gprsUser[] = "";
|
||||
const char gprsPass[] = "";
|
||||
|
||||
// Your WiFi connection credentials, if applicable
|
||||
const char wifiSSID[] = "YourSSID";
|
||||
const char wifiSSID[] = "YourSSID";
|
||||
const char wifiPass[] = "YourWiFiPass";
|
||||
|
||||
// Server details
|
||||
const char server[] = "vsh.pp.ua";
|
||||
const int port = 80;
|
||||
const int port = 80;
|
||||
|
||||
#include <TinyGsmClient.h>
|
||||
#include <CRC32.h>
|
||||
@@ -103,16 +107,16 @@ const int port = 80;
|
||||
#define TINY_GSM_USE_WIFI false
|
||||
#endif
|
||||
|
||||
const char resource[] = "/TinyGSM/test_1k.bin";
|
||||
uint32_t knownCRC32 = 0x6f50d767;
|
||||
uint32_t knownFileSize = 1024; // In case server does not send it
|
||||
const char resource[] = "/TinyGSM/test_1k.bin";
|
||||
uint32_t knownCRC32 = 0x6f50d767;
|
||||
uint32_t knownFileSize = 1024; // In case server does not send it
|
||||
|
||||
#ifdef DUMP_AT_COMMANDS
|
||||
#include <StreamDebugger.h>
|
||||
StreamDebugger debugger(SerialAT, SerialMon);
|
||||
TinyGsm modem(debugger);
|
||||
#include <StreamDebugger.h>
|
||||
StreamDebugger debugger(SerialAT, SerialMon);
|
||||
TinyGsm modem(debugger);
|
||||
#else
|
||||
TinyGsm modem(SerialAT);
|
||||
TinyGsm modem(SerialAT);
|
||||
#endif
|
||||
|
||||
TinyGsmClient client(modem);
|
||||
@@ -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,15 +223,16 @@ 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();
|
||||
String headerBuffer;
|
||||
bool finishedHeader = false;
|
||||
uint32_t contentLength = 0;
|
||||
const uint32_t clientReadTimeout = 5000;
|
||||
uint32_t clientReadStartTime = millis();
|
||||
String headerBuffer;
|
||||
bool finishedHeader = false;
|
||||
uint32_t contentLength = 0;
|
||||
|
||||
while (!finishedHeader) {
|
||||
int nlPos;
|
||||
@@ -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,37 +272,42 @@ 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.
|
||||
//
|
||||
|
||||
uint32_t readLength = 0;
|
||||
CRC32 crc;
|
||||
CRC32 crc;
|
||||
|
||||
if (finishedHeader && contentLength == knownFileSize) {
|
||||
SerialMon.println(F("Reading response data"));
|
||||
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); }
|
||||
}
|
||||
|
@@ -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
|
||||
|
||||
@@ -83,18 +89,18 @@ SoftwareSerial SerialAT(2, 3); // RX, TX
|
||||
#define GSM_PIN ""
|
||||
|
||||
// Your GPRS credentials, if any
|
||||
const char apn[] = "YourAPN";
|
||||
const char apn[] = "YourAPN";
|
||||
const char gprsUser[] = "";
|
||||
const char gprsPass[] = "";
|
||||
|
||||
// Your WiFi connection credentials, if applicable
|
||||
const char wifiSSID[] = "YourSSID";
|
||||
const char wifiSSID[] = "YourSSID";
|
||||
const char wifiPass[] = "YourWiFiPass";
|
||||
|
||||
// Server details
|
||||
const char server[] = "vsh.pp.ua";
|
||||
const char server[] = "vsh.pp.ua";
|
||||
const char resource[] = "/TinyGSM/logo.txt";
|
||||
const int port = 80;
|
||||
const int port = 80;
|
||||
|
||||
#include <TinyGsmClient.h>
|
||||
#include <ArduinoHttpClient.h>
|
||||
@@ -114,15 +120,15 @@ const int port = 80;
|
||||
#endif
|
||||
|
||||
#ifdef DUMP_AT_COMMANDS
|
||||
#include <StreamDebugger.h>
|
||||
StreamDebugger debugger(SerialAT, SerialMon);
|
||||
TinyGsm modem(debugger);
|
||||
#include <StreamDebugger.h>
|
||||
StreamDebugger debugger(SerialAT, SerialMon);
|
||||
TinyGsm modem(debugger);
|
||||
#else
|
||||
TinyGsm modem(SerialAT);
|
||||
TinyGsm modem(SerialAT);
|
||||
#endif
|
||||
|
||||
TinyGsmClient client(modem);
|
||||
HttpClient http(client, server, port);
|
||||
HttpClient http(client, server, port);
|
||||
|
||||
void setup() {
|
||||
// Set console baud rate
|
||||
@@ -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,24 +187,20 @@ 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
|
||||
SerialMon.print(F("Connecting to "));
|
||||
SerialMon.print(apn);
|
||||
if (!modem.gprsConnect(apn, gprsUser, gprsPass)) {
|
||||
SerialMon.println(" fail");
|
||||
delay(10000);
|
||||
return;
|
||||
}
|
||||
SerialMon.println(" success");
|
||||
SerialMon.print(F("Connecting to "));
|
||||
SerialMon.print(apn);
|
||||
if (!modem.gprsConnect(apn, gprsUser, gprsPass)) {
|
||||
SerialMon.println(" fail");
|
||||
delay(10000);
|
||||
return;
|
||||
}
|
||||
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... "));
|
||||
@@ -222,7 +221,7 @@ void loop() {
|
||||
|
||||
SerialMon.println(F("Response Headers:"));
|
||||
while (http.headerAvailable()) {
|
||||
String headerName = http.readHeaderName();
|
||||
String headerName = http.readHeaderName();
|
||||
String headerValue = http.readHeaderValue();
|
||||
SerialMon.println(" " + headerName + " : " + headerValue);
|
||||
}
|
||||
@@ -249,16 +248,14 @@ void loop() {
|
||||
SerialMon.println(F("Server disconnected"));
|
||||
|
||||
#if TINY_GSM_USE_WIFI
|
||||
modem.networkDisconnect();
|
||||
SerialMon.println(F("WiFi disconnected"));
|
||||
modem.networkDisconnect();
|
||||
SerialMon.println(F("WiFi disconnected"));
|
||||
#endif
|
||||
#if TINY_GSM_USE_GPRS
|
||||
modem.gprsDisconnect();
|
||||
SerialMon.println(F("GPRS disconnected"));
|
||||
modem.gprsDisconnect();
|
||||
SerialMon.println(F("GPRS disconnected"));
|
||||
#endif
|
||||
|
||||
// Do nothing forevermore
|
||||
while (true) {
|
||||
delay(1000);
|
||||
}
|
||||
while (true) { delay(1000); }
|
||||
}
|
||||
|
@@ -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
|
||||
|
||||
@@ -79,12 +84,12 @@ SoftwareSerial SerialAT(2, 3); // RX, TX
|
||||
// #define TINY_GSM_SSL_CLIENT_AUTHENTICATION
|
||||
|
||||
// Your GPRS credentials, if any
|
||||
const char apn[] = "YourAPN";
|
||||
const char apn[] = "YourAPN";
|
||||
const char gprsUser[] = "";
|
||||
const char gprsPass[] = "";
|
||||
|
||||
// Your WiFi connection credentials, if applicable
|
||||
const char wifiSSID[] = "YourSSID";
|
||||
const char wifiSSID[] = "YourSSID";
|
||||
const char wifiPass[] = "YourWiFiPass";
|
||||
|
||||
// Server details
|
||||
@@ -114,7 +119,7 @@ const int port = 443;
|
||||
StreamDebugger debugger(SerialAT, SerialMon);
|
||||
TinyGsm modem(debugger);
|
||||
#else
|
||||
TinyGsm modem(SerialAT);
|
||||
TinyGsm modem(SerialAT);
|
||||
#endif
|
||||
|
||||
TinyGsmClientSecure client(modem);
|
||||
@@ -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,28 +182,24 @@ 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
|
||||
SerialMon.print(F("Connecting to "));
|
||||
SerialMon.print(apn);
|
||||
if (!modem.gprsConnect(apn, gprsUser, gprsPass)) {
|
||||
SerialMon.println(" fail");
|
||||
delay(10000);
|
||||
return;
|
||||
}
|
||||
SerialMon.println(" success");
|
||||
SerialMon.print(F("Connecting to "));
|
||||
SerialMon.print(apn);
|
||||
if (!modem.gprsConnect(apn, gprsUser, gprsPass)) {
|
||||
SerialMon.println(" fail");
|
||||
delay(10000);
|
||||
return;
|
||||
}
|
||||
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... "));
|
||||
http.connectionKeepAlive(); // Currently, this is needed for HTTPS
|
||||
http.connectionKeepAlive(); // Currently, this is needed for HTTPS
|
||||
int err = http.get(resource);
|
||||
if (err != 0) {
|
||||
SerialMon.println(F("failed to connect"));
|
||||
@@ -219,7 +217,7 @@ void loop() {
|
||||
|
||||
SerialMon.println(F("Response Headers:"));
|
||||
while (http.headerAvailable()) {
|
||||
String headerName = http.readHeaderName();
|
||||
String headerName = http.readHeaderName();
|
||||
String headerValue = http.readHeaderValue();
|
||||
SerialMon.println(" " + headerName + " : " + headerValue);
|
||||
}
|
||||
@@ -246,16 +244,14 @@ void loop() {
|
||||
SerialMon.println(F("Server disconnected"));
|
||||
|
||||
#if TINY_GSM_USE_WIFI
|
||||
modem.networkDisconnect();
|
||||
SerialMon.println(F("WiFi disconnected"));
|
||||
modem.networkDisconnect();
|
||||
SerialMon.println(F("WiFi disconnected"));
|
||||
#endif
|
||||
#if TINY_GSM_USE_GPRS
|
||||
modem.gprsDisconnect();
|
||||
SerialMon.println(F("GPRS disconnected"));
|
||||
modem.gprsDisconnect();
|
||||
SerialMon.println(F("GPRS disconnected"));
|
||||
#endif
|
||||
|
||||
// Do nothing forevermore
|
||||
while (true) {
|
||||
delay(1000);
|
||||
}
|
||||
while (true) { delay(1000); }
|
||||
}
|
||||
|
@@ -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
|
||||
|
||||
@@ -83,7 +89,7 @@ SoftwareSerial SerialAT(2, 3); // RX, TX
|
||||
#define GSM_PIN ""
|
||||
|
||||
// Your GPRS credentials, if any
|
||||
const char apn[] = "YourAPN";
|
||||
const char apn[] = "YourAPN";
|
||||
const char gprsUser[] = "";
|
||||
const char gprsPass[] = "";
|
||||
|
||||
@@ -94,8 +100,8 @@ const char wifiPass[] = "YourWiFiPass";
|
||||
// MQTT details
|
||||
const char* broker = "broker.hivemq.com";
|
||||
|
||||
const char* topicLed = "GsmClientTest/led";
|
||||
const char* topicInit = "GsmClientTest/init";
|
||||
const char* topicLed = "GsmClientTest/led";
|
||||
const char* topicInit = "GsmClientTest/init";
|
||||
const char* topicLedStatus = "GsmClientTest/ledStatus";
|
||||
|
||||
#include <TinyGsmClient.h>
|
||||
@@ -116,14 +122,14 @@ const char* topicLedStatus = "GsmClientTest/ledStatus";
|
||||
#endif
|
||||
|
||||
#ifdef DUMP_AT_COMMANDS
|
||||
#include <StreamDebugger.h>
|
||||
StreamDebugger debugger(SerialAT, SerialMon);
|
||||
TinyGsm modem(debugger);
|
||||
#include <StreamDebugger.h>
|
||||
StreamDebugger debugger(SerialAT, SerialMon);
|
||||
TinyGsm modem(debugger);
|
||||
#else
|
||||
TinyGsm modem(SerialAT);
|
||||
TinyGsm modem(SerialAT);
|
||||
#endif
|
||||
TinyGsmClient client(modem);
|
||||
PubSubClient mqtt(client);
|
||||
PubSubClient mqtt(client);
|
||||
|
||||
#define LED_PIN 13
|
||||
int ledStatus = LOW;
|
||||
@@ -153,7 +159,7 @@ boolean mqttConnect() {
|
||||
boolean status = mqtt.connect("GsmClientTest");
|
||||
|
||||
// Or, if you want to authenticate MQTT:
|
||||
//boolean status = mqtt.connect("GsmClientName", "mqtt_user", "mqtt_pass");
|
||||
// boolean status = mqtt.connect("GsmClientName", "mqtt_user", "mqtt_pass");
|
||||
|
||||
if (status == false) {
|
||||
SerialMon.println(" fail");
|
||||
@@ -196,13 +202,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
|
||||
|
||||
#if TINY_GSM_USE_WIFI
|
||||
// Wifi connection parameters must be set before waiting for the network
|
||||
// Wifi connection parameters must be set before waiting for the network
|
||||
SerialMon.print(F("Setting SSID/password..."));
|
||||
if (!modem.networkConnect(wifiSSID, wifiPass)) {
|
||||
SerialMon.println(" fail");
|
||||
@@ -225,24 +229,20 @@ 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
|
||||
SerialMon.print(F("Connecting to "));
|
||||
SerialMon.print(apn);
|
||||
if (!modem.gprsConnect(apn, gprsUser, gprsPass)) {
|
||||
SerialMon.println(" fail");
|
||||
delay(10000);
|
||||
return;
|
||||
}
|
||||
SerialMon.println(" success");
|
||||
|
||||
if (modem.isGprsConnected()) {
|
||||
SerialMon.println("GPRS connected");
|
||||
SerialMon.print(F("Connecting to "));
|
||||
SerialMon.print(apn);
|
||||
if (!modem.gprsConnect(apn, gprsUser, gprsPass)) {
|
||||
SerialMon.println(" fail");
|
||||
delay(10000);
|
||||
return;
|
||||
}
|
||||
SerialMon.println(" success");
|
||||
|
||||
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;
|
||||
|
@@ -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
|
||||
|
||||
@@ -75,16 +81,16 @@ SoftwareSerial SerialAT(2, 3); // RX, TX
|
||||
#define GSM_PIN ""
|
||||
|
||||
// Your GPRS credentials, if any
|
||||
const char apn[] = "YourAPN";
|
||||
const char apn[] = "YourAPN";
|
||||
const char gprsUser[] = "";
|
||||
const char gprsPass[] = "";
|
||||
|
||||
// Your WiFi connection credentials, if applicable
|
||||
const char wifiSSID[] = "YourSSID";
|
||||
const char wifiSSID[] = "YourSSID";
|
||||
const char wifiPass[] = "YourWiFiPass";
|
||||
|
||||
// Server details
|
||||
const char server[] = "vsh.pp.ua";
|
||||
const char server[] = "vsh.pp.ua";
|
||||
const char resource[] = "/TinyGSM/logo.txt";
|
||||
|
||||
#include <TinyGsmClient.h>
|
||||
@@ -104,19 +110,19 @@ const char resource[] = "/TinyGSM/logo.txt";
|
||||
#endif
|
||||
|
||||
#ifdef DUMP_AT_COMMANDS
|
||||
#include <StreamDebugger.h>
|
||||
StreamDebugger debugger(SerialAT, SerialMon);
|
||||
TinyGsm modem(debugger);
|
||||
#include <StreamDebugger.h>
|
||||
StreamDebugger debugger(SerialAT, SerialMon);
|
||||
TinyGsm modem(debugger);
|
||||
#else
|
||||
TinyGsm modem(SerialAT);
|
||||
TinyGsm modem(SerialAT);
|
||||
#endif
|
||||
|
||||
#ifdef USE_SSL
|
||||
TinyGsmClientSecure client(modem);
|
||||
const int port = 443;
|
||||
TinyGsmClientSecure client(modem);
|
||||
const int port = 443;
|
||||
#else
|
||||
TinyGsmClient client(modem);
|
||||
const int port = 80;
|
||||
TinyGsmClient client(modem);
|
||||
const int port = 80;
|
||||
#endif
|
||||
|
||||
void setup() {
|
||||
@@ -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,24 +182,20 @@ 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
|
||||
SerialMon.print(F("Connecting to "));
|
||||
SerialMon.print(apn);
|
||||
if (!modem.gprsConnect(apn, gprsUser, gprsPass)) {
|
||||
SerialMon.println(" fail");
|
||||
delay(10000);
|
||||
return;
|
||||
}
|
||||
SerialMon.println(" success");
|
||||
|
||||
if (modem.isGprsConnected()) {
|
||||
SerialMon.println("GPRS connected");
|
||||
SerialMon.print(F("Connecting to "));
|
||||
SerialMon.print(apn);
|
||||
if (!modem.gprsConnect(apn, gprsUser, gprsPass)) {
|
||||
SerialMon.println(" fail");
|
||||
delay(10000);
|
||||
return;
|
||||
}
|
||||
SerialMon.println(" success");
|
||||
|
||||
if (modem.isGprsConnected()) { SerialMon.println("GPRS connected"); }
|
||||
#endif
|
||||
|
||||
SerialMon.print("Connecting to ");
|
||||
@@ -232,16 +231,14 @@ void loop() {
|
||||
SerialMon.println(F("Server disconnected"));
|
||||
|
||||
#if TINY_GSM_USE_WIFI
|
||||
modem.networkDisconnect();
|
||||
SerialMon.println(F("WiFi disconnected"));
|
||||
modem.networkDisconnect();
|
||||
SerialMon.println(F("WiFi disconnected"));
|
||||
#endif
|
||||
#if TINY_GSM_USE_GPRS
|
||||
modem.gprsDisconnect();
|
||||
SerialMon.println(F("GPRS disconnected"));
|
||||
modem.gprsDisconnect();
|
||||
SerialMon.println(F("GPRS disconnected"));
|
||||
#endif
|
||||
|
||||
// Do nothing forevermore
|
||||
while (true) {
|
||||
delay(1000);
|
||||
}
|
||||
while (true) { delay(1000); }
|
||||
}
|
||||
|
@@ -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
|
||||
@@ -75,16 +79,16 @@ SoftwareSerial SerialAT(2, 3); // RX, TX
|
||||
#define GSM_PIN ""
|
||||
|
||||
// Your GPRS credentials, if any
|
||||
const char apn[] = "YourAPN";
|
||||
const char apn[] = "YourAPN";
|
||||
const char gprsUser[] = "";
|
||||
const char gprsPass[] = "";
|
||||
|
||||
// Your WiFi connection credentials, if applicable
|
||||
const char wifiSSID[] = "YourSSID";
|
||||
const char wifiSSID[] = "YourSSID";
|
||||
const char wifiPass[] = "YourWiFiPass";
|
||||
|
||||
// Server details
|
||||
const char server[] = "vsh.pp.ua";
|
||||
const char server[] = "vsh.pp.ua";
|
||||
const char resource[] = "/TinyGSM/logo.txt";
|
||||
|
||||
#include <TinyGsmClient.h>
|
||||
@@ -104,19 +108,19 @@ const char resource[] = "/TinyGSM/logo.txt";
|
||||
#endif
|
||||
|
||||
#ifdef DUMP_AT_COMMANDS
|
||||
#include <StreamDebugger.h>
|
||||
StreamDebugger debugger(SerialAT, SerialMon);
|
||||
TinyGsm modem(debugger);
|
||||
#include <StreamDebugger.h>
|
||||
StreamDebugger debugger(SerialAT, SerialMon);
|
||||
TinyGsm modem(debugger);
|
||||
#else
|
||||
TinyGsm modem(SerialAT);
|
||||
TinyGsm modem(SerialAT);
|
||||
#endif
|
||||
|
||||
#ifdef USE_SSL && defined TINY_GSM_MODEM_HAS_SSL
|
||||
TinyGsmClientSecure client(modem);
|
||||
const int port = 443;
|
||||
#ifdef USE_SSL&& defined TINY_GSM_MODEM_HAS_SSL
|
||||
TinyGsmClientSecure client(modem);
|
||||
const int port = 443;
|
||||
#else
|
||||
TinyGsmClient client(modem);
|
||||
const int port = 80;
|
||||
TinyGsmClient client(modem);
|
||||
const int port = 80;
|
||||
#endif
|
||||
|
||||
void setup() {
|
||||
@@ -141,14 +145,14 @@ void loop() {
|
||||
// To skip it, call init() instead of restart()
|
||||
SerialMon.print("Initializing modem...");
|
||||
if (!modem.restart()) {
|
||||
// if (!modem.init()) {
|
||||
// if (!modem.init()) {
|
||||
SerialMon.println(F(" [fail]"));
|
||||
SerialMon.println(F("************************"));
|
||||
SerialMon.println(F(" Is your modem connected properly?"));
|
||||
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?"));
|
||||
@@ -241,12 +244,12 @@ void loop() {
|
||||
client.find("\r\n\r\n");
|
||||
|
||||
// Read data
|
||||
uint32_t timeout = millis();
|
||||
uint32_t timeout = millis();
|
||||
uint32_t bytesReceived = 0;
|
||||
while (client.connected() && millis() - timeout < 10000L) {
|
||||
while (client.available()) {
|
||||
char c = client.read();
|
||||
//SerialMon.print(c);
|
||||
// SerialMon.print(c);
|
||||
bytesReceived += 1;
|
||||
timeout = millis();
|
||||
}
|
||||
@@ -266,15 +269,13 @@ void loop() {
|
||||
|
||||
SerialMon.println();
|
||||
SerialMon.println(F("************************"));
|
||||
SerialMon.print (F(" Received: "));
|
||||
SerialMon.print(F(" Received: "));
|
||||
SerialMon.print(bytesReceived);
|
||||
SerialMon.println(F(" bytes"));
|
||||
SerialMon.print (F(" Test: "));
|
||||
SerialMon.print(F(" Test: "));
|
||||
SerialMon.println((bytesReceived == 121) ? "PASSED" : "FAILED");
|
||||
SerialMon.println(F("************************"));
|
||||
|
||||
// Do nothing forevermore
|
||||
while (true) {
|
||||
delay(1000);
|
||||
}
|
||||
while (true) { delay(1000); }
|
||||
}
|
||||
|
Reference in New Issue
Block a user