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

@@ -46,19 +46,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
// Add a reception delay, if needed
#define TINY_GSM_YIELD() { delay(2); }
// Set serial for debug console (to the Serial Monitor, default speed 115200)
#define SerialMon Serial
@@ -70,12 +57,32 @@
//#include <SoftwareSerial.h>
//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
// 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;