Hi All,
Tldr; dtostrf(orgLon, 9,6, lonStr); does not appear to work!?!?!? The lonStr is not correct when sprintf'ed in another function.
Writing what effectively is a GPS/GSM tracker. I want to send a data string via HTTP over GSM. This is using the Ardunio IDE, TinyGPS++ for nmea parsing. The GPS object is a wrapper to TinyGPS++ with methods to control hardware etc...
I use global variables for some shared data. The main() and associated functions deal mainly with state. All the hardware and some other things are created as Objects and their variables are hence hidden.
There is a function to update GPS lat/lon location.
Another function to create the char[] message.
In top of the .ino file I have;
double orgLat = 0; // Last recorded Lat
double orgLon = 0; // Last recorded lon
double distance = 10000; // distance moved (default)
char latStr[10]; // lat string
char lonStr[10]; // lon string
void checkLocation(void) {
// update location
gps.getUpdatedFix(UPDATE_GPS_FIX_TIMEOUT_MSECS, UPDATE_GPS_NUMBER_OF_FIXES);
distance = gps.distanceMoved(orgLat, orgLon);
// save present location
orgLat = gps.getLat();
orgLon = gps.getLon();
dtostrf(orgLat, 9,6, latStr); //first number is length, last is numbers after decimal
dtostrf(orgLon, 9,6, lonStr);
dtostrf(distance, 9,2, distanceStr);
DEBUG("distance: ");
Serial.println(distanceStr);
}
If it print the latStr and lonStr in this function they are correct.
void sendMessage(void) {
//Get a dateTime String
sprintf(dateTimeStr, gps.getdateTime());
//Put the message together
sprintf(messageStr, "'%s,%sv,%sv,%sc,%s,%s,%s,%dm'", dateTimeStr, lipoStr, vccStr, tempStr, bilgeStr, latStr, lonStr, distanceStr);
DEBUG("Message is: ");
DEBUGln(messageStr);
If I print the latStr and lonStr in this function they are incorrect.
However in the messageStr gets populated with garbage. latStr looks like a Latitude, but is not the most recent, the lonStr is only 3 digits long. I am near London so Lon is negative - something like -0.45453377
Will post some actual code output later as on the train to work!