|
@ -30,6 +30,9 @@ |
|
|
// else data will be lost (and the http library will fail).
|
|
|
// else data will be lost (and the http library will fail).
|
|
|
#define TINY_GSM_RX_BUFFER 650
|
|
|
#define TINY_GSM_RX_BUFFER 650
|
|
|
|
|
|
|
|
|
|
|
|
// See all AT commands, if wanted
|
|
|
|
|
|
//#define DUMP_AT_COMMANDS
|
|
|
|
|
|
|
|
|
// See the debugging, if wanted
|
|
|
// See the debugging, if wanted
|
|
|
//#define TINY_GSM_DEBUG Serial
|
|
|
//#define TINY_GSM_DEBUG Serial
|
|
|
//#define LOGGING
|
|
|
//#define LOGGING
|
|
@ -40,12 +43,10 @@ |
|
|
#include <TinyGsmClient.h>
|
|
|
#include <TinyGsmClient.h>
|
|
|
#include <ArduinoHttpClient.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)
|
|
|
// 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
|
|
|
|
|
|
|
|
@ -53,6 +54,11 @@ |
|
|
//#include <SoftwareSerial.h>
|
|
|
//#include <SoftwareSerial.h>
|
|
|
//SoftwareSerial SerialAT(2, 3); // RX, TX
|
|
|
//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
|
|
|
// Your GPRS credentials
|
|
|
// Leave empty, if missing user or pass
|
|
|
// Leave empty, if missing user or pass
|
|
@ -82,7 +88,15 @@ void setup() { |
|
|
// Set console baud rate
|
|
|
// Set console baud rate
|
|
|
SerialMon.begin(115200); |
|
|
SerialMon.begin(115200); |
|
|
delay(10); |
|
|
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
|
|
|
// Set GSM module baud rate
|
|
|
SerialAT.begin(115200); |
|
|
SerialAT.begin(115200); |
|
@ -90,11 +104,11 @@ 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
|
|
|
// Unlock your SIM card with a PIN
|
|
@ -108,17 +122,17 @@ void setup() { |
|
|
|
|
|
|
|
|
void loop() { |
|
|
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()) { |
|
|
if (!modem.waitForNetwork()) { |
|
|
SerialMon.println(" fail"); |
|
|
SerialMon.println(" fail"); |
|
|
delay(10000); |
|
|
delay(10000); |
|
@ -126,7 +140,11 @@ void loop() { |
|
|
} |
|
|
} |
|
|
SerialMon.println(" OK"); |
|
|
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(F("Connecting to ")); |
|
|
SerialMon.print(apn); |
|
|
SerialMon.print(apn); |
|
|
if (!modem.gprsConnect(apn, gprsUser, gprsPass)) { |
|
|
if (!modem.gprsConnect(apn, gprsUser, gprsPass)) { |
|
@ -135,7 +153,7 @@ void loop() { |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
SerialMon.println(" OK"); |
|
|
SerialMon.println(" OK"); |
|
|
} |
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
SerialMon.print(F("Performing HTTPS GET request... ")); |
|
|
SerialMon.print(F("Performing HTTPS GET request... ")); |
|
|
http.connectionKeepAlive(); // Currently, this is needed for HTTPS
|
|
|
http.connectionKeepAlive(); // Currently, this is needed for HTTPS
|
|
@ -182,8 +200,14 @@ void loop() { |
|
|
http.stop(); |
|
|
http.stop(); |
|
|
SerialMon.println(F("Server disconnected")); |
|
|
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
|
|
|
// Do nothing forevermore
|
|
|
while (true) { |
|
|
while (true) { |
|
|