I'm using SIM900A and GY NEO6MV2. I'm supposed to receive device location continuously after sending "Staff" to GSM and will stop receiving the location if I send "Stop" to GSM. This work on Serial monitor but not on my cellphone.
#include <SoftwareSerial.h>
#include <TinyGPS.h>
float flat, flon; // create variable for latitude and longitude object
int temp=0,i;
SoftwareSerial mySerial(10, 11); // create gps sensor connection
TinyGPS gps; // create gps object
void setup(){
Serial.begin(9600); // connect serial
mySerial.begin(9600); // connect gps sensor
delay(2000);
Serial.println("AT+CNMI=2,2,0,0,0");
temp=0;
}
void loop()
{
while(Serial.available())
{
if(Serial.find("Staff"))
{
get_gps();
}
if(Serial.find("Stop"))
{
loop();
}
}
}
void get_gps() // run over and over
{
unsigned long start = millis();
while (millis() - start < 10000) {
if (mySerial.available()) {
char c = mySerial.read();
if (gps.encode(c)) {
gpsdump(gps);;
}
}
}
}
void gpsdump(TinyGPS &gps)
{
init_sms();
gps.f_get_position(&flat,&flon);
Serial.print("Location?\nRight here:\n");
Serial.print("Google Maps: https://google.com/maps/place//@");
printFloat(flat, 5); Serial.print(",");
printFloat(flon, 5); Serial.print('\n');
Serial.print("Location as metioned above\nTQVM");
Serial.write(0x1A);
delay(2000);
}
void init_sms()
{
Serial.println("AT+CMGF=1");
delay(400);
Serial.println("AT+CMGS=\"+60134484868\"");
delay(400);
}
void printFloat(double number, int digits)
{
// Handle negative numbers
if (number < 0.0) {
Serial.print('-');
number = -number;
}
// Round correctly so that print(1.999, 2) prints as "2.00"
double rounding = 0.5;
for (uint8_t i=0; i<digits; ++i)
rounding /= 10.0;
number += rounding;
// Extract the integer part of the number and print it
unsigned long int_part = (unsigned long)number;
double remainder = number - (double)int_part;
Serial.print(int_part);
// Print the decimal point, but only if there are digits beyond
if (digits > 0)
Serial.print(".");
// Extract digits from the remainder one at a time
while (digits-- > 0) {
remainder *= 10.0;
int toPrint = int(remainder);
Serial.print(toPrint);
remainder -= toPrint;
}
}