Example change

This commit is contained in:
Sara Damiano
2019-05-30 12:27:00 -04:00
parent 08675a4a24
commit 79f4405c34
7 changed files with 191 additions and 114 deletions

View File

@@ -28,16 +28,6 @@
// #define TINY_GSM_MODEM_XBEE // #define TINY_GSM_MODEM_XBEE
// #define TINY_GSM_MODEM_SEQUANS_MONARCH // #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) // Set serial for debug console (to the Serial Monitor, default speed 115200)
#define SerialMon Serial #define SerialMon Serial
@@ -49,8 +39,18 @@
//#include <SoftwareSerial.h> //#include <SoftwareSerial.h>
//SoftwareSerial SerialAT(2, 3); // RX, TX //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_GPRS true
#define TINY_GSM_TEST_WIFI false #define TINY_GSM_TEST_WIFI false

View File

@@ -32,18 +32,10 @@
// #define TINY_GSM_MODEM_XBEE // #define TINY_GSM_MODEM_XBEE
// #define TINY_GSM_MODEM_SEQUANS_MONARCH // #define TINY_GSM_MODEM_SEQUANS_MONARCH
// Increase RX buffer if needed
#define TINY_GSM_RX_BUFFER 1024
#include <TinyGsmClient.h>
#include <CRC32.h>
// 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) // Set serial for debug console (to the Serial Monitor, default speed 115200)
#define SerialMon Serial #define SerialMon Serial
// Set serial for AT commands (to the module)
// Use Hardware Serial on Mega, Leonardo, Micro // Use Hardware Serial on Mega, Leonardo, Micro
#define SerialAT Serial1 #define SerialAT Serial1
@@ -51,12 +43,35 @@
//#include <SoftwareSerial.h> //#include <SoftwareSerial.h>
//SoftwareSerial SerialAT(2, 3); // RX, TX //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 // Your GPRS credentials
// Leave empty, if missing user or pass // Leave empty, if missing user or pass
const char apn[] = "YourAPN"; const char apn[] = "YourAPN";
const char user[] = ""; const char gprsUser[] = "";
const char pass[] = ""; const char gprsPass[] = "";
const char wifiSSID[] = "YourSSID";
const char wifiPass[] = "YourWiFiPass";
// Server details // Server details
const char server[] = "vsh.pp.ua"; const char server[] = "vsh.pp.ua";
@@ -66,6 +81,9 @@ const char resource[] = "/TinyGSM/test_1k.bin";
uint32_t knownCRC32 = 0x6f50d767; uint32_t knownCRC32 = 0x6f50d767;
uint32_t knownFileSize = 1024; // In case server does not send it uint32_t knownFileSize = 1024; // In case server does not send it
#include <TinyGsmClient.h>
#include <CRC32.h>
#ifdef DUMP_AT_COMMANDS #ifdef DUMP_AT_COMMANDS
#include <StreamDebugger.h> #include <StreamDebugger.h>
StreamDebugger debugger(SerialAT, SerialMon); StreamDebugger debugger(SerialAT, SerialMon);
@@ -87,15 +105,19 @@ void setup() {
// Restart takes quite some time // Restart takes quite some time
// To skip it, call init() instead of restart() // To skip it, call init() instead of restart()
SerialMon.println(F("Initializing modem...")); SerialMon.println("Initializing modem...");
modem.restart(); modem.restart();
String modemInfo = modem.getModemInfo(); String modemInfo = modem.getModemInfo();
SerialMon.print(F("Modem: ")); SerialMon.print("Modem: ");
SerialMon.println(modemInfo); SerialMon.println(modemInfo);
// Unlock your SIM card with a PIN #if TINY_GSM_USE_GPRS
//modem.simUnlock("1234"); // 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) { void printPercent(uint32_t readLength, uint32_t contentLength) {
@@ -110,7 +132,23 @@ void printPercent(uint32_t readLength, uint32_t contentLength) {
} }
void loop() { 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()) { if (!modem.waitForNetwork()) {
SerialMon.println(" fail"); SerialMon.println(" fail");
delay(10000); delay(10000);
@@ -118,14 +156,20 @@ void loop() {
} }
SerialMon.println(" OK"); 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(F("Connecting to "));
SerialMon.print(apn); SerialMon.print(apn);
if (!modem.gprsConnect(apn, user, pass)) { if (!modem.gprsConnect(apn, gprsUser, gprsPass)) {
SerialMon.println(" fail"); SerialMon.println(" fail");
delay(10000); delay(10000);
return; return;
} }
SerialMon.println(" OK"); SerialMon.println(" OK");
#endif
SerialMon.print(F("Connecting to ")); SerialMon.print(F("Connecting to "));
SerialMon.print(server); SerialMon.print(server);

View File

@@ -37,22 +37,6 @@
// #define TINY_GSM_MODEM_XBEE // #define TINY_GSM_MODEM_XBEE
// #define TINY_GSM_MODEM_SEQUANS_MONARCH // #define TINY_GSM_MODEM_SEQUANS_MONARCH
// 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 the serial console for debug prints, if needed
//#define TINY_GSM_DEBUG Serial
//#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) // Set serial for debug console (to the Serial Monitor, default speed 115200)
#define SerialMon Serial #define SerialMon Serial
@@ -64,6 +48,22 @@
//#include <SoftwareSerial.h> //#include <SoftwareSerial.h>
//SoftwareSerial SerialAT(2, 3); // RX, TX //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 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_GPRS true
#define TINY_GSM_USE_WIFI false #define TINY_GSM_USE_WIFI false
@@ -76,7 +76,7 @@ const char apn[] = "YourAPN";
const char gprsUser[] = ""; const char gprsUser[] = "";
const char gprsPass[] = ""; const char gprsPass[] = "";
const char wifiSSID[] = "YourSSID"; const char wifiSSID[] = "YourSSID";
const char wifiPass[] = "SSIDpw"; const char wifiPass[] = "YourWiFiPass";
// Server details // Server details
const char server[] = "vsh.pp.ua"; const char server[] = "vsh.pp.ua";
@@ -125,8 +125,12 @@ void setup() {
SerialMon.print("Modem: "); SerialMon.print("Modem: ");
SerialMon.println(modemInfo); SerialMon.println(modemInfo);
// Unlock your SIM card with a PIN #if TINY_GSM_USE_GPRS
//modem.simUnlock("1234"); // Unlock your SIM card with a PIN if needed
if ( GSM_PIN && modem.getSimStatus() != 3 ) {
modem.simUnlock(GSM_PIN);
}
#endif
} }
void loop() { void loop() {

View File

@@ -32,22 +32,6 @@
// #define TINY_GSM_MODEM_XBEE // #define TINY_GSM_MODEM_XBEE
// #define TINY_GSM_MODEM_SEQUANS_MONARCH // #define TINY_GSM_MODEM_SEQUANS_MONARCH
// 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 the serial console for debug prints, if needed
//#define TINY_GSM_DEBUG Serial
//#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) // Set serial for debug console (to the Serial Monitor, default speed 115200)
#define SerialMon Serial #define SerialMon Serial
@@ -59,6 +43,22 @@
//#include <SoftwareSerial.h> //#include <SoftwareSerial.h>
//SoftwareSerial SerialAT(2, 3); // RX, TX //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 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_GPRS true
#define TINY_GSM_USE_WIFI false #define TINY_GSM_USE_WIFI false
@@ -71,7 +71,7 @@ const char apn[] = "YourAPN";
const char gprsUser[] = ""; const char gprsUser[] = "";
const char gprsPass[] = ""; const char gprsPass[] = "";
const char wifiSSID[] = "YourSSID"; const char wifiSSID[] = "YourSSID";
const char wifiPass[] = "SSIDpw"; const char wifiPass[] = "YourWiFiPass";
// Server details // Server details
const char server[] = "vsh.pp.ua"; const char server[] = "vsh.pp.ua";
@@ -120,8 +120,12 @@ void setup() {
SerialMon.print("Modem: "); SerialMon.print("Modem: ");
SerialMon.println(modemInfo); SerialMon.println(modemInfo);
// Unlock your SIM card with a PIN #if TINY_GSM_USE_GPRS
//modem.simUnlock("1234"); // Unlock your SIM card with a PIN if needed
if ( GSM_PIN && modem.getSimStatus() != 3 ) {
modem.simUnlock(GSM_PIN);
}
#endif
if (!modem.hasSSL()) { if (!modem.hasSSL()) {
SerialMon.println(F("SSL is not supported by this modem")); SerialMon.println(F("SSL is not supported by this modem"));

View File

@@ -46,19 +46,6 @@
// #define TINY_GSM_MODEM_XBEE // #define TINY_GSM_MODEM_XBEE
// #define TINY_GSM_MODEM_SEQUANS_MONARCH // #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
// Add a reception delay, if needed
#define TINY_GSM_YIELD() { delay(2); }
// Set serial for debug console (to the Serial Monitor, default speed 115200) // Set serial for debug console (to the Serial Monitor, default speed 115200)
#define SerialMon Serial #define SerialMon Serial
@@ -70,12 +57,32 @@
//#include <SoftwareSerial.h> //#include <SoftwareSerial.h>
//SoftwareSerial SerialAT(2, 3); // RX, TX //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
// 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 // Your GPRS credentials
// Leave empty, if missing user or pass // Leave empty, if missing user or pass
const char apn[] = "YourAPN"; const char apn[] = "YourAPN";
const char user[] = ""; const char gprsUser[] = "";
const char pass[] = ""; const char gprsPass[] = "";
const char wifiSSID[] = "YourSSID";
const char wifiPass[] = "YourWiFiPass";
// MQTT details // MQTT details
const char* broker = "test.mosquitto.org"; const char* broker = "test.mosquitto.org";
@@ -92,7 +99,6 @@ const char* topicLedStatus = "GsmClientTest/ledStatus";
StreamDebugger debugger(SerialAT, SerialMon); StreamDebugger debugger(SerialAT, SerialMon);
TinyGsm modem(debugger); TinyGsm modem(debugger);
#else #else
TinyGsm modem(SerialAT); TinyGsm modem(SerialAT);
#endif #endif
TinyGsmClient client(modem); TinyGsmClient client(modem);
@@ -104,7 +110,6 @@ int ledStatus = LOW;
long lastReconnectAttempt = 0; long lastReconnectAttempt = 0;
void setup() { void setup() {
// Set console baud rate // Set console baud rate
SerialMon.begin(115200); SerialMon.begin(115200);
delay(10); delay(10);
@@ -134,10 +139,14 @@ void setup() {
SerialMon.print("Modem: "); SerialMon.print("Modem: ");
SerialMon.println(modemInfo); SerialMon.println(modemInfo);
// Unlock your SIM card with a PIN #if TINY_GSM_USE_GPRS
//modem.simUnlock("1234"); // 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...")); SerialMon.print(F("Setting SSID/password..."));
if (!modem.networkConnect(wifiSSID, wifiPass)) { if (!modem.networkConnect(wifiSSID, wifiPass)) {
SerialMon.println(" fail"); SerialMon.println(" fail");
@@ -153,7 +162,7 @@ void setup() {
#endif #endif
SerialMon.print("Waiting for network..."); SerialMon.print("Waiting for network...");
if (!modem.waitForNetwork(240000L)) { if (!modem.waitForNetwork()) {
SerialMon.println(" fail"); SerialMon.println(" fail");
delay(10000); delay(10000);
return; return;

View File

@@ -27,11 +27,25 @@
// #define TINY_GSM_MODEM_XBEE // #define TINY_GSM_MODEM_XBEE
// #define TINY_GSM_MODEM_SEQUANS_MONARCH // #define TINY_GSM_MODEM_SEQUANS_MONARCH
// Increase RX buffer if needed // Set serial for debug console (to the Serial Monitor, default speed 115200)
// #define TINY_GSM_RX_BUFFER 512 #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.h>
//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 // See all AT commands, if wanted
// #define DUMP_AT_COMMANDS //#define DUMP_AT_COMMANDS
// Define the serial console for debug prints, if needed // Define the serial console for debug prints, if needed
#define TINY_GSM_DEBUG SerialMon #define TINY_GSM_DEBUG SerialMon
@@ -41,7 +55,7 @@
#define GSM_AUTOBAUD_MAX 115200 #define GSM_AUTOBAUD_MAX 115200
// Add a reception delay, if needed // 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 // Uncomment this if you want to use SSL
//#define USE_SSL //#define USE_SSL
@@ -68,8 +82,7 @@
const char apn[] = "YourAPN"; const char apn[] = "YourAPN";
const char gprsUser[] = ""; const char gprsUser[] = "";
const char gprsPass[] = ""; const char gprsPass[] = "";
const char wifiSSID[] = "YourSSID"; const char wifiPass[] = "YourWiFiPass";
const char wifiPass[] = "SSIDpw";
// Server details // Server details
const char server[] = "vsh.pp.ua"; const char server[] = "vsh.pp.ua";
@@ -132,7 +145,7 @@ void setup() {
void loop() { 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...")); SerialMon.print(F("Setting SSID/password..."));
if (!modem.networkConnect(wifiSSID, wifiPass)) { if (!modem.networkConnect(wifiSSID, wifiPass)) {
SerialMon.println(" fail"); SerialMon.println(" fail");
@@ -148,7 +161,7 @@ void loop() {
#endif #endif
SerialMon.print("Waiting for network..."); SerialMon.print("Waiting for network...");
if (!modem.waitForNetwork(240000L)) { if (!modem.waitForNetwork()) {
SerialMon.println(" fail"); SerialMon.println(" fail");
delay(10000); delay(10000);
return; return;

View File

@@ -29,25 +29,6 @@
// #define TINY_GSM_MODEM_XBEE // #define TINY_GSM_MODEM_XBEE
// #define TINY_GSM_MODEM_SEQUANS_MONARCH // #define TINY_GSM_MODEM_SEQUANS_MONARCH
// Increase RX buffer if needed
#define TINY_GSM_RX_BUFFER 512
// See all AT commands, if wanted
#define DUMP_AT_COMMANDS
// Define the serial console for debug prints, if needed
#define TINY_GSM_DEBUG Serial
// 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); }
// Uncomment this if you want to use SSL
//#define USE_SSL
// Set serial for debug console (to the Serial Monitor, default speed 115200) // Set serial for debug console (to the Serial Monitor, default speed 115200)
#define SerialMon Serial #define SerialMon Serial
@@ -59,6 +40,28 @@
//#include <SoftwareSerial.h> //#include <SoftwareSerial.h>
//SoftwareSerial SerialAT(2, 3); // RX, TX //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
// 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); }
// Uncomment this if you want to use SSL
//#define USE_SSL
#define TINY_GSM_USE_GPRS true #define TINY_GSM_USE_GPRS true
#define TINY_GSM_USE_WIFI false #define TINY_GSM_USE_WIFI false