2020-06-25 15:56:46 +02:00
|
|
|
#include "Adafruit_FONA.h"
|
2015-06-10 06:22:36 +02:00
|
|
|
#include <Adafruit_SleepyDog.h>
|
2016-01-11 03:17:26 +01:00
|
|
|
#include <SoftwareSerial.h>
|
2015-06-10 06:22:36 +02:00
|
|
|
|
2020-06-25 15:56:46 +02:00
|
|
|
#define halt(s) \
|
|
|
|
{ \
|
|
|
|
Serial.println(F(s)); \
|
|
|
|
while (1) \
|
|
|
|
; \
|
|
|
|
}
|
2015-06-10 06:22:36 +02:00
|
|
|
|
|
|
|
extern Adafruit_FONA fona;
|
|
|
|
extern SoftwareSerial fonaSS;
|
|
|
|
|
2020-06-25 15:56:46 +02:00
|
|
|
boolean FONAconnect(const __FlashStringHelper *apn,
|
|
|
|
const __FlashStringHelper *username,
|
|
|
|
const __FlashStringHelper *password) {
|
2015-06-10 06:22:36 +02:00
|
|
|
Watchdog.reset();
|
|
|
|
|
|
|
|
Serial.println(F("Initializing FONA....(May take 3 seconds)"));
|
2020-06-25 15:56:46 +02:00
|
|
|
|
2015-06-10 06:22:36 +02:00
|
|
|
fonaSS.begin(4800); // if you're using software serial
|
2020-06-25 15:56:46 +02:00
|
|
|
|
|
|
|
if (!fona.begin(fonaSS)) { // can also try fona.begin(Serial1)
|
2015-06-10 06:22:36 +02:00
|
|
|
Serial.println(F("Couldn't find FONA"));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
fonaSS.println("AT+CMEE=2");
|
|
|
|
Serial.println(F("FONA is OK"));
|
|
|
|
Watchdog.reset();
|
|
|
|
Serial.println(F("Checking for network..."));
|
|
|
|
while (fona.getNetworkStatus() != 1) {
|
2020-06-25 15:56:46 +02:00
|
|
|
delay(500);
|
2015-06-10 06:22:36 +02:00
|
|
|
}
|
2016-01-11 03:17:26 +01:00
|
|
|
|
|
|
|
Watchdog.reset();
|
2020-06-25 15:56:46 +02:00
|
|
|
delay(5000); // wait a few seconds to stabilize connection
|
2015-06-10 06:22:36 +02:00
|
|
|
Watchdog.reset();
|
2020-06-25 15:56:46 +02:00
|
|
|
|
2015-06-10 06:22:36 +02:00
|
|
|
fona.setGPRSNetworkSettings(apn, username, password);
|
|
|
|
|
|
|
|
Serial.println(F("Disabling GPRS"));
|
|
|
|
fona.enableGPRS(false);
|
2020-06-25 15:56:46 +02:00
|
|
|
|
2015-06-10 06:22:36 +02:00
|
|
|
Watchdog.reset();
|
2020-06-25 15:56:46 +02:00
|
|
|
delay(5000); // wait a few seconds to stabilize connection
|
2016-01-11 03:17:26 +01:00
|
|
|
Watchdog.reset();
|
|
|
|
|
2015-06-10 06:22:36 +02:00
|
|
|
Serial.println(F("Enabling GPRS"));
|
|
|
|
if (!fona.enableGPRS(true)) {
|
2020-06-25 15:56:46 +02:00
|
|
|
Serial.println(F("Failed to turn GPRS on"));
|
2015-06-10 06:22:36 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
Watchdog.reset();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|