mikalhart / TinyGPSPlus

A new, customizable Arduino NMEA parsing library
http://arduiniana.org
1.1k stars 494 forks source link

How can I save the obtained location & then send it through SMS? #13

Closed Pritha01 closed 7 years ago

Pritha01 commented 8 years ago

Hello! I have following function:

` bool sendLocation(char* number, char* latitude, char* longtitude) {

cleanBuffer();
serialSIM800.println("AT+CMGF=1");
if ( waitFor("OK", "ERROR") != 1 ) return false;

cleanBuffer();
serialSIM800.print("AT+CMGS=\"");
serialSIM800.print(number);
serialSIM800.println("\"");
if ( waitFor(">", "ERROR") != 1 ) return false;

cleanBuffer();
serialSIM800.print("LAT: ");
serialSIM800.println(latitude);
serialSIM800.print("LON: ");
serialSIM800.println(longtitude);
serialSIM800.println((char)26);
if ( waitFor("+CMGS:", "ERROR") != 1 ) return false;
return true;

}`

Will it be fine if I define latitude & longitude as: char* latitude; char* longtitude;

How can I save the obtained latitude & longitude and then pass them into my function? Please help me.

nobodyguy commented 7 years ago

If you're using AVR, you can do something like this:

char latBuffer[20];
char lngBuffer[20];
double lat = gps.location.lat();
double lng = gps.location.lng();
dtostrf(lat, 8, 6, latBuffer);
dtostrf(lng, 8, 6, lngBuffer);
ghost commented 7 years ago

Thank you very much for this code nobodyguy, id got frustraded using sprintf...... Funny fact is that id not searched for this in context with sms. I want to send gps coordinates over LoRa.

nobodyguy commented 7 years ago

You can check code for my LoRaWAN GPS tracker prototype if you want - https://gist.github.com/nobodyguy/7920482dd00f300b973126f9d7188db4