-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathMain_Code
137 lines (120 loc) · 3.94 KB
/
Main_Code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
//####MATH
#include <math.h>
//####SLEEP STUFF
#include <Sleep_n0m1.h>
Sleep sleep;
//####SMS STUFF
// Include the GSM library
#include <GSM.h>
#define PINNUMBER ""
// initialize the library instance
GSM gsmAccess;
GSM_SMS sms;
//####GPS STUFF
#include <AltSoftSerial.h>
#include <Adafruit_GPS.h>
AltSoftSerial mySerial; //AltSoftSerial ALWAYS uses the following pins:
//
// Board Transmit Receive PWM Unusable
// ----- -------- ------- ------------
// Teensy 2.0 9 10 (none)
// Teensy++ 2.0 25 4 26, 27
// Arduino Uno 9 8 10
// Arduino Mega 46 48 44, 45
// Wiring-S 5 6 4
// Sanguino 13 14 12
Adafruit_GPS GPS(&mySerial);
#define GPSECHO true
boolean usingInterrupt = false;
void useInterrupt(boolean); // Func prototype keeps Arduino 0023 happy
//uint32_t timer = millis();
//####NORMAL STUFF
//Global Variables
boolean GPS_Fix;
double decDegLat;
double decDegLong;
char mySmsString[60] = "";
char mySmsStringLat[11]="";//[11] = "";
char mySmsStringLon[11]="";//[11] = "";
char mySmsStringBearLat;//;
char mySmsStringBearLon;//;
int GPS_Pin_Enable=12;
int GPRS_Pin_Enable=11;
void setup()
{
Serial.begin(9600);
pinMode(GPS_Pin_Enable,OUTPUT); //Set out GPS_Pin_Enable as an output
delay(2000);
GPS.begin(9600);
GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA);
GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ); // 1 Hz update rate
digitalWrite(GPS_Pin_Enable,LOW);//Turn Off gps
useInterrupt(true);
pinMode(GPRS_Pin_Enable,OUTPUT);//Set out GPRS as an output
digitalWrite(GPRS_Pin_Enable,LOW);//Turn off the GPRS
}
void loop()
{
Serial.println(F("Starting up"));
digitalWrite(GPS_Pin_Enable,HIGH); //Turn on the gps
delay(2000);
Serial.println(F("Gps up"));
//Get GPS Data
GPS_Fix=false; //Gps fix variable set to nothing to get started
delay(2000);
while(!GPS_Fix) {
if (GPS.newNMEAreceived()) {
if (!GPS.parse(GPS.lastNMEA())) // this also sets the newNMEAreceived() flag to false
return; // we can fail to parse a sentence in which case we should just wait for another
}
if ((strstr(GPS.lastNMEA(), "RMC")) && GPS.fix){
digitalWrite(GPS_Pin_Enable,LOW); //Turn off the gps
delay(1000);
GPS_Fix=true;
dtostrf(convertDegMinToDecDeg(GPS.latitude),11,5,mySmsStringLat);
dtostrf(convertDegMinToDecDeg(GPS.longitude),11,5,mySmsStringLon);
mySmsStringBearLon = GPS.lon;
mySmsStringBearLat = GPS.lat;
Serial.println(F("Fixed!"));
Serial.println(F("GPS off"));
break;
}
Serial.print("\nTime: ");
Serial.print(GPS.hour, DEC); Serial.print(':');
Serial.print(GPS.minute, DEC); Serial.print(':');
Serial.print(GPS.seconds, DEC); Serial.print('.');
Serial.println(GPS.milliseconds);
delay(1000);
}
//########################################Turn on and run SMS###################################
//Turn On SMS
Serial.println(F("Starting up GSM"));
gsmOnOff();
//prepare sms message
sprintf(mySmsString,"%s",mySmsStringLat,mySmsStringLon);
mySmsString[0]=mySmsStringBearLat;
mySmsString[12]=mySmsStringBearLon;
// connection state
boolean notConnected = true;
// Start GSM shield
// If your SIM has PIN, pass it as a parameter of begin() in quotes
while(notConnected)
{
if(gsmAccess.begin(PINNUMBER)==GSM_READY)
notConnected = false;
else
{
//Serial.println("Not connected");
delay(1000);
}
}
Serial.println(F("Sending sms"));
Send_SMS(mySmsString); //Send our SMS
//Turn Off GPRS
gsmOnOff();
Serial.println(F("GSM OFF"));
//Sleep for a while then loop again.
sleep.pwrDownMode();
Serial.println(F("Sleep"));
sleep.sleepDelay(60000);
}