[ Web Proxy ]
URL:
Viewing: https://raw.githubusercontent.com/ImTheDeveloper/Arduino_Tracker_v2/master/Main_Code [Back]  [Original]

//####MATH
#include 
//####SLEEP STUFF
#include 
Sleep sleep;
//####SMS STUFF
// Include the GSM library
#include 

#define PINNUMBER ""

// initialize the library instance
GSM gsmAccess;
GSM_SMS sms;


//####GPS STUFF
#include 
#include 

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);
}

Web Proxy Viewer  |  New URL  |  Original Page