Sending TXT Location showing wrong

i am trying to send a location from GPS card over a txt message but its coming out all strange i am reciving

Google Maps long:

the code sending this is

boolean fonaSendLocationSMS (char *recipient) {
  char sms_response[52];

  boolean gps_success = fona.getGPS(&latitude, &longitude,&speed_kph, &heading, &altitude);
 


  if (gps_success)
 {
    
    sprintf (sms_response, "https://maps.google.com?q=%s,%s",latitude,longitude);
  } else {
    sprintf (sms_response, "I'm lost!");
  }

  return fona.sendSMS(recipient, sms_response);
}

whats causing this to happen?

sprintf (sms_response, "https://maps.google.com?q=%s,%s",latitude,longitude);

Are latitude and longitude strings of characters ? (the %s parameter says they are) What do you see if you simply print them ?

You need to convert from the gps co-ord's to the ones used by google.

Mark

mikewitney:
whats causing this to happen?

sprintf (sms_response, "https://maps.google.com?q=%s,%s",latitude,longitude);

How is the declaration for the latitude,longitude parameters?

For '%s' they should be nullterminated strings or string pointers.

But most likely you have declared them something different (float?), so they cannot be formatted as strings.

Hard to say if you just show a small part of your code with all important variable declarations missing in that code snippet.

#include "Adafruit_FONA.h"
#include <Phant.h>

// Arduino example stream
// https://data.sparkfun.com/streams/9JLrZYvqLdHROqVwg2Zd
// https://data.sparkfun.com/wheresmydog
// Delete Key = 
// host, public key, private key
Phant phant("data.sparkfun.com", "", "");
#define SPARKFUN_PUBLIC_KEY ""
#define SPARKFUN_PRIVATE_KEY ""
// standard pins for the 808 shield
#define FONA_RX 11
#define FONA_TX 10
#define FONA_RST 9
#define mobile "447795966848"

// This is to handle the absence of software serial on platforms
// like the Arduino Due. Modify this code if you are using different
// hardware serial port, or if you are using a non-avr platform
// that supports software serial.
#ifdef __AVR__
#include <SoftwareSerial.h>
SoftwareSerial fonaSS = SoftwareSerial(FONA_TX, FONA_RX);
SoftwareSerial *fonaSerial = &fonaSS;
#else
HardwareSerial *fonaSerial = &Serial1;
#endif

Adafruit_FONA fona = Adafruit_FONA(FONA_RST);
float latitude, longitude, speed_kph, heading, speed_mph, altitude;

void setup() {

  while (! Serial);

  Serial.begin(115200);
  Serial.println(F("Adafruit FONA 808 GPS demo"));
  Serial.println(F("Initializing FONA... (May take a few seconds)"));

  fonaSerial->begin(9600);
  if (! fona.begin(*fonaSerial)) {
    Serial.println(F("Couldn't find FONA"));
    while (1);
  }
  Serial.println(F("FONA is OK"));

  Serial.println(F("Enabling GPS..."));
  fona.enableGPS(true);
  delay(5000);
  fonaSendLocationSMS("447795966848");
  
  if (!fona.enableGPRS(true))
    Serial.println(F("Failed to turn on"));

}




void loop() {
  // if you ask for an altitude reading, getGPS will return false if there isn't a 3D fix
  
  //if (fona.newNMEAreceived() && fona.parse(gps.lastNMEA()))
  boolean gps_success = fona.getGPS(&latitude, &longitude,   &speed_kph, &heading, &altitude);

  if (gps_success) {

    Serial.print("GPS lat:");
    Serial.println(latitude, 6);
    Serial.print("GPS long:");
    Serial.println(longitude, 6);
    Serial.print("GPS speed KPH:");
    Serial.println(speed_kph);
    Serial.print("GPS speed MPH:");
    speed_mph = speed_kph * 0.621371192;
    Serial.println(speed_mph);
    Serial.print("GPS heading:");
    Serial.println(heading);
    
  } else {
    Serial.println("Waiting for FONA 808 GPS 3D fix...");
  }

  // print out the GSM location to compare
  boolean gsmloc_success = fona.getGSMLoc(&latitude, &longitude);

  if (gsmloc_success) {

    Serial.print("GSMLoc lat:");
    Serial.println(latitude, 6);
    Serial.print("GSMLoc long:");
    Serial.println(longitude, 6);

  } else {
    Serial.println("GSM location failed...");
  }
 
  
 


}

boolean fonaSendLocationSMS (char *recipient) {
  char sms_response[52];

  boolean gps_success = fona.getGPS(&latitude, &longitude,&speed_kph, &heading, &altitude);
  boolean sms_send = fona.getGPS(&latitude, &longitude);


  if (gps_success)
 {
    
    sprintf (sms_response, "https://maps.google.com?q=%s,%s",latitude,longitude);
  } else {
    sprintf (sms_response, "I'm lost!");
  }

  return fona.sendSMS(recipient, sms_response);
}


boolean fonaSendStatusSMS (char *recipient) {
  uint8_t rssi = fona.getRSSI();
  uint16_t vbat;
  fona.getBattVoltage(&vbat);

  char sms_response[16];
  sprintf (sms_response, "%d bars, %d mV", barsFromRSSI(rssi), vbat);

  return fona.sendSMS(recipient, sms_response);
}


uint8_t barsFromRSSI (uint8_t rssi) {
  // https://en.wikipedia.org/wiki/Mobile_phone_signal#ASU
  //
  // In GSM networks, ASU maps to RSSI (received signal strength indicator, see TS 27.007[1] sub clause 8.5).
  //   dBm = 2 × ASU - 113, ASU in the range of 0..31 and 99 (for not known or not detectable).

  int8_t dbm = 2 * rssi - 113;

  if (rssi == 99 || rssi == 0) {
    return 0;
  } else if (dbm < -107) {
    return 1;
  } else if (dbm < -98) {
    return 2;
  } else if (dbm < -87) {
    return 3;
  } else if (dbm < -76) {
    return 4;
  }

  return 5;
}
float latitude, longitude, speed_kph, heading, speed_mph, altitude;

    sprintf (sms_response, "https://maps.google.com?q=%s,%s",latitude,longitude);

You have been told that the format specifier %s is for strings. Why are you using it for floats?

mikewitney:

float latitude, longitude, speed_kph, heading, speed_mph, altitude;

...
sprintf (sms_response, "Google Maps",latitude,longitude);

The latitude and longitude variables are NOT string pointers, so you cannot use "%s" string formatting with these two variables.

Also the "%f" float formatting with 'sprintf' is not enabled for 8-bit microcontrollers.

For float formatting with 8-bit Atmegas you might want to use dtostrf()

can they be converted to strings after the value is achieved?

can they be converted to strings after the value is achieved?

Yes, but chocolate peanut butter ice cream is better.

I hope that someday you learn to ask an intelligent question. "After the value is achieved"? What ARE you talking about?

mikewitney:
can they be converted to strings after the value is achieved?

Yes, of course, like I told before: Use the dtostrf() function for formatting float values.

Here is a complete example to format your string:

  • copy fixed text to the char array with strcpy()
  • add the first float value with dtostrf()
  • append the comma with strcat()
  • add the second float value with dtostr()
void setup() {
  Serial.begin(9600);
  char sms_response[52];
  float latitude=12.3456;
  float longitude=45.6789;
  strcpy(sms_response, "https://maps.google.com?q=");
  dtostrf(latitude,6,5,&sms_response[strlen(sms_response)]);
  strcat(sms_response,",");
  dtostrf(longitude,6,5,&sms_response[strlen(sms_response)]);
  Serial.println(sms_response);
}

void loop() {
}