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

@@ -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 <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)
#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.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 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 <TinyGsmClient.h>
#include <CRC32.h>
#ifdef DUMP_AT_COMMANDS
#include <StreamDebugger.h>
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);