Hi Paul,
I really hope that I have it now I have done away with TinyGPS, the code is not returning an sms but I have a feeling it's just something small. The sms is being delivered, I am not sure how to test whether my gps data has all been received before exiting that While loop. If you have some time could you please review my code and let me know. Thanks very much. Hope my indentation is OK and it's not overall confusing.
#include <NewSoftSerial.h>
#include <String.h>
NewSoftSerial cell(2,3);
String line, SenderNumber, SenderMessage, strBuffer;;
int ct = 0;
char c, buffer[128];
void setup()
{
cell.begin(9600);
Serial.begin(4800);
pinMode(13, OUTPUT);
digitalWrite(13, LOW);
}
void loop()
{
if (cell.available())
{
c = cell.read();
if (c == '\n')
{
buffer[ct] = 0;
strBuffer = buffer;
if (strBuffer.substring(0,8) == "+SIND: 4")
{
cell.println("AT+CNMI=3,3,0,0");
delay(20);
cell.println("AT+CMGF=1");
delay(20);
cell.println("AT+CMGD=1,4");
delay(1000);
digitalWrite(13, HIGH);
}
if (strBuffer.substring(0,5) == "+CMT:")
{
SenderNumber = ("0" + strBuffer.substring(10,19));
}
if (strBuffer.substring(0,4) == "#LOC")
{
int flag = 0;
String LatRaw = "";
String LatDir = "";
String LonRaw = "";
String LonDir = "";
String Speed = "";
Serial.flush();
//I think this loop is the problem, not sure how else to confirm data is received.
//Without this while in a new sketch, it gets data flawlessly from the GPS.
while (flag != 1)
{
if (Serial.available())
{
c = Serial.read();
if (c == '
EDIT: About those if statements in your previous post, they didn't have any elses on them because I was only testing for those 2 or 3 results. The rest of the results were to be discarded so I wouldn't have needed to handle them.)
{
buffer[ct] = 0;
strBuffer = buffer;
if (strBuffer.substring(0,5) == "GPRMC")
{
int comma1 = strBuffer.indexOf(',');
int comma2 = strBuffer.indexOf(',', comma1 + 1);
int comma3 = strBuffer.indexOf(',', comma2 + 1);
int comma4 = strBuffer.indexOf(',', comma3 + 1);
int comma5 = strBuffer.indexOf(',', comma4 + 1);
int comma6 = strBuffer.indexOf(',', comma5 + 1);
int comma7 = strBuffer.indexOf(',', comma6 + 1);
int comma8 = strBuffer.indexOf(',', comma7 + 1);
int comma9 = strBuffer.indexOf(',', comma8 + 1);
LatRaw = strBuffer.substring(comma3 + 1,comma4);
LatDir = strBuffer.substring(comma4 + 1,comma5);
LonRaw = strBuffer.substring(comma5 + 1,comma6);
LonDir = strBuffer.substring(comma6 + 1,comma7);
Speed = strBuffer.substring(comma7 + 1,comma8);
if (Speed != "")
{
flag = 1;
}
}
ct = 0;
}
else
{
buffer[ct] = c;
ct += 1;
if (ct >= sizeof(buffer))
{
ct = 0;
}
}
}
}
SenderMessage = "LONG:";
SenderMessage += LonRaw;
SenderMessage += " LAT:";
SenderMessage += LatRaw;
SenderMessage += " SPD:";
SenderMessage += Speed;
SenderMessage += "Km/h";
sms(SenderNumber, SenderMessage);
cell.println("AT+CMGD=1,4");
delay(1000);
}
ct = 0;
}
else
{
buffer[ct] = c;
ct += 1;
if (ct >= sizeof(buffer))
{
ct = 0;
}
}
}
}
void sms(String number, String message)
{
cell.println("AT+CMGF=1");
cell.print("AT+CMGS=");
cell.print(34, BYTE);
cell.print(number);
cell.println(34, BYTE);
delay(500);
cell.print(message);
cell.println(26,BYTE);
delay(15000);
}
EDIT: About those if statements in your previous post, they didn't have any elses on them because I was only testing for those 2 or 3 results. The rest of the results were to be discarded so I wouldn't have needed to handle them.