Alright guys, let's see if you can help me out. Recently I tackled the Instructables: Athena Global Car tracking project. Lots of issues with it but it was a good starting point. So I have all my code working but no matter what I do I can't seem to get a working password.
What I'm using: Arduino Uno, SIM900, and Adafruit Ultimate GPS.
What I want: I want to be able to text my predefined number and it only send me back the coordinates if the password (predefined) is correct. If incorrect I want it to give and error message and go right back to being able to try the password again.
Here's my code:
#include <SoftwareSerial.h>
#include <string.h>
#include <TinyGPS.h>
#include <Adafruit_GPS.h>
SoftwareSerial GPRS(7, 8); //hook TX of the GPS to port 7 of the GPRS and RX to port 8
byte buffer[64]; // buffer array for data recieve over serial port
int count=0; // counter for buffer array
SoftwareSerial GPS(3, 2); //set the Arduino in line with the GPRS, (7,8) correspond with (3,2)
TinyGPS gps;
unsigned long fix_age;
long lat, lon;
float LAT, LON;
void gpsdump(TinyGPS &gps);
bool feedgps();
void getGPS();
void SIM900power() // software equivalent of pressing the GSM shield "power" button
{
digitalWrite(9, HIGH);
delay(1000);
Sim900_Inti();
}
void setup()
{
GPRS.begin(19200); // the SIM900 baud rate
SIM900power();
GPS.begin(9600); // GPS module baud rate
Serial.begin(115200); // the Serial port of Arduino baud rate.
delay(500);
}
void loop()
{
GPRS.listen();
if (GPRS.available()) // If date is comming from from GSM shield)
{
while(GPRS.available()) // reading data into char array
{
buffer[count++]=GPRS.read(); // writing data into array
if(count == 64)break;
}
Serial.write(buffer,count); // if no data transmission ends, write buffer to hardware serial port
SendTextMessage(); //Took out Read the 'COMMAND' sent to SIM900 through SMS
clearBufferArray(); // call clearBufferArray function to clear the storaged data from the array
count=0; // set counter of while loop to zero
}
if (Serial.available()) // if data is available on hardwareserial port ==> data is comming from PC or notebook
GPRS.write(Serial.read()); // write it to the GPRS shield
}
void clearBufferArray() // function to clear buffer array
{
for (int i=0; i<count;i++)
{
buffer[i]=NULL;
} // clear all index of array with command NULL
}
void Sim900_Inti(void)
{
GPRS.println("AT+CMGF=1"); // Set GSM shield to sms mode
Serial.println("AT CMGF=1");
delay(500);
GPRS.println("AT+CNMI=2,2");
Serial.println("AT CMGF=1");
delay(500);
}
void SendTextMessage()
{
GPRS.print("AT+CMGF=1\r"); //Sending the SMS in text mode
delay(100);
GPRS.println("AT + CMGS = \"+1765********\""); //The predefined phone number
delay(100);
GPRS.println("Please wait while GPS Module calculates position"); //the content of the message
delay(100);
GPRS.println((char)26);//the ASCII code of the ctrl z is 26
delay(100);
GPRS.println();
delay(5000);
int counter=0;
GPS.listen();
for (;;)
{
long lat, lon;
unsigned long fix_age, time, date, speed, course;
unsigned long chars;
unsigned short sentences, failed_checksum;
long Latitude, Longitude;
// retrieves /- lat/long in 100000ths of a degree
gps.get_position(&lat, &lon, &fix_age);
getGPS();
Serial.print("Latitude : ");
Serial.print(LAT/1000000,7);
Serial.print(" :: Longitude : ");
Serial.println(LON/1000000,7);
GPRS.print("AT+CMGF=1\r"); //Sending the SMS in text mode
delay(100);
GPRS.println("AT + CMGS = \"+1765********\""); //The predefined phone number
delay(100);
GPRS.print("maps.google.com/maps?q=");
GPRS.print(LAT/1000000,7);
GPRS.print("+");
GPRS.println(LON/1000000,7);//the content of the message
delay(100);
GPRS.println((char)26);//the ASCII code of the ctrl z is 26
delay(100);
GPRS.println();
delay(5000);
counter=0;
break;
}
}
void getGPS()
{
bool newdata = false;
unsigned long start = millis();
while (millis() - start < 1000)
{
if (feedgps ())
{
newdata = true;
}
}
if (newdata)
{
gpsdump(gps);
}
}
bool feedgps()
{
while (GPS.available())
{
if (gps.encode(GPS.read()))
return true;
}
return 0;
}
void gpsdump(TinyGPS &gps)
{
gps.get_position(&lat, &lon);
LAT = lat;
LON = lon;
{
feedgps();
}
}