Moved begin above init, reset historic buffer sizes
This commit is contained in:
@@ -30,6 +30,9 @@
|
||||
// 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
|
||||
|
||||
// See the debugging, if wanted
|
||||
//#define TINY_GSM_DEBUG Serial
|
||||
//#define LOGGING
|
||||
@@ -40,12 +43,10 @@
|
||||
#include <TinyGsmClient.h>
|
||||
#include <ArduinoHttpClient.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
|
||||
|
||||
@@ -53,6 +54,11 @@
|
||||
//#include <SoftwareSerial.h>
|
||||
//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
|
||||
@@ -82,7 +88,15 @@ void setup() {
|
||||
// Set console baud rate
|
||||
SerialMon.begin(115200);
|
||||
delay(10);
|
||||
SerialMon.println(F("Wait..."));
|
||||
|
||||
// Set your reset, enable, power pins here
|
||||
pinMode(20, OUTPUT);
|
||||
digitalWrite(20, HIGH);
|
||||
|
||||
pinMode(23, OUTPUT);
|
||||
digitalWrite(23, HIGH);
|
||||
|
||||
SerialMon.println("Wait...");
|
||||
|
||||
// Set GSM module baud rate
|
||||
SerialAT.begin(115200);
|
||||
@@ -90,11 +104,11 @@ 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
|
||||
@@ -108,17 +122,17 @@ void setup() {
|
||||
|
||||
void loop() {
|
||||
|
||||
if (modem.hasWifi()) {
|
||||
SerialMon.print(F("Setting SSID/password..."));
|
||||
if (!modem.networkConnect(wifiSSID, wifiPass)) {
|
||||
SerialMon.println(" fail");
|
||||
delay(10000);
|
||||
return;
|
||||
}
|
||||
SerialMon.println(" OK");
|
||||
#if TINY_GSM_USE_WIFI
|
||||
SerialMon.print(F("Setting SSID/password..."));
|
||||
if (!modem.networkConnect(wifiSSID, wifiPass)) {
|
||||
SerialMon.println(" fail");
|
||||
delay(10000);
|
||||
return;
|
||||
}
|
||||
SerialMon.println(" OK");
|
||||
#endif
|
||||
|
||||
SerialMon.print(F("Waiting for network..."));
|
||||
SerialMon.print("Waiting for network...");
|
||||
if (!modem.waitForNetwork()) {
|
||||
SerialMon.println(" fail");
|
||||
delay(10000);
|
||||
@@ -126,7 +140,11 @@ void loop() {
|
||||
}
|
||||
SerialMon.println(" OK");
|
||||
|
||||
if (modem.hasGPRS()) {
|
||||
if (modem.isNetworkConnected()) {
|
||||
SerialMon.print("Network connected");
|
||||
}
|
||||
|
||||
#if TINY_GSM_USE_GPRS
|
||||
SerialMon.print(F("Connecting to "));
|
||||
SerialMon.print(apn);
|
||||
if (!modem.gprsConnect(apn, gprsUser, gprsPass)) {
|
||||
@@ -135,7 +153,7 @@ void loop() {
|
||||
return;
|
||||
}
|
||||
SerialMon.println(" OK");
|
||||
}
|
||||
#endif
|
||||
|
||||
SerialMon.print(F("Performing HTTPS GET request... "));
|
||||
http.connectionKeepAlive(); // Currently, this is needed for HTTPS
|
||||
@@ -182,8 +200,14 @@ void loop() {
|
||||
http.stop();
|
||||
SerialMon.println(F("Server disconnected"));
|
||||
|
||||
modem.gprsDisconnect();
|
||||
SerialMon.println(F("GPRS disconnected"));
|
||||
#if TINY_GSM_USE_WIFI
|
||||
modem.networkDisconnect();
|
||||
SerialMon.println(F("WiFi disconnected"));
|
||||
#endif
|
||||
#if TINY_GSM_USE_GPRS
|
||||
modem.gprsDisconnect();
|
||||
SerialMon.println(F("GPRS disconnected"));
|
||||
#endif
|
||||
|
||||
// Do nothing forevermore
|
||||
while (true) {
|
||||
|
Reference in New Issue
Block a user