aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVasil Zlatanov <v@skozl.com>2017-03-02 16:45:53 +0000
committerVasil Zlatanov <v@skozl.com>2017-03-02 16:45:53 +0000
commite3d42de038c5e558fd88588aa8809d2171c4d9e9 (patch)
tree6199fbf66881d645870364f1da6ce26e49a5ed08
parenta917ecc9c9ec20abb58791af0bae715ab7039e4f (diff)
downloade2-lifelarm-e3d42de038c5e558fd88588aa8809d2171c4d9e9.tar.gz
e2-lifelarm-e3d42de038c5e558fd88588aa8809d2171c4d9e9.tar.bz2
e2-lifelarm-e3d42de038c5e558fd88588aa8809d2171c4d9e9.zip
preliminary contact control
-rw-r--r--src/src.ino196
1 files changed, 113 insertions, 83 deletions
diff --git a/src/src.ino b/src/src.ino
index 2950d6a..c6f9566 100644
--- a/src/src.ino
+++ b/src/src.ino
@@ -1,4 +1,6 @@
-#include "Adafruit_FONA.h"
+#include <Adafruit_FONA.h>
+#include <Adafruit_GPS.h>
+#include <SoftwareSerial.h>
// Pin for actiaving LifeLarm
#define activateLarm 5
@@ -15,7 +17,9 @@ char replybuffer[255];
// Phone number we send emergency text to
char callerIDbuffer[32];
-#include <SoftwareSerial.h>
+// Slot in which the phone number is stored
+int slot = 0;
+
SoftwareSerial fonaSS = SoftwareSerial(FONA_TX, FONA_RX);
SoftwareSerial *fonaSerial = &fonaSS;
@@ -23,89 +27,115 @@ Adafruit_FONA fona = Adafruit_FONA(FONA_RST);
uint8_t readline(char *buff, uint8_t maxbuff, uint16_t timeout = 0);
-void setup() {
- while (!Serial);
-
- Serial.begin(115200);
- Serial.println(F("LifeLarm turning on!"));
- 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);
- }
-
- // Set button to active low
- pinMode(activateLarm, INPUT_PULLUP);
- attachInterrupt(digitalPinToInterrupt(activateLarm), sendHelp, CHANGE);
-
- Serial.println("LifeLarm Ready");
+void setup()
+{
+ while (!Serial) ;
+
+ Serial.begin(115200);
+ Serial.println(F("LifeLarm turning on!"));
+ 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) ;
+ }
+ // Set button to active low
+ pinMode(activateLarm, INPUT_PULLUP);
+ attachInterrupt(digitalPinToInterrupt(activateLarm), sendHelp, CHANGE);
+
+ Serial.println("LifeLarm Ready");
+
+ // Loop trough slots untill we find the number
+
+ for (int k = 0; k < 10; k++) {
+ if (!fona.getSMSSender(slot, callerIDbuffer, 31)) {
+ Serial.print(F("Found number in slot:"));
+ Serial.println(slot);
+ Serial.print(F("Emergency number set to: "));
+ Serial.println(callerIDbuffer);
+ k = 99; // exit for loop by going out of bounds
+ } else {
+ Serial.print(F
+ ("Could not find emergency number in slot:"));
+ Serial.println(slot);
+ }
+ }
+
}
-
-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();
- Serial.write(*bufPtr);
- delay(1);
- } while ((*bufPtr++ != '\n') && (fona.available()) && (++charCount < (sizeof(fonaInBuffer)-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(fonaInBuffer, "+CMTI: \"SM\",%d", &slot)) {
- Serial.print("slot: "); Serial.println(slot);
-
-
- // Retrieve SMS sender address/phone number.
- if (! fona.getSMSSender(slot, callerIDbuffer, 31)) {
- Serial.println("Didn't find SMS message in slot!");
- }
- 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 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!"));
- }
-
- // 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.println(F("Couldn't delete"));
- }
- */
- }
- }
+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 charCount = 0;
+ int newSlot = 0;
+
+ //Read the notification into fonaInBuffer
+ do {
+ *bufPtr = fona.read();
+ Serial.write(*bufPtr);
+ delay(1);
+ } while ((*bufPtr++ != '\n') && (fona.available())
+ && (++charCount < (sizeof(fonaInBuffer) - 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(fonaInBuffer, "+CMTI: \"SM\",%d", &newSlot)) {
+ Serial.print("New slot: ");
+ Serial.println(slot);
+
+ // Retrieve SMS sender address/phone number.
+ if (!fona.getSMSSender(newSlot, callerIDbuffer, 31)) {
+ Serial.println
+ ("Didn't find SMS message in slot!");
+ }
+ Serial.print(F("Retreived number: "));
+ Serial.println(callerIDbuffer);
+ Serial.print(F("Stored in slot: "));
+ Serial.println(newSlot);
+
+ //Send back an automatic response
+ 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!"));
+ }
+
+ // delete the previous slot
+ // 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.println(F("Couldn't delete"));
+ }
+ // set current slot to new message
+ slot = newSlot;
+ }
+ }
}
-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!"));
- } else {
- Serial.println(F("Sent!"));
- }
+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!"));
+ } else {
+ Serial.println(F("Sent!"));
+ }
}