aboutsummaryrefslogtreecommitdiff
path: root/main.ino
diff options
context:
space:
mode:
Diffstat (limited to 'main.ino')
-rw-r--r--main.ino87
1 files changed, 37 insertions, 50 deletions
diff --git a/main.ino b/main.ino
index d67fb30..90f5d41 100644
--- a/main.ino
+++ b/main.ino
@@ -1,46 +1,24 @@
-/***************************************************
- 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
-For use with FONA 800 & 808, not 3G
-*/
-
#include "Adafruit_FONA.h"
-#define FONA_RX 9
-#define FONA_TX 8
+// Pin for actiaving LifeLarm
+#define activateLarm 5
+
+// Pins on PCB that connect to Sim
+#define FONA_RX 9
+#define FONA_TX 8
#define FONA_RST 4
-#define FONA_RI 7
+#define FONA_RI 7
// 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
+// Phone number we send emergency text to
+char callerIDbuffer[32];
+
#include <SoftwareSerial.h>
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);
uint8_t readline(char *buff, uint8_t maxbuff, uint16_t timeout = 0);
@@ -49,7 +27,7 @@ void setup() {
while (!Serial);
Serial.begin(115200);
- Serial.println(F("FONA SMS caller ID test"));
+ Serial.println(F("LifeLarm turning on!"));
Serial.println(F("Initializing....(May take 3 seconds)"));
// make it slow so its easy to read!
@@ -58,16 +36,12 @@ void setup() {
Serial.println(F("Couldn't find FONA"));
while(1);
}
- Serial.println(F("FONA is OK"));
- // Print SIM card 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("SIM card IMEI: "); Serial.println(imei);
- }
+ // Set button to active low
+ pinmode(activateLarm, INPUT_PULLUP);
+ attachInterrupt(digitalPinToInterrupt(activateLarm), sendHelp, CHANGE);
- Serial.println("FONA Ready");
+ Serial.println("LifeLarm Ready");
}
@@ -76,11 +50,13 @@ char fonaInBuffer[64]; //for notifications from the FONA
void loop() {
char* bufPtr = fonaInBuffer; //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();
@@ -91,23 +67,23 @@ void loop() {
//Add a terminal NULL to the notification string
*bufPtr = 0;
- //Scan the notification string for an SMS received notification.
+ // 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(fonaInBuffer, "+CMTI: \"SM\",%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);
+ Serial.print(F("Retreived number: ")); Serial.println(callerIDbuffer);
+ Serial.print(F("Stored in slot: ")); Serial.println(slot);
//Send back an automatic response
- Serial.println("Sending reponse...");
- if (!fona.sendSMS(callerIDbuffer, "Hey, I got your text!")) {
- Serial.println(F("Failed"));
+ Serial.println("Sending confirmation...");
+ if (!fona.sendSMS(callerIDbuffer, "Your phone number has been set as the emergency number!")) {
+ Serial.println(F("Failed to send!"));
} else {
Serial.println(F("Sent!"));
}
@@ -115,11 +91,22 @@ void loop() {
// 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)) {
+ /* if (fona.deleteSMS(slot)) {
Serial.println(F("OK!"));
- } else {
+ } else {
Serial.println(F("Couldn't delete"));
- }
+ }
+ */
}
}
}
+
+void sendHelp() [
+ Serial.println("Sending text...");
+ if (!fona.sendSMS(callerIDbuffer, "HELP! ... --- ... I will be sending my location to you!")) {
+ Serial.println(F("Failed to send!"));
+ failed++;
+ } else {
+ Serial.println(F("Sent!"));
+ }
+}