diff --git a/examples/AllFunctions/AllFunctions.ino b/examples/AllFunctions/AllFunctions.ino index 718193c..3f80573 100644 --- a/examples/AllFunctions/AllFunctions.ino +++ b/examples/AllFunctions/AllFunctions.ino @@ -28,16 +28,6 @@ // #define TINY_GSM_MODEM_XBEE // #define TINY_GSM_MODEM_SEQUANS_MONARCH -// See all AT commands, if wanted -// #define DUMP_AT_COMMANDS - -// Define the serial console for debug prints, if needed -#define TINY_GSM_DEBUG SerialMon - -// Range to attempt to autobaud -#define GSM_AUTOBAUD_MIN 9600 -#define GSM_AUTOBAUD_MAX 38400 - // Set serial for debug console (to the Serial Monitor, default speed 115200) #define SerialMon Serial @@ -49,8 +39,18 @@ //#include //SoftwareSerial SerialAT(2, 3); // RX, TX +// See all AT commands, if wanted +//#define DUMP_AT_COMMANDS + +// Define the serial console for debug prints, if needed +#define TINY_GSM_DEBUG SerialMon + +// Range to attempt to autobaud +#define GSM_AUTOBAUD_MIN 9600 +#define GSM_AUTOBAUD_MAX 38400 + /* - * Test enabled + * Tests enabled */ #define TINY_GSM_TEST_GPRS true #define TINY_GSM_TEST_WIFI false diff --git a/examples/FileDownload/FileDownload.ino b/examples/FileDownload/FileDownload.ino index 966e2d7..c0a93d8 100644 --- a/examples/FileDownload/FileDownload.ino +++ b/examples/FileDownload/FileDownload.ino @@ -32,18 +32,10 @@ // #define TINY_GSM_MODEM_XBEE // #define TINY_GSM_MODEM_SEQUANS_MONARCH -// Increase RX buffer if needed -#define TINY_GSM_RX_BUFFER 1024 - -#include -#include - -// Uncomment this if you want to see all AT commands -//#define DUMP_AT_COMMANDS - // Set serial for debug console (to the Serial Monitor, default speed 115200) #define SerialMon Serial +// Set serial for AT commands (to the module) // Use Hardware Serial on Mega, Leonardo, Micro #define SerialAT Serial1 @@ -51,12 +43,35 @@ //#include //SoftwareSerial SerialAT(2, 3); // RX, TX +// Increase RX buffer to capture the entire response +// Chips without internal buffering (A6/A7, ESP8266, M590) +// need enough space in the buffer for the entire response +// else data will be lost (and the http library will fail). +#define TINY_GSM_RX_BUFFER 1024 + +// See all AT commands, if wanted +//#define DUMP_AT_COMMANDS + +// Define the serial console for debug prints, if needed +#define TINY_GSM_DEBUG SerialMon +//#define LOGGING // <- Logging is for the HTTP library + +// Add a reception delay, if needed +//#define TINY_GSM_YIELD() { delay(2); } + +#define TINY_GSM_USE_GPRS true +#define TINY_GSM_USE_WIFI false + +// set GSM PIN, if any +#define GSM_PIN "" // Your GPRS credentials // Leave empty, if missing user or pass const char apn[] = "YourAPN"; -const char user[] = ""; -const char pass[] = ""; +const char gprsUser[] = ""; +const char gprsPass[] = ""; +const char wifiSSID[] = "YourSSID"; +const char wifiPass[] = "YourWiFiPass"; // Server details const char server[] = "vsh.pp.ua"; @@ -66,6 +81,9 @@ const char resource[] = "/TinyGSM/test_1k.bin"; uint32_t knownCRC32 = 0x6f50d767; uint32_t knownFileSize = 1024; // In case server does not send it +#include +#include + #ifdef DUMP_AT_COMMANDS #include StreamDebugger debugger(SerialAT, SerialMon); @@ -87,15 +105,19 @@ void setup() { // Restart takes quite some time // To skip it, call init() instead of restart() - SerialMon.println(F("Initializing modem...")); + SerialMon.println("Initializing modem..."); modem.restart(); String modemInfo = modem.getModemInfo(); - SerialMon.print(F("Modem: ")); + SerialMon.print("Modem: "); SerialMon.println(modemInfo); - // Unlock your SIM card with a PIN - //modem.simUnlock("1234"); +#if TINY_GSM_USE_GPRS + // Unlock your SIM card with a PIN if needed + if ( GSM_PIN && modem.getSimStatus() != 3 ) { + modem.simUnlock(GSM_PIN); +} +#endif } void printPercent(uint32_t readLength, uint32_t contentLength) { @@ -110,7 +132,23 @@ void printPercent(uint32_t readLength, uint32_t contentLength) { } void loop() { - SerialMon.print(F("Waiting for network...")); + +#if defined TINY_GSM_USE_WIFI && defined TINY_GSM_MODEM_HAS_WIFI + SerialMon.print(F("Setting SSID/password...")); + if (!modem.networkConnect(wifiSSID, wifiPass)) { + SerialMon.println(" fail"); + delay(10000); + return; + } + SerialMon.println(" OK"); +#endif + +#if TINY_GSM_USE_GPRS && defined TINY_GSM_MODEM_XBEE + // The XBee must run the gprsConnect function BEFORE waiting for network! + modem.gprsConnect(apn, gprsUser, gprsPass); +#endif + + SerialMon.print("Waiting for network..."); if (!modem.waitForNetwork()) { SerialMon.println(" fail"); delay(10000); @@ -118,14 +156,20 @@ void loop() { } SerialMon.println(" OK"); + if (modem.isNetworkConnected()) { + SerialMon.println("Network connected"); + } + +#if TINY_GSM_USE_GPRS && defined TINY_GSM_MODEM_HAS_GPRS SerialMon.print(F("Connecting to ")); SerialMon.print(apn); - if (!modem.gprsConnect(apn, user, pass)) { + if (!modem.gprsConnect(apn, gprsUser, gprsPass)) { SerialMon.println(" fail"); delay(10000); return; } SerialMon.println(" OK"); +#endif SerialMon.print(F("Connecting to ")); SerialMon.print(server); diff --git a/examples/HttpClient/HttpClient.ino b/examples/HttpClient/HttpClient.ino index 45295b8..bf9924d 100644 --- a/examples/HttpClient/HttpClient.ino +++ b/examples/HttpClient/HttpClient.ino @@ -37,6 +37,17 @@ // #define TINY_GSM_MODEM_XBEE // #define TINY_GSM_MODEM_SEQUANS_MONARCH +// Set serial for debug console (to the Serial Monitor, default speed 115200) +#define SerialMon Serial + +// Set serial for AT commands (to the module) +// Use Hardware Serial on Mega, Leonardo, Micro +#define SerialAT Serial1 + +// or Software Serial on Uno, Nano +//#include +//SoftwareSerial SerialAT(2, 3); // RX, TX + // Increase RX buffer to capture the entire response // Chips without internal buffering (A6/A7, ESP8266, M590) // need enough space in the buffer for the entire response @@ -47,22 +58,11 @@ //#define DUMP_AT_COMMANDS // Define the serial console for debug prints, if needed -//#define TINY_GSM_DEBUG Serial +#define TINY_GSM_DEBUG SerialMon //#define LOGGING // <- Logging is for the HTTP library // Add a reception delay, if needed -//#define TINY_GSM_YIELD() { delay(1); } - -// Set serial for debug console (to the Serial Monitor, default speed 115200) -#define SerialMon Serial - -// Set serial for AT commands (to the module) -// Use Hardware Serial on Mega, Leonardo, Micro -#define SerialAT Serial1 - -// or Software Serial on Uno, Nano -//#include -//SoftwareSerial SerialAT(2, 3); // RX, TX +//#define TINY_GSM_YIELD() { delay(2); } #define TINY_GSM_USE_GPRS true #define TINY_GSM_USE_WIFI false @@ -76,7 +76,7 @@ const char apn[] = "YourAPN"; const char gprsUser[] = ""; const char gprsPass[] = ""; const char wifiSSID[] = "YourSSID"; -const char wifiPass[] = "SSIDpw"; +const char wifiPass[] = "YourWiFiPass"; // Server details const char server[] = "vsh.pp.ua"; @@ -125,8 +125,12 @@ void setup() { SerialMon.print("Modem: "); SerialMon.println(modemInfo); - // Unlock your SIM card with a PIN - //modem.simUnlock("1234"); +#if TINY_GSM_USE_GPRS + // Unlock your SIM card with a PIN if needed + if ( GSM_PIN && modem.getSimStatus() != 3 ) { + modem.simUnlock(GSM_PIN); + } +#endif } void loop() { diff --git a/examples/HttpsClient/HttpsClient.ino b/examples/HttpsClient/HttpsClient.ino index ca61d43..e43711c 100644 --- a/examples/HttpsClient/HttpsClient.ino +++ b/examples/HttpsClient/HttpsClient.ino @@ -32,6 +32,17 @@ // #define TINY_GSM_MODEM_XBEE // #define TINY_GSM_MODEM_SEQUANS_MONARCH +// Set serial for debug console (to the Serial Monitor, default speed 115200) +#define SerialMon Serial + +// Set serial for AT commands (to the module) +// Use Hardware Serial on Mega, Leonardo, Micro +#define SerialAT Serial1 + +// or Software Serial on Uno, Nano +//#include +//SoftwareSerial SerialAT(2, 3); // RX, TX + // Increase RX buffer to capture the entire response // Chips without internal buffering (A6/A7, ESP8266, M590) // need enough space in the buffer for the entire response @@ -42,22 +53,11 @@ //#define DUMP_AT_COMMANDS // Define the serial console for debug prints, if needed -//#define TINY_GSM_DEBUG Serial +#define TINY_GSM_DEBUG SerialMon //#define LOGGING // <- Logging is for the HTTP library // Add a reception delay, if needed -//#define TINY_GSM_YIELD() { delay(1); } - -// Set serial for debug console (to the Serial Monitor, default speed 115200) -#define SerialMon Serial - -// Set serial for AT commands (to the module) -// Use Hardware Serial on Mega, Leonardo, Micro -#define SerialAT Serial1 - -// or Software Serial on Uno, Nano -//#include -//SoftwareSerial SerialAT(2, 3); // RX, TX +//#define TINY_GSM_YIELD() { delay(2); } #define TINY_GSM_USE_GPRS true #define TINY_GSM_USE_WIFI false @@ -71,7 +71,7 @@ const char apn[] = "YourAPN"; const char gprsUser[] = ""; const char gprsPass[] = ""; const char wifiSSID[] = "YourSSID"; -const char wifiPass[] = "SSIDpw"; +const char wifiPass[] = "YourWiFiPass"; // Server details const char server[] = "vsh.pp.ua"; @@ -120,8 +120,12 @@ void setup() { SerialMon.print("Modem: "); SerialMon.println(modemInfo); - // Unlock your SIM card with a PIN - //modem.simUnlock("1234"); +#if TINY_GSM_USE_GPRS + // Unlock your SIM card with a PIN if needed + if ( GSM_PIN && modem.getSimStatus() != 3 ) { + modem.simUnlock(GSM_PIN); + } +#endif if (!modem.hasSSL()) { SerialMon.println(F("SSL is not supported by this modem")); diff --git a/examples/MqttClient/MqttClient.ino b/examples/MqttClient/MqttClient.ino index 841be7f..91873a7 100644 --- a/examples/MqttClient/MqttClient.ino +++ b/examples/MqttClient/MqttClient.ino @@ -46,8 +46,19 @@ // #define TINY_GSM_MODEM_XBEE // #define TINY_GSM_MODEM_SEQUANS_MONARCH +// Set serial for debug console (to the Serial Monitor, default speed 115200) +#define SerialMon Serial + +// Set serial for AT commands (to the module) +// Use Hardware Serial on Mega, Leonardo, Micro +#define SerialAT Serial1 + +// or Software Serial on Uno, Nano +//#include +//SoftwareSerial SerialAT(2, 3); // RX, TX + // See all AT commands, if wanted -// #define DUMP_AT_COMMANDS +//#define DUMP_AT_COMMANDS // Define the serial console for debug prints, if needed #define TINY_GSM_DEBUG SerialMon @@ -57,25 +68,21 @@ #define GSM_AUTOBAUD_MAX 38400 // Add a reception delay, if needed -#define TINY_GSM_YIELD() { delay(2); } +//#define TINY_GSM_YIELD() { delay(2); } -// Set serial for debug console (to the Serial Monitor, default speed 115200) -#define SerialMon Serial - -// Set serial for AT commands (to the module) -// Use Hardware Serial on Mega, Leonardo, Micro -#define SerialAT Serial1 - -// or Software Serial on Uno, Nano -//#include -//SoftwareSerial SerialAT(2, 3); // RX, TX +#define TINY_GSM_USE_GPRS true +#define TINY_GSM_USE_WIFI false +// set GSM PIN, if any +#define GSM_PIN "" // Your GPRS credentials // Leave empty, if missing user or pass const char apn[] = "YourAPN"; -const char user[] = ""; -const char pass[] = ""; +const char gprsUser[] = ""; +const char gprsPass[] = ""; +const char wifiSSID[] = "YourSSID"; +const char wifiPass[] = "YourWiFiPass"; // MQTT details const char* broker = "test.mosquitto.org"; @@ -92,7 +99,6 @@ const char* topicLedStatus = "GsmClientTest/ledStatus"; StreamDebugger debugger(SerialAT, SerialMon); TinyGsm modem(debugger); #else - TinyGsm modem(SerialAT); #endif TinyGsmClient client(modem); @@ -104,7 +110,6 @@ int ledStatus = LOW; long lastReconnectAttempt = 0; void setup() { - // Set console baud rate SerialMon.begin(115200); delay(10); @@ -134,10 +139,14 @@ void setup() { SerialMon.print("Modem: "); SerialMon.println(modemInfo); - // Unlock your SIM card with a PIN - //modem.simUnlock("1234"); +#if TINY_GSM_USE_GPRS + // Unlock your SIM card with a PIN if needed + if ( GSM_PIN && modem.getSimStatus() != 3 ) { + modem.simUnlock(GSM_PIN); + } +#endif -#if TINY_GSM_USE_WIFI +#if defined TINY_GSM_USE_WIFI && defined TINY_GSM_MODEM_HAS_WIFI SerialMon.print(F("Setting SSID/password...")); if (!modem.networkConnect(wifiSSID, wifiPass)) { SerialMon.println(" fail"); @@ -153,7 +162,7 @@ void setup() { #endif SerialMon.print("Waiting for network..."); - if (!modem.waitForNetwork(240000L)) { + if (!modem.waitForNetwork()) { SerialMon.println(" fail"); delay(10000); return; diff --git a/examples/WebClient/WebClient.ino b/examples/WebClient/WebClient.ino index af26650..ee278b8 100644 --- a/examples/WebClient/WebClient.ino +++ b/examples/WebClient/WebClient.ino @@ -27,11 +27,25 @@ // #define TINY_GSM_MODEM_XBEE // #define TINY_GSM_MODEM_SEQUANS_MONARCH -// Increase RX buffer if needed -// #define TINY_GSM_RX_BUFFER 512 +// Set serial for debug console (to the Serial Monitor, default speed 115200) +#define SerialMon Serial + +// Set serial for AT commands (to the module) +// Use Hardware Serial on Mega, Leonardo, Micro +#define SerialAT Serial1 + +// or Software Serial on Uno, Nano +//#include +//SoftwareSerial SerialAT(2, 3); // RX, TX + +// Increase RX buffer to capture the entire response +// Chips without internal buffering (A6/A7, ESP8266, M590) +// need enough space in the buffer for the entire response +// else data will be lost (and the http library will fail). +#define TINY_GSM_RX_BUFFER 650 // See all AT commands, if wanted -// #define DUMP_AT_COMMANDS +//#define DUMP_AT_COMMANDS // Define the serial console for debug prints, if needed #define TINY_GSM_DEBUG SerialMon @@ -41,7 +55,7 @@ #define GSM_AUTOBAUD_MAX 115200 // Add a reception delay, if needed -// #define TINY_GSM_YIELD() { delay(1); } +//#define TINY_GSM_YIELD() { delay(2); } // Uncomment this if you want to use SSL //#define USE_SSL @@ -68,8 +82,7 @@ const char apn[] = "YourAPN"; const char gprsUser[] = ""; const char gprsPass[] = ""; -const char wifiSSID[] = "YourSSID"; -const char wifiPass[] = "SSIDpw"; +const char wifiPass[] = "YourWiFiPass"; // Server details const char server[] = "vsh.pp.ua"; @@ -132,7 +145,7 @@ void setup() { void loop() { -#if TINY_GSM_USE_WIFI +#if defined TINY_GSM_USE_WIFI && defined TINY_GSM_MODEM_HAS_WIFI SerialMon.print(F("Setting SSID/password...")); if (!modem.networkConnect(wifiSSID, wifiPass)) { SerialMon.println(" fail"); @@ -148,7 +161,7 @@ void loop() { #endif SerialMon.print("Waiting for network..."); - if (!modem.waitForNetwork(240000L)) { + if (!modem.waitForNetwork()) { SerialMon.println(" fail"); delay(10000); return; diff --git a/tools/Diagnostics/Diagnostics.ino b/tools/Diagnostics/Diagnostics.ino index ac22e48..7d116c2 100644 --- a/tools/Diagnostics/Diagnostics.ino +++ b/tools/Diagnostics/Diagnostics.ino @@ -29,36 +29,39 @@ // #define TINY_GSM_MODEM_XBEE // #define TINY_GSM_MODEM_SEQUANS_MONARCH -// Increase RX buffer if needed -#define TINY_GSM_RX_BUFFER 512 +// Set serial for debug console (to the Serial Monitor, default speed 115200) +#define SerialMon Serial + +// Set serial for AT commands (to the module) +// Use Hardware Serial on Mega, Leonardo, Micro +#define SerialAT Serial1 + +// or Software Serial on Uno, Nano +//#include +//SoftwareSerial SerialAT(2, 3); // RX, TX + +// Increase RX buffer to capture the entire response +// Chips without internal buffering (A6/A7, ESP8266, M590) +// need enough space in the buffer for the entire response +// else data will be lost (and the http library will fail). +#define TINY_GSM_RX_BUFFER 1024 // See all AT commands, if wanted -#define DUMP_AT_COMMANDS +//#define DUMP_AT_COMMANDS // Define the serial console for debug prints, if needed -#define TINY_GSM_DEBUG Serial +#define TINY_GSM_DEBUG SerialMon // Range to attempt to autobaud #define GSM_AUTOBAUD_MIN 9600 #define GSM_AUTOBAUD_MAX 115200 // Add a reception delay, if needed -#define TINY_GSM_YIELD() { delay(2); } +//#define TINY_GSM_YIELD() { delay(2); } // Uncomment this if you want to use SSL //#define USE_SSL -// Set serial for debug console (to the Serial Monitor, default speed 115200) -#define SerialMon Serial - -// Set serial for AT commands (to the module) -// Use Hardware Serial on Mega, Leonardo, Micro -#define SerialAT Serial1 - -// or Software Serial on Uno, Nano -//#include -//SoftwareSerial SerialAT(2, 3); // RX, TX - #define TINY_GSM_USE_GPRS true #define TINY_GSM_USE_WIFI false