From 98e33fc3e1a29eb9451fded4fcdd207e3bf27a7b Mon Sep 17 00:00:00 2001 From: ladyada Date: Mon, 20 Nov 2017 20:59:20 -0500 Subject: [PATCH 1/5] add ssl --- Adafruit_FONA.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Adafruit_FONA.cpp b/Adafruit_FONA.cpp index 036fedb..f2e442f 100644 --- a/Adafruit_FONA.cpp +++ b/Adafruit_FONA.cpp @@ -29,7 +29,7 @@ Adafruit_FONA::Adafruit_FONA(int8_t rst) apnusername = 0; apnpassword = 0; mySerial = 0; - httpsredirect = false; + httpsredirect = true; useragent = F("FONA"); ok_reply = F("OK"); } @@ -86,6 +86,9 @@ boolean Adafruit_FONA::begin(Stream &port) { // turn on hangupitude sendCheckReply(F("AT+CVHU=0"), ok_reply); + // turn on SSL support + sendCheckReply(F("AT+CVHU=0"), ok_reply); + delay(100); flushInput(); From cefa9e242238fa22bbd944d97bb2b053861521c6 Mon Sep 17 00:00:00 2001 From: ladyada Date: Mon, 27 Sep 2021 12:59:55 -0400 Subject: [PATCH 2/5] update examples to have hardwareserial work --- examples/FONA3G_setbaud/.esp32.test.skip | 0 examples/FONA3G_setbaud/.esp8266.test.skip | 0 examples/FONA3G_setbaud/.metro_m4.test.skip | 0 examples/FONA3G_setbaud/.trinket_m0.test.skip | 0 examples/FONA3G_setbaud/.zero.test.skip | 0 examples/FONA3G_setbaud/FONA3G_setbaud.ino | 19 +- examples/FONA_SMS_Response/.esp32.test.skip | 0 examples/FONA_SMS_Response/.esp8266.test.skip | 0 .../FONA_SMS_Response/.metro_m4.test.skip | 0 .../FONA_SMS_Response/.trinket_m0.test.skip | 0 examples/FONA_SMS_Response/.zero.test.skip | 0 .../FONA_SMS_Response/FONA_SMS_Response.ino | 293 +-- examples/FONAtest/.esp32.test.skip | 0 examples/FONAtest/.esp8266.test.skip | 0 examples/FONAtest/.metro_m4.test.skip | 0 examples/FONAtest/.trinket_m0.test.skip | 0 examples/FONAtest/.zero.test.skip | 0 examples/FONAtest/FONAtest.ino | 17 +- examples/FONAtest_KEY_mod/.esp32.test.skip | 0 examples/FONAtest_KEY_mod/.esp8266.test.skip | 0 examples/FONAtest_KEY_mod/.metro_m4.test.skip | 0 .../FONAtest_KEY_mod/.trinket_m0.test.skip | 0 examples/FONAtest_KEY_mod/.zero.test.skip | 0 .../FONAtest_KEY_mod/FONAtest_KEY_mod.ino | 1825 +++++++++-------- examples/GPS/.esp32.test.skip | 0 examples/GPS/.esp8266.test.skip | 0 examples/GPS/.metro_m4.test.skip | 0 examples/GPS/.trinket_m0.test.skip | 0 examples/GPS/.zero.test.skip | 0 examples/GPS/GPS.ino | 20 +- examples/IncomingCall/.esp32.test.skip | 0 examples/IncomingCall/.esp8266.test.skip | 0 examples/IncomingCall/.metro_m4.test.skip | 0 examples/IncomingCall/.trinket_m0.test.skip | 0 examples/IncomingCall/.zero.test.skip | 0 examples/IncomingCall/IncomingCall.ino | 130 +- 36 files changed, 1174 insertions(+), 1130 deletions(-) delete mode 100644 examples/FONA3G_setbaud/.esp32.test.skip delete mode 100644 examples/FONA3G_setbaud/.esp8266.test.skip delete mode 100644 examples/FONA3G_setbaud/.metro_m4.test.skip delete mode 100644 examples/FONA3G_setbaud/.trinket_m0.test.skip delete mode 100644 examples/FONA3G_setbaud/.zero.test.skip delete mode 100644 examples/FONA_SMS_Response/.esp32.test.skip delete mode 100644 examples/FONA_SMS_Response/.esp8266.test.skip delete mode 100644 examples/FONA_SMS_Response/.metro_m4.test.skip delete mode 100644 examples/FONA_SMS_Response/.trinket_m0.test.skip delete mode 100644 examples/FONA_SMS_Response/.zero.test.skip delete mode 100644 examples/FONAtest/.esp32.test.skip delete mode 100644 examples/FONAtest/.esp8266.test.skip delete mode 100644 examples/FONAtest/.metro_m4.test.skip delete mode 100644 examples/FONAtest/.trinket_m0.test.skip delete mode 100644 examples/FONAtest/.zero.test.skip delete mode 100644 examples/FONAtest_KEY_mod/.esp32.test.skip delete mode 100644 examples/FONAtest_KEY_mod/.esp8266.test.skip delete mode 100644 examples/FONAtest_KEY_mod/.metro_m4.test.skip delete mode 100644 examples/FONAtest_KEY_mod/.trinket_m0.test.skip delete mode 100644 examples/FONAtest_KEY_mod/.zero.test.skip delete mode 100644 examples/GPS/.esp32.test.skip delete mode 100644 examples/GPS/.esp8266.test.skip delete mode 100644 examples/GPS/.metro_m4.test.skip delete mode 100644 examples/GPS/.trinket_m0.test.skip delete mode 100644 examples/GPS/.zero.test.skip delete mode 100644 examples/IncomingCall/.esp32.test.skip delete mode 100644 examples/IncomingCall/.esp8266.test.skip delete mode 100644 examples/IncomingCall/.metro_m4.test.skip delete mode 100644 examples/IncomingCall/.trinket_m0.test.skip delete mode 100644 examples/IncomingCall/.zero.test.skip diff --git a/examples/FONA3G_setbaud/.esp32.test.skip b/examples/FONA3G_setbaud/.esp32.test.skip deleted file mode 100644 index e69de29..0000000 diff --git a/examples/FONA3G_setbaud/.esp8266.test.skip b/examples/FONA3G_setbaud/.esp8266.test.skip deleted file mode 100644 index e69de29..0000000 diff --git a/examples/FONA3G_setbaud/.metro_m4.test.skip b/examples/FONA3G_setbaud/.metro_m4.test.skip deleted file mode 100644 index e69de29..0000000 diff --git a/examples/FONA3G_setbaud/.trinket_m0.test.skip b/examples/FONA3G_setbaud/.trinket_m0.test.skip deleted file mode 100644 index e69de29..0000000 diff --git a/examples/FONA3G_setbaud/.zero.test.skip b/examples/FONA3G_setbaud/.zero.test.skip deleted file mode 100644 index e69de29..0000000 diff --git a/examples/FONA3G_setbaud/FONA3G_setbaud.ino b/examples/FONA3G_setbaud/FONA3G_setbaud.ino index b0be4c5..3d0fa0c 100644 --- a/examples/FONA3G_setbaud/FONA3G_setbaud.ino +++ b/examples/FONA3G_setbaud/FONA3G_setbaud.ino @@ -19,22 +19,29 @@ #include "Adafruit_FONA.h" -#define FONA_RX 2 -#define FONA_TX 3 #define FONA_RST 4 // this is a large buffer for replies char replybuffer[255]; -// We default to using software serial. If you want to use hardware serial +#if (defined(__AVR__) || defined(ESP8266)) && !defined(__AVR_ATmega2560__) +// For UNO and others without hardware serial, +// we default to using software serial. If you want to use hardware serial // (because softserial isnt supported) comment out the following three lines // and uncomment the HardwareSerial line #include + +#define FONA_RX 2 +#define FONA_TX 3 + SoftwareSerial fonaSS = SoftwareSerial(FONA_TX, FONA_RX); SoftwareSerial *fonaSerial = &fonaSS; -// Hardware serial is also possible! -// HardwareSerial *fonaSerial = &Serial1; +#else +// On Leonardo/M0/etc, others with hardware serial, use hardware serial! +HardwareSerial *fonaSerial = &Serial1; + +#endif Adafruit_FONA fona = Adafruit_FONA(FONA_RST); @@ -74,4 +81,4 @@ void setup() { } void loop() { -} \ No newline at end of file +} diff --git a/examples/FONA_SMS_Response/.esp32.test.skip b/examples/FONA_SMS_Response/.esp32.test.skip deleted file mode 100644 index e69de29..0000000 diff --git a/examples/FONA_SMS_Response/.esp8266.test.skip b/examples/FONA_SMS_Response/.esp8266.test.skip deleted file mode 100644 index e69de29..0000000 diff --git a/examples/FONA_SMS_Response/.metro_m4.test.skip b/examples/FONA_SMS_Response/.metro_m4.test.skip deleted file mode 100644 index e69de29..0000000 diff --git a/examples/FONA_SMS_Response/.trinket_m0.test.skip b/examples/FONA_SMS_Response/.trinket_m0.test.skip deleted file mode 100644 index e69de29..0000000 diff --git a/examples/FONA_SMS_Response/.zero.test.skip b/examples/FONA_SMS_Response/.zero.test.skip deleted file mode 100644 index e69de29..0000000 diff --git a/examples/FONA_SMS_Response/FONA_SMS_Response.ino b/examples/FONA_SMS_Response/FONA_SMS_Response.ino index 411651f..8c4854d 100644 --- a/examples/FONA_SMS_Response/FONA_SMS_Response.ino +++ b/examples/FONA_SMS_Response/FONA_SMS_Response.ino @@ -1,143 +1,150 @@ -/*************************************************** - This is an example for our Adafruit FONA Cellular Module - - Designed specifically to work with the Adafruit FONA - ----> http://www.adafruit.com/products/1946 - ----> http://www.adafruit.com/products/1963 - ----> http://www.adafruit.com/products/2468 - ----> http://www.adafruit.com/products/2542 - - These cellular modules use TTL Serial to communicate, 2 pins are - required to interface - Adafruit invests time and resources providing this open source code, - please support Adafruit and open-source hardware by purchasing - products from Adafruit! - - Written by Limor Fried/Ladyada for Adafruit Industries. - BSD license, all text above must be included in any redistribution - ****************************************************/ - -/* -THIS CODE IS STILL IN PROGRESS! - -Open up the serial console on the Arduino at 115200 baud to interact with FONA - - -This code will receive an SMS, identify the sender's phone number, and automatically send a response - -*/ - -#include "Adafruit_FONA.h" - -#define FONA_RX 2 -#define FONA_TX 3 -#define FONA_RST 4 - -// this is a large buffer for replies -char replybuffer[255]; - -// We default to using software serial. If you want to use hardware serial -// (because softserial isnt supported) comment out the following three lines -// and uncomment the HardwareSerial line -#include -SoftwareSerial fonaSS = SoftwareSerial(FONA_TX, FONA_RX); -SoftwareSerial *fonaSerial = &fonaSS; - -// Hardware serial is also possible! -// HardwareSerial *fonaSerial = &Serial1; - -// Use this for FONA 800 and 808s -Adafruit_FONA fona = Adafruit_FONA(FONA_RST); -// Use this one for FONA 3G -//Adafruit_FONA_3G fona = Adafruit_FONA_3G(FONA_RST); - -uint8_t readline(char *buff, uint8_t maxbuff, uint16_t timeout = 0); - -void setup() { - while (!Serial); - - Serial.begin(115200); - Serial.println(F("FONA SMS caller ID test")); - Serial.println(F("Initializing....(May take 3 seconds)")); - - // make it slow so its easy to read! - fonaSerial->begin(4800); - if (! fona.begin(*fonaSerial)) { - Serial.println(F("Couldn't find FONA")); - while(1); - } - Serial.println(F("FONA is OK")); - - // Print SIM card IMEI number. - char imei[16] = {0}; // MUST use a 16 character buffer for IMEI! - uint8_t imeiLen = fona.getIMEI(imei); - if (imeiLen > 0) { - Serial.print("SIM card IMEI: "); Serial.println(imei); - } - - fonaSerial->print("AT+CNMI=2,1\r\n"); //set up the FONA to send a +CMTI notification when an SMS is received - - Serial.println("FONA Ready"); -} - - -char fonaNotificationBuffer[64]; //for notifications from the FONA -char smsBuffer[250]; - -void loop() { - - char* bufPtr = fonaNotificationBuffer; //handy buffer pointer - - if (fona.available()) //any data available from the FONA? - { - int slot = 0; //this will be the slot number of the SMS - int charCount = 0; - //Read the notification into fonaInBuffer - do { - *bufPtr = fona.read(); - Serial.write(*bufPtr); - delay(1); - } while ((*bufPtr++ != '\n') && (fona.available()) && (++charCount < (sizeof(fonaNotificationBuffer)-1))); - - //Add a terminal NULL to the notification string - *bufPtr = 0; - - //Scan the notification string for an SMS received notification. - // If it's an SMS message, we'll get the slot number in 'slot' - if (1 == sscanf(fonaNotificationBuffer, "+CMTI: " FONA_PREF_SMS_STORAGE ",%d", &slot)) { - Serial.print("slot: "); Serial.println(slot); - - char callerIDbuffer[32]; //we'll store the SMS sender number in here - - // Retrieve SMS sender address/phone number. - if (! fona.getSMSSender(slot, callerIDbuffer, 31)) { - Serial.println("Didn't find SMS message in slot!"); - } - Serial.print(F("FROM: ")); Serial.println(callerIDbuffer); - - // Retrieve SMS value. - uint16_t smslen; - if (fona.readSMS(slot, smsBuffer, 250, &smslen)) { // pass in buffer and max len! - Serial.println(smsBuffer); - } - - //Send back an automatic response - Serial.println("Sending reponse..."); - if (!fona.sendSMS(callerIDbuffer, "Hey, I got your text!")) { - Serial.println(F("Failed")); - } else { - Serial.println(F("Sent!")); - } - - // delete the original msg after it is processed - // otherwise, we will fill up all the slots - // and then we won't be able to receive SMS anymore - if (fona.deleteSMS(slot)) { - Serial.println(F("OK!")); - } else { - Serial.print(F("Couldn't delete SMS in slot ")); Serial.println(slot); - fona.print(F("AT+CMGD=?\r\n")); - } - } - } -} +/*************************************************** + This is an example for our Adafruit FONA Cellular Module + + Designed specifically to work with the Adafruit FONA + ----> http://www.adafruit.com/products/1946 + ----> http://www.adafruit.com/products/1963 + ----> http://www.adafruit.com/products/2468 + ----> http://www.adafruit.com/products/2542 + + These cellular modules use TTL Serial to communicate, 2 pins are + required to interface + Adafruit invests time and resources providing this open source code, + please support Adafruit and open-source hardware by purchasing + products from Adafruit! + + Written by Limor Fried/Ladyada for Adafruit Industries. + BSD license, all text above must be included in any redistribution + ****************************************************/ + +/* +THIS CODE IS STILL IN PROGRESS! + +Open up the serial console on the Arduino at 115200 baud to interact with FONA + + +This code will receive an SMS, identify the sender's phone number, and automatically send a response + +*/ + +#include "Adafruit_FONA.h" + +#define FONA_RST 4 + +// this is a large buffer for replies +char replybuffer[255]; + +#if (defined(__AVR__) || defined(ESP8266)) && !defined(__AVR_ATmega2560__) +// For UNO and others without hardware serial, +// we default to using software serial. If you want to use hardware serial +// (because softserial isnt supported) comment out the following three lines +// and uncomment the HardwareSerial line +#include + +#define FONA_RX 2 +#define FONA_TX 3 + +SoftwareSerial fonaSS = SoftwareSerial(FONA_TX, FONA_RX); +SoftwareSerial *fonaSerial = &fonaSS; + +#else +// On Leonardo/M0/etc, others with hardware serial, use hardware serial! +HardwareSerial *fonaSerial = &Serial1; + +#endif + +// Use this for FONA 800 and 808s +Adafruit_FONA fona = Adafruit_FONA(FONA_RST); +// Use this one for FONA 3G +//Adafruit_FONA_3G fona = Adafruit_FONA_3G(FONA_RST); + +uint8_t readline(char *buff, uint8_t maxbuff, uint16_t timeout = 0); + +void setup() { + while (!Serial); + + Serial.begin(115200); + Serial.println(F("FONA SMS caller ID test")); + Serial.println(F("Initializing....(May take 3 seconds)")); + + // make it slow so its easy to read! + fonaSerial->begin(4800); + if (! fona.begin(*fonaSerial)) { + Serial.println(F("Couldn't find FONA")); + while(1); + } + Serial.println(F("FONA is OK")); + + // Print SIM card IMEI number. + char imei[16] = {0}; // MUST use a 16 character buffer for IMEI! + uint8_t imeiLen = fona.getIMEI(imei); + if (imeiLen > 0) { + Serial.print("SIM card IMEI: "); Serial.println(imei); + } + + fonaSerial->print("AT+CNMI=2,1\r\n"); //set up the FONA to send a +CMTI notification when an SMS is received + + Serial.println("FONA Ready"); +} + + +char fonaNotificationBuffer[64]; //for notifications from the FONA +char smsBuffer[250]; + +void loop() { + + char* bufPtr = fonaNotificationBuffer; //handy buffer pointer + + if (fona.available()) //any data available from the FONA? + { + int slot = 0; //this will be the slot number of the SMS + int charCount = 0; + //Read the notification into fonaInBuffer + do { + *bufPtr = fona.read(); + Serial.write(*bufPtr); + delay(1); + } while ((*bufPtr++ != '\n') && (fona.available()) && (++charCount < (sizeof(fonaNotificationBuffer)-1))); + + //Add a terminal NULL to the notification string + *bufPtr = 0; + + //Scan the notification string for an SMS received notification. + // If it's an SMS message, we'll get the slot number in 'slot' + if (1 == sscanf(fonaNotificationBuffer, "+CMTI: " FONA_PREF_SMS_STORAGE ",%d", &slot)) { + Serial.print("slot: "); Serial.println(slot); + + char callerIDbuffer[32]; //we'll store the SMS sender number in here + + // Retrieve SMS sender address/phone number. + if (! fona.getSMSSender(slot, callerIDbuffer, 31)) { + Serial.println("Didn't find SMS message in slot!"); + } + Serial.print(F("FROM: ")); Serial.println(callerIDbuffer); + + // Retrieve SMS value. + uint16_t smslen; + if (fona.readSMS(slot, smsBuffer, 250, &smslen)) { // pass in buffer and max len! + Serial.println(smsBuffer); + } + + //Send back an automatic response + Serial.println("Sending reponse..."); + if (!fona.sendSMS(callerIDbuffer, "Hey, I got your text!")) { + Serial.println(F("Failed")); + } else { + Serial.println(F("Sent!")); + } + + // delete the original msg after it is processed + // otherwise, we will fill up all the slots + // and then we won't be able to receive SMS anymore + if (fona.deleteSMS(slot)) { + Serial.println(F("OK!")); + } else { + Serial.print(F("Couldn't delete SMS in slot ")); Serial.println(slot); + fona.print(F("AT+CMGD=?\r\n")); + } + } + } +} diff --git a/examples/FONAtest/.esp32.test.skip b/examples/FONAtest/.esp32.test.skip deleted file mode 100644 index e69de29..0000000 diff --git a/examples/FONAtest/.esp8266.test.skip b/examples/FONAtest/.esp8266.test.skip deleted file mode 100644 index e69de29..0000000 diff --git a/examples/FONAtest/.metro_m4.test.skip b/examples/FONAtest/.metro_m4.test.skip deleted file mode 100644 index e69de29..0000000 diff --git a/examples/FONAtest/.trinket_m0.test.skip b/examples/FONAtest/.trinket_m0.test.skip deleted file mode 100644 index e69de29..0000000 diff --git a/examples/FONAtest/.zero.test.skip b/examples/FONAtest/.zero.test.skip deleted file mode 100644 index e69de29..0000000 diff --git a/examples/FONAtest/FONAtest.ino b/examples/FONAtest/FONAtest.ino index 3f669f9..fb12178 100644 --- a/examples/FONAtest/FONAtest.ino +++ b/examples/FONAtest/FONAtest.ino @@ -27,22 +27,29 @@ the commented section below at the end of the setup() function. */ #include "Adafruit_FONA.h" -#define FONA_RX 2 -#define FONA_TX 3 #define FONA_RST 4 // this is a large buffer for replies char replybuffer[255]; -// We default to using software serial. If you want to use hardware serial +#if (defined(__AVR__) || defined(ESP8266)) && !defined(__AVR_ATmega2560__) +// For UNO and others without hardware serial, +// we default to using software serial. If you want to use hardware serial // (because softserial isnt supported) comment out the following three lines // and uncomment the HardwareSerial line #include + +#define FONA_RX 2 +#define FONA_TX 3 + SoftwareSerial fonaSS = SoftwareSerial(FONA_TX, FONA_RX); SoftwareSerial *fonaSerial = &fonaSS; -// Hardware serial is also possible! -// HardwareSerial *fonaSerial = &Serial1; +#else +// On Leonardo/M0/etc, others with hardware serial, use hardware serial! +HardwareSerial *fonaSerial = &Serial1; + +#endif // Use this for FONA 800 and 808s Adafruit_FONA fona = Adafruit_FONA(FONA_RST); diff --git a/examples/FONAtest_KEY_mod/.esp32.test.skip b/examples/FONAtest_KEY_mod/.esp32.test.skip deleted file mode 100644 index e69de29..0000000 diff --git a/examples/FONAtest_KEY_mod/.esp8266.test.skip b/examples/FONAtest_KEY_mod/.esp8266.test.skip deleted file mode 100644 index e69de29..0000000 diff --git a/examples/FONAtest_KEY_mod/.metro_m4.test.skip b/examples/FONAtest_KEY_mod/.metro_m4.test.skip deleted file mode 100644 index e69de29..0000000 diff --git a/examples/FONAtest_KEY_mod/.trinket_m0.test.skip b/examples/FONAtest_KEY_mod/.trinket_m0.test.skip deleted file mode 100644 index e69de29..0000000 diff --git a/examples/FONAtest_KEY_mod/.zero.test.skip b/examples/FONAtest_KEY_mod/.zero.test.skip deleted file mode 100644 index e69de29..0000000 diff --git a/examples/FONAtest_KEY_mod/FONAtest_KEY_mod.ino b/examples/FONAtest_KEY_mod/FONAtest_KEY_mod.ino index 775c72d..d4debcb 100644 --- a/examples/FONAtest_KEY_mod/FONAtest_KEY_mod.ino +++ b/examples/FONAtest_KEY_mod/FONAtest_KEY_mod.ino @@ -1,909 +1,916 @@ -/*************************************************** - This is an example for our Adafruit FONA Cellular Module - - Designed specifically to work with the Adafruit FONA - ----> http://www.adafruit.com/products/1946 - ----> http://www.adafruit.com/products/1963 - ----> http://www.adafruit.com/products/2468 - ----> http://www.adafruit.com/products/2542 - - These cellular modules use TTL Serial to communicate, 2 pins are - required to interface - Adafruit invests time and resources providing this open source code, - please support Adafruit and open-source hardware by purchasing - products from Adafruit! - - Written by Limor Fried/Ladyada for Adafruit Industries. - BSD license, all text above must be included in any redistribution - ****************************************************/ - -/* -THIS CODE IS STILL IN PROGRESS! - -Open up the serial console on the Arduino at 115200 baud to interact with FONA - -Note that if you need to set a GPRS APN, username, and password scroll down to -the commented section below at the end of the setup() function. -*/ -#include "Adafruit_FONA.h" - -#define FONA_RX 2 -#define FONA_TX 3 -#define FONA_RST 4 -#define FONA_KEY 8 - -// this is a large buffer for replies -char replybuffer[255]; - -// We default to using software serial. If you want to use hardware serial -// (because softserial isnt supported) comment out the following three lines -// and uncomment the HardwareSerial line -#include -SoftwareSerial fonaSS = SoftwareSerial(FONA_TX, FONA_RX); -SoftwareSerial *fonaSerial = &fonaSS; - -// Hardware serial is also possible! -// HardwareSerial *fonaSerial = &Serial1; - -// Use this for FONA 800 and 808s -Adafruit_FONA fona = Adafruit_FONA(FONA_RST); -// Use this one for FONA 3G -//Adafruit_FONA_3G fona = Adafruit_FONA_3G(FONA_RST); - -uint8_t readline(char *buff, uint8_t maxbuff, uint16_t timeout = 0); - -uint8_t type; - -void setup() { - while (!Serial); - - pinMode(FONA_KEY, OUTPUT); - digitalWrite(FONA_KEY, HIGH); - - Serial.begin(115200); - Serial.println(F("FONA basic test")); - Serial.println(F("Initializing....(May take 3 seconds)")); - - fonaSerial->begin(4800); - if (! fona.begin(*fonaSerial)) { - Serial.println(F("Couldn't find FONA")); - while (1); - } - type = fona.type(); - Serial.println(F("FONA is OK")); - Serial.print(F("Found ")); - switch (type) { - case FONA800L: - Serial.println(F("FONA 800L")); break; - case FONA800H: - Serial.println(F("FONA 800H")); break; - case FONA808_V1: - Serial.println(F("FONA 808 (v1)")); break; - case FONA808_V2: - Serial.println(F("FONA 808 (v2)")); break; - case FONA3G_A: - Serial.println(F("FONA 3G (American)")); break; - case FONA3G_E: - Serial.println(F("FONA 3G (European)")); break; - default: - Serial.println(F("???")); break; - } - - // Print module IMEI number. - char imei[15] = {0}; // MUST use a 16 character buffer for IMEI! - uint8_t imeiLen = fona.getIMEI(imei); - if (imeiLen > 0) { - Serial.print("Module IMEI: "); Serial.println(imei); - } - - // Optionally configure a GPRS APN, username, and password. - // You might need to do this to access your network's GPRS/data - // network. Contact your provider for the exact APN, username, - // and password values. Username and password are optional and - // can be removed, but APN is required. - //fona.setGPRSNetworkSettings(F("your APN"), F("your username"), F("your password")); - - // Optionally configure HTTP gets to follow redirects over SSL. - // Default is not to follow SSL redirects, however if you uncomment - // the following line then redirects over SSL will be followed. - //fona.setHTTPSRedirect(true); - - printMenu(); -} - -void printMenu(void) { - Serial.println(F("-------------------------------------")); - Serial.println(F("[?] Print this menu")); - Serial.println(F("[a] read the ADC 2.8V max (FONA800 & 808)")); - Serial.println(F("[b] read the Battery V and % charged")); - Serial.println(F("[C] read the SIM CCID")); - Serial.println(F("[U] Unlock SIM with PIN code")); - Serial.println(F("[i] read RSSI")); - Serial.println(F("[n] get Network status")); - Serial.println(F("[v] set audio Volume")); - Serial.println(F("[V] get Volume")); - Serial.println(F("[H] set Headphone audio (FONA800 & 808)")); - Serial.println(F("[e] set External audio (FONA800 & 808)")); - Serial.println(F("[T] play audio Tone")); - Serial.println(F("[P] PWM/Buzzer out (FONA800 & 808)")); - Serial.println(F("[Z] power off with Key")); - Serial.println(F("[z] power on with Key")); - - // FM (SIM800 only!) - Serial.println(F("[f] tune FM radio (FONA800)")); - Serial.println(F("[F] turn off FM (FONA800)")); - Serial.println(F("[m] set FM volume (FONA800)")); - Serial.println(F("[M] get FM volume (FONA800)")); - Serial.println(F("[q] get FM station signal level (FONA800)")); - - // Phone - Serial.println(F("[c] make phone Call")); - Serial.println(F("[A] get call status")); - Serial.println(F("[h] Hang up phone")); - Serial.println(F("[p] Pick up phone")); - - // SMS - Serial.println(F("[N] Number of SMSs")); - Serial.println(F("[r] Read SMS #")); - Serial.println(F("[R] Read All SMS")); - Serial.println(F("[d] Delete SMS #")); - Serial.println(F("[s] Send SMS")); - Serial.println(F("[u] Send USSD")); - - // Time - Serial.println(F("[y] Enable network time sync (FONA 800 & 808)")); - Serial.println(F("[Y] Enable NTP time sync (GPRS FONA 800 & 808)")); - Serial.println(F("[t] Get network time")); - - // GPRS - Serial.println(F("[G] Enable GPRS")); - Serial.println(F("[g] Disable GPRS")); - Serial.println(F("[l] Query GSMLOC (GPRS)")); - Serial.println(F("[w] Read webpage (GPRS)")); - Serial.println(F("[W] Post to website (GPRS)")); - - // GPS - if ((type == FONA3G_A) || (type == FONA3G_E) || (type == FONA808_V1) || (type == FONA808_V2)) { - Serial.println(F("[O] Turn GPS on (FONA 808 & 3G)")); - Serial.println(F("[o] Turn GPS off (FONA 808 & 3G)")); - Serial.println(F("[L] Query GPS location (FONA 808 & 3G)")); - if (type == FONA808_V1) { - Serial.println(F("[x] GPS fix status (FONA808 v1 only)")); - } - Serial.println(F("[E] Raw NMEA out (FONA808)")); - } - - Serial.println(F("[S] create Serial passthru tunnel")); - Serial.println(F("-------------------------------------")); - Serial.println(F("")); - -} -void loop() { - Serial.print(F("FONA> ")); - while (! Serial.available() ) { - if (fona.available()) { - Serial.write(fona.read()); - } - } - - char command = Serial.read(); - Serial.println(command); - - - switch (command) { - case '?': { - printMenu(); - break; - } - - case 'Z': { - digitalWrite(FONA_KEY, LOW); - delay(2000); - digitalWrite(FONA_KEY, HIGH); - delay(3000); - break; - } - case 'z': { - digitalWrite(FONA_KEY, LOW); - delay(2000); - digitalWrite(FONA_KEY, HIGH); - delay(3000); - if (! fona.begin(*fonaSerial)) { - Serial.println(F("Couldn't find FONA")); - } - break; - } - case 'a': { - // read the ADC - uint16_t adc; - if (! fona.getADCVoltage(&adc)) { - Serial.println(F("Failed to read ADC")); - } else { - Serial.print(F("ADC = ")); Serial.print(adc); Serial.println(F(" mV")); - } - break; - } - - case 'b': { - // read the battery voltage and percentage - uint16_t vbat; - if (! fona.getBattVoltage(&vbat)) { - Serial.println(F("Failed to read Batt")); - } else { - Serial.print(F("VBat = ")); Serial.print(vbat); Serial.println(F(" mV")); - } - - - if (! fona.getBattPercent(&vbat)) { - Serial.println(F("Failed to read Batt")); - } else { - Serial.print(F("VPct = ")); Serial.print(vbat); Serial.println(F("%")); - } - - break; - } - - case 'U': { - // Unlock the SIM with a PIN code - char PIN[5]; - flushSerial(); - Serial.println(F("Enter 4-digit PIN")); - readline(PIN, 3); - Serial.println(PIN); - Serial.print(F("Unlocking SIM card: ")); - if (! fona.unlockSIM(PIN)) { - Serial.println(F("Failed")); - } else { - Serial.println(F("OK!")); - } - break; - } - - case 'C': { - // read the CCID - fona.getSIMCCID(replybuffer); // make sure replybuffer is at least 21 bytes! - Serial.print(F("SIM CCID = ")); Serial.println(replybuffer); - break; - } - - case 'i': { - // read the RSSI - uint8_t n = fona.getRSSI(); - int8_t r; - - Serial.print(F("RSSI = ")); Serial.print(n); Serial.print(": "); - if (n == 0) r = -115; - if (n == 1) r = -111; - if (n == 31) r = -52; - if ((n >= 2) && (n <= 30)) { - r = map(n, 2, 30, -110, -54); - } - Serial.print(r); Serial.println(F(" dBm")); - - break; - } - - case 'n': { - // read the network/cellular status - uint8_t n = fona.getNetworkStatus(); - Serial.print(F("Network status ")); - Serial.print(n); - Serial.print(F(": ")); - if (n == 0) Serial.println(F("Not registered")); - if (n == 1) Serial.println(F("Registered (home)")); - if (n == 2) Serial.println(F("Not registered (searching)")); - if (n == 3) Serial.println(F("Denied")); - if (n == 4) Serial.println(F("Unknown")); - if (n == 5) Serial.println(F("Registered roaming")); - break; - } - - /*** Audio ***/ - case 'v': { - // set volume - flushSerial(); - if ( (type == FONA3G_A) || (type == FONA3G_E) ) { - Serial.print(F("Set Vol [0-8] ")); - } else { - Serial.print(F("Set Vol % [0-100] ")); - } - uint8_t vol = readnumber(); - Serial.println(); - if (! fona.setVolume(vol)) { - Serial.println(F("Failed")); - } else { - Serial.println(F("OK!")); - } - break; - } - - case 'V': { - uint8_t v = fona.getVolume(); - Serial.print(v); - if ( (type == FONA3G_A) || (type == FONA3G_E) ) { - Serial.println(" / 8"); - } else { - Serial.println("%"); - } - break; - } - - case 'H': { - // Set Headphone output - if (! fona.setAudio(FONA_HEADSETAUDIO)) { - Serial.println(F("Failed")); - } else { - Serial.println(F("OK!")); - } - fona.setMicVolume(FONA_HEADSETAUDIO, 15); - break; - } - case 'e': { - // Set External output - if (! fona.setAudio(FONA_EXTAUDIO)) { - Serial.println(F("Failed")); - } else { - Serial.println(F("OK!")); - } - - fona.setMicVolume(FONA_EXTAUDIO, 10); - break; - } - - case 'T': { - // play tone - flushSerial(); - Serial.print(F("Play tone #")); - uint8_t kittone = readnumber(); - Serial.println(); - // play for 1 second (1000 ms) - if (! fona.playToolkitTone(kittone, 1000)) { - Serial.println(F("Failed")); - } else { - Serial.println(F("OK!")); - } - break; - } - - /*** FM Radio ***/ - - case 'f': { - // get freq - flushSerial(); - Serial.print(F("FM Freq (eg 1011 == 101.1 MHz): ")); - uint16_t station = readnumber(); - Serial.println(); - // FM radio ON using headset - if (fona.FMradio(true, FONA_HEADSETAUDIO)) { - Serial.println(F("Opened")); - } - if (! fona.tuneFMradio(station)) { - Serial.println(F("Failed")); - } else { - Serial.println(F("Tuned")); - } - break; - } - case 'F': { - // FM radio off - if (! fona.FMradio(false)) { - Serial.println(F("Failed")); - } else { - Serial.println(F("OK!")); - } - break; - } - case 'm': { - // Set FM volume. - flushSerial(); - Serial.print(F("Set FM Vol [0-6]:")); - uint8_t vol = readnumber(); - Serial.println(); - if (!fona.setFMVolume(vol)) { - Serial.println(F("Failed")); - } else { - Serial.println(F("OK!")); - } - break; - } - case 'M': { - // Get FM volume. - uint8_t fmvol = fona.getFMVolume(); - if (fmvol < 0) { - Serial.println(F("Failed")); - } else { - Serial.print(F("FM volume: ")); - Serial.println(fmvol, DEC); - } - break; - } - case 'q': { - // Get FM station signal level (in decibels). - flushSerial(); - Serial.print(F("FM Freq (eg 1011 == 101.1 MHz): ")); - uint16_t station = readnumber(); - Serial.println(); - int8_t level = fona.getFMSignalLevel(station); - if (level < 0) { - Serial.println(F("Failed! Make sure FM radio is on (tuned to station).")); - } else { - Serial.print(F("Signal level (dB): ")); - Serial.println(level, DEC); - } - break; - } - - /*** PWM ***/ - - case 'P': { - // PWM Buzzer output @ 2KHz max - flushSerial(); - Serial.print(F("PWM Freq, 0 = Off, (1-2000): ")); - uint16_t freq = readnumber(); - Serial.println(); - if (! fona.setPWM(freq)) { - Serial.println(F("Failed")); - } else { - Serial.println(F("OK!")); - } - break; - } - - /*** Call ***/ - case 'c': { - // call a phone! - char number[30]; - flushSerial(); - Serial.print(F("Call #")); - readline(number, 30); - Serial.println(); - Serial.print(F("Calling ")); Serial.println(number); - if (!fona.callPhone(number)) { - Serial.println(F("Failed")); - } else { - Serial.println(F("Sent!")); - } - - break; - } - case 'A': { - // get call status - int8_t callstat = fona.getCallStatus(); - switch (callstat) { - case 0: Serial.println(F("Ready")); break; - case 1: Serial.println(F("Could not get status")); break; - case 3: Serial.println(F("Ringing (incoming)")); break; - case 4: Serial.println(F("Ringing/in progress (outgoing)")); break; - default: Serial.println(F("Unknown")); break; - } - break; - } - - case 'h': { - // hang up! - if (! fona.hangUp()) { - Serial.println(F("Failed")); - } else { - Serial.println(F("OK!")); - } - break; - } - - case 'p': { - // pick up! - if (! fona.pickUp()) { - Serial.println(F("Failed")); - } else { - Serial.println(F("OK!")); - } - break; - } - - /*** SMS ***/ - - case 'N': { - // read the number of SMS's! - int8_t smsnum = fona.getNumSMS(); - if (smsnum < 0) { - Serial.println(F("Could not read # SMS")); - } else { - Serial.print(smsnum); - Serial.println(F(" SMS's on SIM card!")); - } - break; - } - case 'r': { - // read an SMS - flushSerial(); - Serial.print(F("Read #")); - uint8_t smsn = readnumber(); - Serial.print(F("\n\rReading SMS #")); Serial.println(smsn); - - // Retrieve SMS sender address/phone number. - if (! fona.getSMSSender(smsn, replybuffer, 250)) { - Serial.println("Failed!"); - break; - } - Serial.print(F("FROM: ")); Serial.println(replybuffer); - - // Retrieve SMS value. - uint16_t smslen; - if (! fona.readSMS(smsn, replybuffer, 250, &smslen)) { // pass in buffer and max len! - Serial.println("Failed!"); - break; - } - Serial.print(F("***** SMS #")); Serial.print(smsn); - Serial.print(" ("); Serial.print(smslen); Serial.println(F(") bytes *****")); - Serial.println(replybuffer); - Serial.println(F("*****")); - - break; - } - case 'R': { - // read all SMS - int8_t smsnum = fona.getNumSMS(); - uint16_t smslen; - int8_t smsn; - - if ( (type == FONA3G_A) || (type == FONA3G_E) ) { - smsn = 0; // zero indexed - smsnum--; - } else { - smsn = 1; // 1 indexed - } - - for ( ; smsn <= smsnum; smsn++) { - Serial.print(F("\n\rReading SMS #")); Serial.println(smsn); - if (!fona.readSMS(smsn, replybuffer, 250, &smslen)) { // pass in buffer and max len! - Serial.println(F("Failed!")); - break; - } - // if the length is zero, its a special case where the index number is higher - // so increase the max we'll look at! - if (smslen == 0) { - Serial.println(F("[empty slot]")); - smsnum++; - continue; - } - - Serial.print(F("***** SMS #")); Serial.print(smsn); - Serial.print(" ("); Serial.print(smslen); Serial.println(F(") bytes *****")); - Serial.println(replybuffer); - Serial.println(F("*****")); - } - break; - } - - case 'd': { - // delete an SMS - flushSerial(); - Serial.print(F("Delete #")); - uint8_t smsn = readnumber(); - - Serial.print(F("\n\rDeleting SMS #")); Serial.println(smsn); - if (fona.deleteSMS(smsn)) { - Serial.println(F("OK!")); - } else { - Serial.println(F("Couldn't delete")); - } - break; - } - - case 's': { - // send an SMS! - char sendto[21], message[141]; - flushSerial(); - Serial.print(F("Send to #")); - readline(sendto, 20); - Serial.println(sendto); - Serial.print(F("Type out one-line message (140 char): ")); - readline(message, 140); - Serial.println(message); - if (!fona.sendSMS(sendto, message)) { - Serial.println(F("Failed")); - } else { - Serial.println(F("Sent!")); - } - - break; - } - - case 'u': { - // send a USSD! - char message[141]; - flushSerial(); - Serial.print(F("Type out one-line message (140 char): ")); - readline(message, 140); - Serial.println(message); - - uint16_t ussdlen; - if (!fona.sendUSSD(message, replybuffer, 250, &ussdlen)) { // pass in buffer and max len! - Serial.println(F("Failed")); - } else { - Serial.println(F("Sent!")); - Serial.print(F("***** USSD Reply")); - Serial.print(" ("); Serial.print(ussdlen); Serial.println(F(") bytes *****")); - Serial.println(replybuffer); - Serial.println(F("*****")); - } - } - - /*** Time ***/ - - case 'y': { - // enable network time sync - if (!fona.enableNetworkTimeSync(true)) - Serial.println(F("Failed to enable")); - break; - } - - case 'Y': { - // enable NTP time sync - if (!fona.enableNTPTimeSync(true, F("pool.ntp.org"))) - Serial.println(F("Failed to enable")); - break; - } - - case 't': { - // read the time - char buffer[23]; - - fona.getTime(buffer, 23); // make sure replybuffer is at least 23 bytes! - Serial.print(F("Time = ")); Serial.println(buffer); - break; - } - - - /*********************************** GPS (SIM808 only) */ - - case 'o': { - // turn GPS off - if (!fona.enableGPS(false)) - Serial.println(F("Failed to turn off")); - break; - } - case 'O': { - // turn GPS on - if (!fona.enableGPS(true)) - Serial.println(F("Failed to turn on")); - break; - } - case 'x': { - int8_t stat; - // check GPS fix - stat = fona.GPSstatus(); - if (stat < 0) - Serial.println(F("Failed to query")); - if (stat == 0) Serial.println(F("GPS off")); - if (stat == 1) Serial.println(F("No fix")); - if (stat == 2) Serial.println(F("2D fix")); - if (stat == 3) Serial.println(F("3D fix")); - break; - } - - case 'L': { - // check for GPS location - char gpsdata[120]; - fona.getGPS(0, gpsdata, 120); - if (type == FONA808_V1) - Serial.println(F("Reply in format: mode,longitude,latitude,altitude,utctime(yyyymmddHHMMSS),ttff,satellites,speed,course")); - else - Serial.println(F("Reply in format: mode,fixstatus,utctime(yyyymmddHHMMSS),latitude,longitude,altitude,speed,course,fixmode,reserved1,HDOP,PDOP,VDOP,reserved2,view_satellites,used_satellites,reserved3,C/N0max,HPA,VPA")); - Serial.println(gpsdata); - - break; - } - - case 'E': { - flushSerial(); - if (type == FONA808_V1) { - Serial.print(F("GPS NMEA output sentences (0 = off, 34 = RMC+GGA, 255 = all)")); - } else { - Serial.print(F("On (1) or Off (0)? ")); - } - uint8_t nmeaout = readnumber(); - - // turn on NMEA output - fona.enableGPSNMEA(nmeaout); - - break; - } - - /*********************************** GPRS */ - - case 'g': { - // turn GPRS off - if (!fona.enableGPRS(false)) - Serial.println(F("Failed to turn off")); - break; - } - case 'G': { - // turn GPRS on - if (!fona.enableGPRS(true)) - Serial.println(F("Failed to turn on")); - break; - } - case 'l': { - // check for GSMLOC (requires GPRS) - uint16_t returncode; - - if (!fona.getGSMLoc(&returncode, replybuffer, 250)) - Serial.println(F("Failed!")); - if (returncode == 0) { - Serial.println(replybuffer); - } else { - Serial.print(F("Fail code #")); Serial.println(returncode); - } - - break; - } - case 'w': { - // read website URL - uint16_t statuscode; - int16_t length; - char url[80]; - - flushSerial(); - Serial.println(F("NOTE: in beta! Use small webpages to read!")); - Serial.println(F("URL to read (e.g. www.adafruit.com/testwifi/index.html):")); - Serial.print(F("http://")); readline(url, 79); - Serial.println(url); - - Serial.println(F("****")); - if (!fona.HTTP_GET_start(url, &statuscode, (uint16_t *)&length)) { - Serial.println("Failed!"); - break; - } - while (length > 0) { - while (fona.available()) { - char c = fona.read(); - - // Serial.write is too slow, we'll write directly to Serial register! -#if defined(__AVR_ATmega328P__) || defined(__AVR_ATmega168__) - loop_until_bit_is_set(UCSR0A, UDRE0); /* Wait until data register empty. */ - UDR0 = c; -#else - Serial.write(c); -#endif - length--; - if (! length) break; - } - } - Serial.println(F("\n****")); - fona.HTTP_GET_end(); - break; - } - - case 'W': { - // Post data to website - uint16_t statuscode; - int16_t length; - char url[80]; - char data[80]; - - flushSerial(); - Serial.println(F("NOTE: in beta! Use simple websites to post!")); - Serial.println(F("URL to post (e.g. httpbin.org/post):")); - Serial.print(F("http://")); readline(url, 79); - Serial.println(url); - Serial.println(F("Data to post (e.g. \"foo\" or \"{\"simple\":\"json\"}\"):")); - readline(data, 79); - Serial.println(data); - - Serial.println(F("****")); - if (!fona.HTTP_POST_start(url, F("text/plain"), (uint8_t *) data, strlen(data), &statuscode, (uint16_t *)&length)) { - Serial.println("Failed!"); - break; - } - while (length > 0) { - while (fona.available()) { - char c = fona.read(); - -#if defined(__AVR_ATmega328P__) || defined(__AVR_ATmega168__) - loop_until_bit_is_set(UCSR0A, UDRE0); /* Wait until data register empty. */ - UDR0 = c; -#else - Serial.write(c); -#endif - - length--; - if (! length) break; - } - } - Serial.println(F("\n****")); - fona.HTTP_POST_end(); - break; - } - /*****************************************/ - - case 'S': { - Serial.println(F("Creating SERIAL TUBE")); - while (1) { - while (Serial.available()) { - delay(1); - fona.write(Serial.read()); - } - if (fona.available()) { - Serial.write(fona.read()); - } - } - break; - } - - default: { - Serial.println(F("Unknown command")); - printMenu(); - break; - } - } - // flush input - flushSerial(); - while (fona.available()) { - Serial.write(fona.read()); - } - -} - -void flushSerial() { - while (Serial.available()) - Serial.read(); -} - -char readBlocking() { - while (!Serial.available()); - return Serial.read(); -} -uint16_t readnumber() { - uint16_t x = 0; - char c; - while (! isdigit(c = readBlocking())) { - //Serial.print(c); - } - Serial.print(c); - x = c - '0'; - while (isdigit(c = readBlocking())) { - Serial.print(c); - x *= 10; - x += c - '0'; - } - return x; -} - -uint8_t readline(char *buff, uint8_t maxbuff, uint16_t timeout) { - uint16_t buffidx = 0; - boolean timeoutvalid = true; - if (timeout == 0) timeoutvalid = false; - - while (true) { - if (buffidx > maxbuff) { - //Serial.println(F("SPACE")); - break; - } - - while (Serial.available()) { - char c = Serial.read(); - - //Serial.print(c, HEX); Serial.print("#"); Serial.println(c); - - if (c == '\r') continue; - if (c == 0xA) { - if (buffidx == 0) // the first 0x0A is ignored - continue; - - timeout = 0; // the second 0x0A is the end of the line - timeoutvalid = true; - break; - } - buff[buffidx] = c; - buffidx++; - } - - if (timeoutvalid && timeout == 0) { - //Serial.println(F("TIMEOUT")); - break; - } - delay(1); - } - buff[buffidx] = 0; // null term - return buffidx; -} +/*************************************************** + This is an example for our Adafruit FONA Cellular Module + + Designed specifically to work with the Adafruit FONA + ----> http://www.adafruit.com/products/1946 + ----> http://www.adafruit.com/products/1963 + ----> http://www.adafruit.com/products/2468 + ----> http://www.adafruit.com/products/2542 + + These cellular modules use TTL Serial to communicate, 2 pins are + required to interface + Adafruit invests time and resources providing this open source code, + please support Adafruit and open-source hardware by purchasing + products from Adafruit! + + Written by Limor Fried/Ladyada for Adafruit Industries. + BSD license, all text above must be included in any redistribution + ****************************************************/ + +/* +THIS CODE IS STILL IN PROGRESS! + +Open up the serial console on the Arduino at 115200 baud to interact with FONA + +Note that if you need to set a GPRS APN, username, and password scroll down to +the commented section below at the end of the setup() function. +*/ +#include "Adafruit_FONA.h" + +#define FONA_RST 4 +#define FONA_KEY 8 + +// this is a large buffer for replies +char replybuffer[255]; + +#if (defined(__AVR__) || defined(ESP8266)) && !defined(__AVR_ATmega2560__) +// For UNO and others without hardware serial, +// we default to using software serial. If you want to use hardware serial +// (because softserial isnt supported) comment out the following three lines +// and uncomment the HardwareSerial line +#include + +#define FONA_RX 2 +#define FONA_TX 3 + +SoftwareSerial fonaSS = SoftwareSerial(FONA_TX, FONA_RX); +SoftwareSerial *fonaSerial = &fonaSS; + +#else +// On Leonardo/M0/etc, others with hardware serial, use hardware serial! +HardwareSerial *fonaSerial = &Serial1; + +#endif + +// Use this for FONA 800 and 808s +Adafruit_FONA fona = Adafruit_FONA(FONA_RST); +// Use this one for FONA 3G +//Adafruit_FONA_3G fona = Adafruit_FONA_3G(FONA_RST); + +uint8_t readline(char *buff, uint8_t maxbuff, uint16_t timeout = 0); + +uint8_t type; + +void setup() { + while (!Serial); + + pinMode(FONA_KEY, OUTPUT); + digitalWrite(FONA_KEY, HIGH); + + Serial.begin(115200); + Serial.println(F("FONA basic test")); + Serial.println(F("Initializing....(May take 3 seconds)")); + + fonaSerial->begin(4800); + if (! fona.begin(*fonaSerial)) { + Serial.println(F("Couldn't find FONA")); + while (1); + } + type = fona.type(); + Serial.println(F("FONA is OK")); + Serial.print(F("Found ")); + switch (type) { + case FONA800L: + Serial.println(F("FONA 800L")); break; + case FONA800H: + Serial.println(F("FONA 800H")); break; + case FONA808_V1: + Serial.println(F("FONA 808 (v1)")); break; + case FONA808_V2: + Serial.println(F("FONA 808 (v2)")); break; + case FONA3G_A: + Serial.println(F("FONA 3G (American)")); break; + case FONA3G_E: + Serial.println(F("FONA 3G (European)")); break; + default: + Serial.println(F("???")); break; + } + + // Print module IMEI number. + char imei[15] = {0}; // MUST use a 16 character buffer for IMEI! + uint8_t imeiLen = fona.getIMEI(imei); + if (imeiLen > 0) { + Serial.print("Module IMEI: "); Serial.println(imei); + } + + // Optionally configure a GPRS APN, username, and password. + // You might need to do this to access your network's GPRS/data + // network. Contact your provider for the exact APN, username, + // and password values. Username and password are optional and + // can be removed, but APN is required. + //fona.setGPRSNetworkSettings(F("your APN"), F("your username"), F("your password")); + + // Optionally configure HTTP gets to follow redirects over SSL. + // Default is not to follow SSL redirects, however if you uncomment + // the following line then redirects over SSL will be followed. + //fona.setHTTPSRedirect(true); + + printMenu(); +} + +void printMenu(void) { + Serial.println(F("-------------------------------------")); + Serial.println(F("[?] Print this menu")); + Serial.println(F("[a] read the ADC 2.8V max (FONA800 & 808)")); + Serial.println(F("[b] read the Battery V and % charged")); + Serial.println(F("[C] read the SIM CCID")); + Serial.println(F("[U] Unlock SIM with PIN code")); + Serial.println(F("[i] read RSSI")); + Serial.println(F("[n] get Network status")); + Serial.println(F("[v] set audio Volume")); + Serial.println(F("[V] get Volume")); + Serial.println(F("[H] set Headphone audio (FONA800 & 808)")); + Serial.println(F("[e] set External audio (FONA800 & 808)")); + Serial.println(F("[T] play audio Tone")); + Serial.println(F("[P] PWM/Buzzer out (FONA800 & 808)")); + Serial.println(F("[Z] power off with Key")); + Serial.println(F("[z] power on with Key")); + + // FM (SIM800 only!) + Serial.println(F("[f] tune FM radio (FONA800)")); + Serial.println(F("[F] turn off FM (FONA800)")); + Serial.println(F("[m] set FM volume (FONA800)")); + Serial.println(F("[M] get FM volume (FONA800)")); + Serial.println(F("[q] get FM station signal level (FONA800)")); + + // Phone + Serial.println(F("[c] make phone Call")); + Serial.println(F("[A] get call status")); + Serial.println(F("[h] Hang up phone")); + Serial.println(F("[p] Pick up phone")); + + // SMS + Serial.println(F("[N] Number of SMSs")); + Serial.println(F("[r] Read SMS #")); + Serial.println(F("[R] Read All SMS")); + Serial.println(F("[d] Delete SMS #")); + Serial.println(F("[s] Send SMS")); + Serial.println(F("[u] Send USSD")); + + // Time + Serial.println(F("[y] Enable network time sync (FONA 800 & 808)")); + Serial.println(F("[Y] Enable NTP time sync (GPRS FONA 800 & 808)")); + Serial.println(F("[t] Get network time")); + + // GPRS + Serial.println(F("[G] Enable GPRS")); + Serial.println(F("[g] Disable GPRS")); + Serial.println(F("[l] Query GSMLOC (GPRS)")); + Serial.println(F("[w] Read webpage (GPRS)")); + Serial.println(F("[W] Post to website (GPRS)")); + + // GPS + if ((type == FONA3G_A) || (type == FONA3G_E) || (type == FONA808_V1) || (type == FONA808_V2)) { + Serial.println(F("[O] Turn GPS on (FONA 808 & 3G)")); + Serial.println(F("[o] Turn GPS off (FONA 808 & 3G)")); + Serial.println(F("[L] Query GPS location (FONA 808 & 3G)")); + if (type == FONA808_V1) { + Serial.println(F("[x] GPS fix status (FONA808 v1 only)")); + } + Serial.println(F("[E] Raw NMEA out (FONA808)")); + } + + Serial.println(F("[S] create Serial passthru tunnel")); + Serial.println(F("-------------------------------------")); + Serial.println(F("")); + +} +void loop() { + Serial.print(F("FONA> ")); + while (! Serial.available() ) { + if (fona.available()) { + Serial.write(fona.read()); + } + } + + char command = Serial.read(); + Serial.println(command); + + + switch (command) { + case '?': { + printMenu(); + break; + } + + case 'Z': { + digitalWrite(FONA_KEY, LOW); + delay(2000); + digitalWrite(FONA_KEY, HIGH); + delay(3000); + break; + } + case 'z': { + digitalWrite(FONA_KEY, LOW); + delay(2000); + digitalWrite(FONA_KEY, HIGH); + delay(3000); + if (! fona.begin(*fonaSerial)) { + Serial.println(F("Couldn't find FONA")); + } + break; + } + case 'a': { + // read the ADC + uint16_t adc; + if (! fona.getADCVoltage(&adc)) { + Serial.println(F("Failed to read ADC")); + } else { + Serial.print(F("ADC = ")); Serial.print(adc); Serial.println(F(" mV")); + } + break; + } + + case 'b': { + // read the battery voltage and percentage + uint16_t vbat; + if (! fona.getBattVoltage(&vbat)) { + Serial.println(F("Failed to read Batt")); + } else { + Serial.print(F("VBat = ")); Serial.print(vbat); Serial.println(F(" mV")); + } + + + if (! fona.getBattPercent(&vbat)) { + Serial.println(F("Failed to read Batt")); + } else { + Serial.print(F("VPct = ")); Serial.print(vbat); Serial.println(F("%")); + } + + break; + } + + case 'U': { + // Unlock the SIM with a PIN code + char PIN[5]; + flushSerial(); + Serial.println(F("Enter 4-digit PIN")); + readline(PIN, 3); + Serial.println(PIN); + Serial.print(F("Unlocking SIM card: ")); + if (! fona.unlockSIM(PIN)) { + Serial.println(F("Failed")); + } else { + Serial.println(F("OK!")); + } + break; + } + + case 'C': { + // read the CCID + fona.getSIMCCID(replybuffer); // make sure replybuffer is at least 21 bytes! + Serial.print(F("SIM CCID = ")); Serial.println(replybuffer); + break; + } + + case 'i': { + // read the RSSI + uint8_t n = fona.getRSSI(); + int8_t r; + + Serial.print(F("RSSI = ")); Serial.print(n); Serial.print(": "); + if (n == 0) r = -115; + if (n == 1) r = -111; + if (n == 31) r = -52; + if ((n >= 2) && (n <= 30)) { + r = map(n, 2, 30, -110, -54); + } + Serial.print(r); Serial.println(F(" dBm")); + + break; + } + + case 'n': { + // read the network/cellular status + uint8_t n = fona.getNetworkStatus(); + Serial.print(F("Network status ")); + Serial.print(n); + Serial.print(F(": ")); + if (n == 0) Serial.println(F("Not registered")); + if (n == 1) Serial.println(F("Registered (home)")); + if (n == 2) Serial.println(F("Not registered (searching)")); + if (n == 3) Serial.println(F("Denied")); + if (n == 4) Serial.println(F("Unknown")); + if (n == 5) Serial.println(F("Registered roaming")); + break; + } + + /*** Audio ***/ + case 'v': { + // set volume + flushSerial(); + if ( (type == FONA3G_A) || (type == FONA3G_E) ) { + Serial.print(F("Set Vol [0-8] ")); + } else { + Serial.print(F("Set Vol % [0-100] ")); + } + uint8_t vol = readnumber(); + Serial.println(); + if (! fona.setVolume(vol)) { + Serial.println(F("Failed")); + } else { + Serial.println(F("OK!")); + } + break; + } + + case 'V': { + uint8_t v = fona.getVolume(); + Serial.print(v); + if ( (type == FONA3G_A) || (type == FONA3G_E) ) { + Serial.println(" / 8"); + } else { + Serial.println("%"); + } + break; + } + + case 'H': { + // Set Headphone output + if (! fona.setAudio(FONA_HEADSETAUDIO)) { + Serial.println(F("Failed")); + } else { + Serial.println(F("OK!")); + } + fona.setMicVolume(FONA_HEADSETAUDIO, 15); + break; + } + case 'e': { + // Set External output + if (! fona.setAudio(FONA_EXTAUDIO)) { + Serial.println(F("Failed")); + } else { + Serial.println(F("OK!")); + } + + fona.setMicVolume(FONA_EXTAUDIO, 10); + break; + } + + case 'T': { + // play tone + flushSerial(); + Serial.print(F("Play tone #")); + uint8_t kittone = readnumber(); + Serial.println(); + // play for 1 second (1000 ms) + if (! fona.playToolkitTone(kittone, 1000)) { + Serial.println(F("Failed")); + } else { + Serial.println(F("OK!")); + } + break; + } + + /*** FM Radio ***/ + + case 'f': { + // get freq + flushSerial(); + Serial.print(F("FM Freq (eg 1011 == 101.1 MHz): ")); + uint16_t station = readnumber(); + Serial.println(); + // FM radio ON using headset + if (fona.FMradio(true, FONA_HEADSETAUDIO)) { + Serial.println(F("Opened")); + } + if (! fona.tuneFMradio(station)) { + Serial.println(F("Failed")); + } else { + Serial.println(F("Tuned")); + } + break; + } + case 'F': { + // FM radio off + if (! fona.FMradio(false)) { + Serial.println(F("Failed")); + } else { + Serial.println(F("OK!")); + } + break; + } + case 'm': { + // Set FM volume. + flushSerial(); + Serial.print(F("Set FM Vol [0-6]:")); + uint8_t vol = readnumber(); + Serial.println(); + if (!fona.setFMVolume(vol)) { + Serial.println(F("Failed")); + } else { + Serial.println(F("OK!")); + } + break; + } + case 'M': { + // Get FM volume. + uint8_t fmvol = fona.getFMVolume(); + if (fmvol < 0) { + Serial.println(F("Failed")); + } else { + Serial.print(F("FM volume: ")); + Serial.println(fmvol, DEC); + } + break; + } + case 'q': { + // Get FM station signal level (in decibels). + flushSerial(); + Serial.print(F("FM Freq (eg 1011 == 101.1 MHz): ")); + uint16_t station = readnumber(); + Serial.println(); + int8_t level = fona.getFMSignalLevel(station); + if (level < 0) { + Serial.println(F("Failed! Make sure FM radio is on (tuned to station).")); + } else { + Serial.print(F("Signal level (dB): ")); + Serial.println(level, DEC); + } + break; + } + + /*** PWM ***/ + + case 'P': { + // PWM Buzzer output @ 2KHz max + flushSerial(); + Serial.print(F("PWM Freq, 0 = Off, (1-2000): ")); + uint16_t freq = readnumber(); + Serial.println(); + if (! fona.setPWM(freq)) { + Serial.println(F("Failed")); + } else { + Serial.println(F("OK!")); + } + break; + } + + /*** Call ***/ + case 'c': { + // call a phone! + char number[30]; + flushSerial(); + Serial.print(F("Call #")); + readline(number, 30); + Serial.println(); + Serial.print(F("Calling ")); Serial.println(number); + if (!fona.callPhone(number)) { + Serial.println(F("Failed")); + } else { + Serial.println(F("Sent!")); + } + + break; + } + case 'A': { + // get call status + int8_t callstat = fona.getCallStatus(); + switch (callstat) { + case 0: Serial.println(F("Ready")); break; + case 1: Serial.println(F("Could not get status")); break; + case 3: Serial.println(F("Ringing (incoming)")); break; + case 4: Serial.println(F("Ringing/in progress (outgoing)")); break; + default: Serial.println(F("Unknown")); break; + } + break; + } + + case 'h': { + // hang up! + if (! fona.hangUp()) { + Serial.println(F("Failed")); + } else { + Serial.println(F("OK!")); + } + break; + } + + case 'p': { + // pick up! + if (! fona.pickUp()) { + Serial.println(F("Failed")); + } else { + Serial.println(F("OK!")); + } + break; + } + + /*** SMS ***/ + + case 'N': { + // read the number of SMS's! + int8_t smsnum = fona.getNumSMS(); + if (smsnum < 0) { + Serial.println(F("Could not read # SMS")); + } else { + Serial.print(smsnum); + Serial.println(F(" SMS's on SIM card!")); + } + break; + } + case 'r': { + // read an SMS + flushSerial(); + Serial.print(F("Read #")); + uint8_t smsn = readnumber(); + Serial.print(F("\n\rReading SMS #")); Serial.println(smsn); + + // Retrieve SMS sender address/phone number. + if (! fona.getSMSSender(smsn, replybuffer, 250)) { + Serial.println("Failed!"); + break; + } + Serial.print(F("FROM: ")); Serial.println(replybuffer); + + // Retrieve SMS value. + uint16_t smslen; + if (! fona.readSMS(smsn, replybuffer, 250, &smslen)) { // pass in buffer and max len! + Serial.println("Failed!"); + break; + } + Serial.print(F("***** SMS #")); Serial.print(smsn); + Serial.print(" ("); Serial.print(smslen); Serial.println(F(") bytes *****")); + Serial.println(replybuffer); + Serial.println(F("*****")); + + break; + } + case 'R': { + // read all SMS + int8_t smsnum = fona.getNumSMS(); + uint16_t smslen; + int8_t smsn; + + if ( (type == FONA3G_A) || (type == FONA3G_E) ) { + smsn = 0; // zero indexed + smsnum--; + } else { + smsn = 1; // 1 indexed + } + + for ( ; smsn <= smsnum; smsn++) { + Serial.print(F("\n\rReading SMS #")); Serial.println(smsn); + if (!fona.readSMS(smsn, replybuffer, 250, &smslen)) { // pass in buffer and max len! + Serial.println(F("Failed!")); + break; + } + // if the length is zero, its a special case where the index number is higher + // so increase the max we'll look at! + if (smslen == 0) { + Serial.println(F("[empty slot]")); + smsnum++; + continue; + } + + Serial.print(F("***** SMS #")); Serial.print(smsn); + Serial.print(" ("); Serial.print(smslen); Serial.println(F(") bytes *****")); + Serial.println(replybuffer); + Serial.println(F("*****")); + } + break; + } + + case 'd': { + // delete an SMS + flushSerial(); + Serial.print(F("Delete #")); + uint8_t smsn = readnumber(); + + Serial.print(F("\n\rDeleting SMS #")); Serial.println(smsn); + if (fona.deleteSMS(smsn)) { + Serial.println(F("OK!")); + } else { + Serial.println(F("Couldn't delete")); + } + break; + } + + case 's': { + // send an SMS! + char sendto[21], message[141]; + flushSerial(); + Serial.print(F("Send to #")); + readline(sendto, 20); + Serial.println(sendto); + Serial.print(F("Type out one-line message (140 char): ")); + readline(message, 140); + Serial.println(message); + if (!fona.sendSMS(sendto, message)) { + Serial.println(F("Failed")); + } else { + Serial.println(F("Sent!")); + } + + break; + } + + case 'u': { + // send a USSD! + char message[141]; + flushSerial(); + Serial.print(F("Type out one-line message (140 char): ")); + readline(message, 140); + Serial.println(message); + + uint16_t ussdlen; + if (!fona.sendUSSD(message, replybuffer, 250, &ussdlen)) { // pass in buffer and max len! + Serial.println(F("Failed")); + } else { + Serial.println(F("Sent!")); + Serial.print(F("***** USSD Reply")); + Serial.print(" ("); Serial.print(ussdlen); Serial.println(F(") bytes *****")); + Serial.println(replybuffer); + Serial.println(F("*****")); + } + } + + /*** Time ***/ + + case 'y': { + // enable network time sync + if (!fona.enableNetworkTimeSync(true)) + Serial.println(F("Failed to enable")); + break; + } + + case 'Y': { + // enable NTP time sync + if (!fona.enableNTPTimeSync(true, F("pool.ntp.org"))) + Serial.println(F("Failed to enable")); + break; + } + + case 't': { + // read the time + char buffer[23]; + + fona.getTime(buffer, 23); // make sure replybuffer is at least 23 bytes! + Serial.print(F("Time = ")); Serial.println(buffer); + break; + } + + + /*********************************** GPS (SIM808 only) */ + + case 'o': { + // turn GPS off + if (!fona.enableGPS(false)) + Serial.println(F("Failed to turn off")); + break; + } + case 'O': { + // turn GPS on + if (!fona.enableGPS(true)) + Serial.println(F("Failed to turn on")); + break; + } + case 'x': { + int8_t stat; + // check GPS fix + stat = fona.GPSstatus(); + if (stat < 0) + Serial.println(F("Failed to query")); + if (stat == 0) Serial.println(F("GPS off")); + if (stat == 1) Serial.println(F("No fix")); + if (stat == 2) Serial.println(F("2D fix")); + if (stat == 3) Serial.println(F("3D fix")); + break; + } + + case 'L': { + // check for GPS location + char gpsdata[120]; + fona.getGPS(0, gpsdata, 120); + if (type == FONA808_V1) + Serial.println(F("Reply in format: mode,longitude,latitude,altitude,utctime(yyyymmddHHMMSS),ttff,satellites,speed,course")); + else + Serial.println(F("Reply in format: mode,fixstatus,utctime(yyyymmddHHMMSS),latitude,longitude,altitude,speed,course,fixmode,reserved1,HDOP,PDOP,VDOP,reserved2,view_satellites,used_satellites,reserved3,C/N0max,HPA,VPA")); + Serial.println(gpsdata); + + break; + } + + case 'E': { + flushSerial(); + if (type == FONA808_V1) { + Serial.print(F("GPS NMEA output sentences (0 = off, 34 = RMC+GGA, 255 = all)")); + } else { + Serial.print(F("On (1) or Off (0)? ")); + } + uint8_t nmeaout = readnumber(); + + // turn on NMEA output + fona.enableGPSNMEA(nmeaout); + + break; + } + + /*********************************** GPRS */ + + case 'g': { + // turn GPRS off + if (!fona.enableGPRS(false)) + Serial.println(F("Failed to turn off")); + break; + } + case 'G': { + // turn GPRS on + if (!fona.enableGPRS(true)) + Serial.println(F("Failed to turn on")); + break; + } + case 'l': { + // check for GSMLOC (requires GPRS) + uint16_t returncode; + + if (!fona.getGSMLoc(&returncode, replybuffer, 250)) + Serial.println(F("Failed!")); + if (returncode == 0) { + Serial.println(replybuffer); + } else { + Serial.print(F("Fail code #")); Serial.println(returncode); + } + + break; + } + case 'w': { + // read website URL + uint16_t statuscode; + int16_t length; + char url[80]; + + flushSerial(); + Serial.println(F("NOTE: in beta! Use small webpages to read!")); + Serial.println(F("URL to read (e.g. www.adafruit.com/testwifi/index.html):")); + Serial.print(F("http://")); readline(url, 79); + Serial.println(url); + + Serial.println(F("****")); + if (!fona.HTTP_GET_start(url, &statuscode, (uint16_t *)&length)) { + Serial.println("Failed!"); + break; + } + while (length > 0) { + while (fona.available()) { + char c = fona.read(); + + // Serial.write is too slow, we'll write directly to Serial register! +#if defined(__AVR_ATmega328P__) || defined(__AVR_ATmega168__) + loop_until_bit_is_set(UCSR0A, UDRE0); /* Wait until data register empty. */ + UDR0 = c; +#else + Serial.write(c); +#endif + length--; + if (! length) break; + } + } + Serial.println(F("\n****")); + fona.HTTP_GET_end(); + break; + } + + case 'W': { + // Post data to website + uint16_t statuscode; + int16_t length; + char url[80]; + char data[80]; + + flushSerial(); + Serial.println(F("NOTE: in beta! Use simple websites to post!")); + Serial.println(F("URL to post (e.g. httpbin.org/post):")); + Serial.print(F("http://")); readline(url, 79); + Serial.println(url); + Serial.println(F("Data to post (e.g. \"foo\" or \"{\"simple\":\"json\"}\"):")); + readline(data, 79); + Serial.println(data); + + Serial.println(F("****")); + if (!fona.HTTP_POST_start(url, F("text/plain"), (uint8_t *) data, strlen(data), &statuscode, (uint16_t *)&length)) { + Serial.println("Failed!"); + break; + } + while (length > 0) { + while (fona.available()) { + char c = fona.read(); + +#if defined(__AVR_ATmega328P__) || defined(__AVR_ATmega168__) + loop_until_bit_is_set(UCSR0A, UDRE0); /* Wait until data register empty. */ + UDR0 = c; +#else + Serial.write(c); +#endif + + length--; + if (! length) break; + } + } + Serial.println(F("\n****")); + fona.HTTP_POST_end(); + break; + } + /*****************************************/ + + case 'S': { + Serial.println(F("Creating SERIAL TUBE")); + while (1) { + while (Serial.available()) { + delay(1); + fona.write(Serial.read()); + } + if (fona.available()) { + Serial.write(fona.read()); + } + } + break; + } + + default: { + Serial.println(F("Unknown command")); + printMenu(); + break; + } + } + // flush input + flushSerial(); + while (fona.available()) { + Serial.write(fona.read()); + } + +} + +void flushSerial() { + while (Serial.available()) + Serial.read(); +} + +char readBlocking() { + while (!Serial.available()); + return Serial.read(); +} +uint16_t readnumber() { + uint16_t x = 0; + char c; + while (! isdigit(c = readBlocking())) { + //Serial.print(c); + } + Serial.print(c); + x = c - '0'; + while (isdigit(c = readBlocking())) { + Serial.print(c); + x *= 10; + x += c - '0'; + } + return x; +} + +uint8_t readline(char *buff, uint8_t maxbuff, uint16_t timeout) { + uint16_t buffidx = 0; + boolean timeoutvalid = true; + if (timeout == 0) timeoutvalid = false; + + while (true) { + if (buffidx > maxbuff) { + //Serial.println(F("SPACE")); + break; + } + + while (Serial.available()) { + char c = Serial.read(); + + //Serial.print(c, HEX); Serial.print("#"); Serial.println(c); + + if (c == '\r') continue; + if (c == 0xA) { + if (buffidx == 0) // the first 0x0A is ignored + continue; + + timeout = 0; // the second 0x0A is the end of the line + timeoutvalid = true; + break; + } + buff[buffidx] = c; + buffidx++; + } + + if (timeoutvalid && timeout == 0) { + //Serial.println(F("TIMEOUT")); + break; + } + delay(1); + } + buff[buffidx] = 0; // null term + return buffidx; +} diff --git a/examples/GPS/.esp32.test.skip b/examples/GPS/.esp32.test.skip deleted file mode 100644 index e69de29..0000000 diff --git a/examples/GPS/.esp8266.test.skip b/examples/GPS/.esp8266.test.skip deleted file mode 100644 index e69de29..0000000 diff --git a/examples/GPS/.metro_m4.test.skip b/examples/GPS/.metro_m4.test.skip deleted file mode 100644 index e69de29..0000000 diff --git a/examples/GPS/.trinket_m0.test.skip b/examples/GPS/.trinket_m0.test.skip deleted file mode 100644 index e69de29..0000000 diff --git a/examples/GPS/.zero.test.skip b/examples/GPS/.zero.test.skip deleted file mode 100644 index e69de29..0000000 diff --git a/examples/GPS/GPS.ino b/examples/GPS/GPS.ino index cce63d5..0ac775d 100644 --- a/examples/GPS/GPS.ino +++ b/examples/GPS/GPS.ino @@ -15,19 +15,29 @@ #include "Adafruit_FONA.h" // standard pins for the shield, adjust as necessary -#define FONA_RX 2 -#define FONA_TX 3 #define FONA_RST 4 -// We default to using software serial. If you want to use hardware serial +// this is a large buffer for replies +char replybuffer[255]; + +#if (defined(__AVR__) || defined(ESP8266)) && !defined(__AVR_ATmega2560__) +// For UNO and others without hardware serial, +// we default to using software serial. If you want to use hardware serial // (because softserial isnt supported) comment out the following three lines // and uncomment the HardwareSerial line #include + +#define FONA_RX 2 +#define FONA_TX 3 + SoftwareSerial fonaSS = SoftwareSerial(FONA_TX, FONA_RX); SoftwareSerial *fonaSerial = &fonaSS; -// Hardware serial is also possible! -// HardwareSerial *fonaSerial = &Serial1; +#else +// On Leonardo/M0/etc, others with hardware serial, use hardware serial! +HardwareSerial *fonaSerial = &Serial1; + +#endif Adafruit_FONA fona = Adafruit_FONA(FONA_RST); diff --git a/examples/IncomingCall/.esp32.test.skip b/examples/IncomingCall/.esp32.test.skip deleted file mode 100644 index e69de29..0000000 diff --git a/examples/IncomingCall/.esp8266.test.skip b/examples/IncomingCall/.esp8266.test.skip deleted file mode 100644 index e69de29..0000000 diff --git a/examples/IncomingCall/.metro_m4.test.skip b/examples/IncomingCall/.metro_m4.test.skip deleted file mode 100644 index e69de29..0000000 diff --git a/examples/IncomingCall/.trinket_m0.test.skip b/examples/IncomingCall/.trinket_m0.test.skip deleted file mode 100644 index e69de29..0000000 diff --git a/examples/IncomingCall/.zero.test.skip b/examples/IncomingCall/.zero.test.skip deleted file mode 100644 index e69de29..0000000 diff --git a/examples/IncomingCall/IncomingCall.ino b/examples/IncomingCall/IncomingCall.ino index 8dba308..ea33395 100644 --- a/examples/IncomingCall/IncomingCall.ino +++ b/examples/IncomingCall/IncomingCall.ino @@ -1,62 +1,68 @@ -// FONA Incoming Call Number Example -// Listens for a call and displays the phone number of the caller (if available). -// Use this example to add phone call detection to your own FONA sketch. -#include "Adafruit_FONA.h" - -// Pins which are connected to the FONA. -// Note that this is different from FONAtest! -#define FONA_RX 3 -#define FONA_TX 4 -#define FONA_RST 5 - -// Note you need to map interrupt number to pin number -// for your board. On an Uno & Mega interrupt 0 is -// digital pin 2, and on a Leonardo interrupt 0 is -// digital pin 3. See this page for a complete table: -// http://arduino.cc/en/Reference/attachInterrupt -// Make sure this interrupt pin is connected to FONA RI! -#define FONA_RI_INTERRUPT 0 - -// We default to using software serial. If you want to use hardware serial -// (because softserial isnt supported) comment out the following three lines -// and uncomment the HardwareSerial line -#include -SoftwareSerial fonaSS = SoftwareSerial(FONA_TX, FONA_RX); -SoftwareSerial *fonaSerial = &fonaSS; - -// Hardware serial is also possible! -// HardwareSerial *fonaSerial = &Serial1; - -Adafruit_FONA fona = Adafruit_FONA(FONA_RST); - -void setup() { - Serial.begin(115200); - Serial.println(F("FONA incoming call example")); - Serial.println(F("Initializing....(May take 3 seconds)")); - - fonaSerial->begin(4800); - if (! fona.begin(*fonaSerial)) { - Serial.println(F("Couldn't find FONA")); - while(1); - } - Serial.println(F("FONA is OK")); - - // Enable incoming call notification. - if(fona.callerIdNotification(true, FONA_RI_INTERRUPT)) { - Serial.println(F("Caller id notification enabled.")); - } - else { - Serial.println(F("Caller id notification disabled")); - } -} - -void loop(){ - // Create a small string buffer to hold incoming call number. - char phone[32] = {0}; - // Check for an incoming call. Will return true if a call is incoming. - if(fona.incomingCallNumber(phone)){ - Serial.println(F("RING!")); - Serial.print(F("Phone Number: ")); - Serial.println(phone); - } -} +// FONA Incoming Call Number Example +// Listens for a call and displays the phone number of the caller (if available). +// Use this example to add phone call detection to your own FONA sketch. +#include "Adafruit_FONA.h" + +// Pins which are connected to the FONA. +// Note that this is different from FONAtest! +#define FONA_RST 5 + +// Note you need to map interrupt number to pin number +// for your board. On an Uno & Mega interrupt 0 is +// digital pin 2, and on a Leonardo interrupt 0 is +// digital pin 3. See this page for a complete table: +// http://arduino.cc/en/Reference/attachInterrupt +// Make sure this interrupt pin is connected to FONA RI! +#define FONA_RI_INTERRUPT 0 + +#if (defined(__AVR__) || defined(ESP8266)) && !defined(__AVR_ATmega2560__) +// For UNO and others without hardware serial, +// we default to using software serial. If you want to use hardware serial +// (because softserial isnt supported) comment out the following three lines +// and uncomment the HardwareSerial line +#include + +#define FONA_RX 2 +#define FONA_TX 3 + +SoftwareSerial fonaSS = SoftwareSerial(FONA_TX, FONA_RX); +SoftwareSerial *fonaSerial = &fonaSS; + +#else +// On Leonardo/M0/etc, others with hardware serial, use hardware serial! +HardwareSerial *fonaSerial = &Serial1; +#endif + +Adafruit_FONA fona = Adafruit_FONA(FONA_RST); + +void setup() { + Serial.begin(115200); + Serial.println(F("FONA incoming call example")); + Serial.println(F("Initializing....(May take 3 seconds)")); + + fonaSerial->begin(4800); + if (! fona.begin(*fonaSerial)) { + Serial.println(F("Couldn't find FONA")); + while(1); + } + Serial.println(F("FONA is OK")); + + // Enable incoming call notification. + if(fona.callerIdNotification(true, FONA_RI_INTERRUPT)) { + Serial.println(F("Caller id notification enabled.")); + } + else { + Serial.println(F("Caller id notification disabled")); + } +} + +void loop(){ + // Create a small string buffer to hold incoming call number. + char phone[32] = {0}; + // Check for an incoming call. Will return true if a call is incoming. + if(fona.incomingCallNumber(phone)){ + Serial.println(F("RING!")); + Serial.print(F("Phone Number: ")); + Serial.println(phone); + } +} From 8a1383dd983431bc51e9584ad0d260e316ab8635 Mon Sep 17 00:00:00 2001 From: ladyada Date: Mon, 27 Sep 2021 13:10:08 -0400 Subject: [PATCH 3/5] re-add one skip --- examples/FONA3G_setbaud/.esp8266.test.skip | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 examples/FONA3G_setbaud/.esp8266.test.skip diff --git a/examples/FONA3G_setbaud/.esp8266.test.skip b/examples/FONA3G_setbaud/.esp8266.test.skip new file mode 100644 index 0000000..e69de29 From e4af5edf1e21adfcb1695784b8708cc7c82d5d10 Mon Sep 17 00:00:00 2001 From: ladyada Date: Mon, 27 Sep 2021 13:53:27 -0400 Subject: [PATCH 4/5] try to fix some errors & warns --- .github/ISSUE_TEMPLATE.md | 92 ++++++++++++++++---------------- .github/PULL_REQUEST_TEMPLATE.md | 52 +++++++++--------- .gitignore | 2 +- Adafruit_FONA.cpp | 8 +++ library.properties | 18 +++---- 5 files changed, 90 insertions(+), 82 deletions(-) diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md index f0e2614..396c6e8 100644 --- a/.github/ISSUE_TEMPLATE.md +++ b/.github/ISSUE_TEMPLATE.md @@ -1,46 +1,46 @@ -Thank you for opening an issue on an Adafruit Arduino library repository. To -improve the speed of resolution please review the following guidelines and -common troubleshooting steps below before creating the issue: - -- **Do not use GitHub issues for troubleshooting projects and issues.** Instead use - the forums at http://forums.adafruit.com to ask questions and troubleshoot why - something isn't working as expected. In many cases the problem is a common issue - that you will more quickly receive help from the forum community. GitHub issues - are meant for known defects in the code. If you don't know if there is a defect - in the code then start with troubleshooting on the forum first. - -- **If following a tutorial or guide be sure you didn't miss a step.** Carefully - check all of the steps and commands to run have been followed. Consult the - forum if you're unsure or have questions about steps in a guide/tutorial. - -- **For Arduino projects check these very common issues to ensure they don't apply**: - - - For uploading sketches or communicating with the board make sure you're using - a **USB data cable** and **not** a **USB charge-only cable**. It is sometimes - very hard to tell the difference between a data and charge cable! Try using the - cable with other devices or swapping to another cable to confirm it is not - the problem. - - - **Be sure you are supplying adequate power to the board.** Check the specs of - your board and plug in an external power supply. In many cases just - plugging a board into your computer is not enough to power it and other - peripherals. - - - **Double check all soldering joints and connections.** Flakey connections - cause many mysterious problems. See the [guide to excellent soldering](https://learn.adafruit.com/adafruit-guide-excellent-soldering/tools) for examples of good solder joints. - - - **Ensure you are using an official Arduino or Adafruit board.** We can't - guarantee a clone board will have the same functionality and work as expected - with this code and don't support them. - -If you're sure this issue is a defect in the code and checked the steps above -please fill in the following fields to provide enough troubleshooting information. -You may delete the guideline and text above to just leave the following details: - -- Arduino board: **INSERT ARDUINO BOARD NAME/TYPE HERE** - -- Arduino IDE version (found in Arduino -> About Arduino menu): **INSERT ARDUINO - VERSION HERE** - -- List the steps to reproduce the problem below (if possible attach a sketch or - copy the sketch code in too): **LIST REPRO STEPS BELOW** +Thank you for opening an issue on an Adafruit Arduino library repository. To +improve the speed of resolution please review the following guidelines and +common troubleshooting steps below before creating the issue: + +- **Do not use GitHub issues for troubleshooting projects and issues.** Instead use + the forums at http://forums.adafruit.com to ask questions and troubleshoot why + something isn't working as expected. In many cases the problem is a common issue + that you will more quickly receive help from the forum community. GitHub issues + are meant for known defects in the code. If you don't know if there is a defect + in the code then start with troubleshooting on the forum first. + +- **If following a tutorial or guide be sure you didn't miss a step.** Carefully + check all of the steps and commands to run have been followed. Consult the + forum if you're unsure or have questions about steps in a guide/tutorial. + +- **For Arduino projects check these very common issues to ensure they don't apply**: + + - For uploading sketches or communicating with the board make sure you're using + a **USB data cable** and **not** a **USB charge-only cable**. It is sometimes + very hard to tell the difference between a data and charge cable! Try using the + cable with other devices or swapping to another cable to confirm it is not + the problem. + + - **Be sure you are supplying adequate power to the board.** Check the specs of + your board and plug in an external power supply. In many cases just + plugging a board into your computer is not enough to power it and other + peripherals. + + - **Double check all soldering joints and connections.** Flakey connections + cause many mysterious problems. See the [guide to excellent soldering](https://learn.adafruit.com/adafruit-guide-excellent-soldering/tools) for examples of good solder joints. + + - **Ensure you are using an official Arduino or Adafruit board.** We can't + guarantee a clone board will have the same functionality and work as expected + with this code and don't support them. + +If you're sure this issue is a defect in the code and checked the steps above +please fill in the following fields to provide enough troubleshooting information. +You may delete the guideline and text above to just leave the following details: + +- Arduino board: **INSERT ARDUINO BOARD NAME/TYPE HERE** + +- Arduino IDE version (found in Arduino -> About Arduino menu): **INSERT ARDUINO + VERSION HERE** + +- List the steps to reproduce the problem below (if possible attach a sketch or + copy the sketch code in too): **LIST REPRO STEPS BELOW** diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 7b641eb..a7e3c88 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -1,26 +1,26 @@ -Thank you for creating a pull request to contribute to Adafruit's GitHub code! -Before you open the request please review the following guidelines and tips to -help it be more easily integrated: - -- **Describe the scope of your change--i.e. what the change does and what parts - of the code were modified.** This will help us understand any risks of integrating - the code. - -- **Describe any known limitations with your change.** For example if the change - doesn't apply to a supported platform of the library please mention it. - -- **Please run any tests or examples that can exercise your modified code.** We - strive to not break users of the code and running tests/examples helps with this - process. - -Thank you again for contributing! We will try to test and integrate the change -as soon as we can, but be aware we have many GitHub repositories to manage and -can't immediately respond to every request. There is no need to bump or check in -on a pull request (it will clutter the discussion of the request). - -Also don't be worried if the request is closed or not integrated--sometimes the -priorities of Adafruit's GitHub code (education, ease of use) might not match the -priorities of the pull request. Don't fret, the open source community thrives on -forks and GitHub makes it easy to keep your changes in a forked repo. - -After reviewing the guidelines above you can delete this text from the pull request. +Thank you for creating a pull request to contribute to Adafruit's GitHub code! +Before you open the request please review the following guidelines and tips to +help it be more easily integrated: + +- **Describe the scope of your change--i.e. what the change does and what parts + of the code were modified.** This will help us understand any risks of integrating + the code. + +- **Describe any known limitations with your change.** For example if the change + doesn't apply to a supported platform of the library please mention it. + +- **Please run any tests or examples that can exercise your modified code.** We + strive to not break users of the code and running tests/examples helps with this + process. + +Thank you again for contributing! We will try to test and integrate the change +as soon as we can, but be aware we have many GitHub repositories to manage and +can't immediately respond to every request. There is no need to bump or check in +on a pull request (it will clutter the discussion of the request). + +Also don't be worried if the request is closed or not integrated--sometimes the +priorities of Adafruit's GitHub code (education, ease of use) might not match the +priorities of the pull request. Don't fret, the open source community thrives on +forks and GitHub makes it easy to keep your changes in a forked repo. + +After reviewing the guidelines above you can delete this text from the pull request. diff --git a/.gitignore b/.gitignore index e43b0f9..6e8821b 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1 @@ -.DS_Store +.DS_Store diff --git a/Adafruit_FONA.cpp b/Adafruit_FONA.cpp index ae002cc..03fc9b9 100644 --- a/Adafruit_FONA.cpp +++ b/Adafruit_FONA.cpp @@ -208,7 +208,15 @@ bool Adafruit_FONA::readRTC(uint8_t *year, uint8_t *month, uint8_t *day, // TODO: https://github.com/adafruit/Adafruit_FONA/issues/111 *year = v; + // avoid non-used warning + (void *)month; + (void *)day; + (void *)hr; + (void *)min; + (void *)sec; + DEBUG_PRINTLN(*year); + return true; } /** diff --git a/library.properties b/library.properties index d08225b..0cb9c3f 100644 --- a/library.properties +++ b/library.properties @@ -1,9 +1,9 @@ -name=Adafruit FONA Library -version=1.3.9 -author=Adafruit -maintainer=Adafruit -sentence=Arduino library for the Adafruit FONA -paragraph=Arduino library for the Adafruit FONA -category=Communication -url=https://github.com/adafruit/Adafruit_FONA -architectures=* +name=Adafruit FONA Library +version=1.3.9 +author=Adafruit +maintainer=Adafruit +sentence=Arduino library for the Adafruit FONA +paragraph=Arduino library for the Adafruit FONA +category=Communication +url=https://github.com/adafruit/Adafruit_FONA +architectures=* From 684b42327b500a8e2eb9532e8bf6dee816769e34 Mon Sep 17 00:00:00 2001 From: ladyada Date: Mon, 27 Sep 2021 14:20:55 -0400 Subject: [PATCH 5/5] undo extra commit --- Adafruit_FONA.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Adafruit_FONA.cpp b/Adafruit_FONA.cpp index 03fc9b9..254ae7f 100644 --- a/Adafruit_FONA.cpp +++ b/Adafruit_FONA.cpp @@ -51,7 +51,7 @@ Adafruit_FONA::Adafruit_FONA(int8_t rst) { apnusername = 0; apnpassword = 0; mySerial = 0; - httpsredirect = true; + httpsredirect = false; useragent = F("FONA"); ok_reply = F("OK"); } @@ -118,9 +118,6 @@ bool Adafruit_FONA::begin(Stream &port) { // turn on hangupitude sendCheckReply(F("AT+CVHU=0"), ok_reply); - // turn on SSL support - sendCheckReply(F("AT+CVHU=0"), ok_reply); - delay(100); flushInput();