Arduino Uno SIM808 GPS send SMS --> coordinats in maps.google

Hi All,

The goal for the code below is to build an GPS tracker, with a Arduino UNO, connected with GPS and GSM with the SIM808.

The code below is working for 95%.
I can send a SMS and I am getting a message back.
What is not 100% working is the URL

Below, I am not getting the Lat/Lon in the URL. It comes back as
http://maps.google.com/maps?q= 52.00, 6.88

maps.google.com/maps?q=%s,%s\n

The problem is that it opens maps. But not on the correct coordinates.
How can I get this URL parsing working?

The complete code:

#include <DFRobot_sim808.h>
#include <SoftwareSerial.h>
#define MESSAGE_LENGTH 160

char message[MESSAGE_LENGTH];
int messageIndex = 0;
char MESSAGE[300];
char lat[12];
char lon[12];
char wspeed[12];

char phone[16];
char datetime[24];

#define PIN_TX    3
#define PIN_RX    2
SoftwareSerial mySerial(PIN_TX,PIN_RX);
DFRobot_SIM808 sim808(&mySerial);//Connect RX,TX,PWR,

void setup()
{
  mySerial.begin(9600);
  Serial.begin(9600);

  //******** Initialize sim808 module *************
  while(!sim808.init())
  {
      Serial.print("Sim808 init error\r\n");
      delay(1000);
  }
  delay(3000);

  if( sim808.attachGPS())
      Serial.println("Open the GPS power success");
  else 
      Serial.println("Open the GPS power failure");
      
  Serial.println("Init Success, please send SMS message to me!");
}

void loop()
{
  //*********** Detecting unread SMS ************************
   messageIndex = sim808.isSMSunread();

   //*********** At least, there is one UNREAD SMS ***********
   if (messageIndex > 0)
   { 
      Serial.print("messageIndex: ");
      Serial.println(messageIndex);
      
      sim808.readSMS(messageIndex, message, MESSAGE_LENGTH, phone, datetime);
                 
      //***********In order not to full SIM Memory, is better to delete it**********
      sim808.deleteSMS(messageIndex);
      Serial.print("From number: ");
      Serial.println(phone);  
      Serial.print("Datetime: ");
      Serial.println(datetime);        
      Serial.print("Recieved Message: ");
      Serial.println(message); 

    while(!sim808.getGPS())
    {
      
    }

   
      Serial.print(sim808.GPSdata.year);
      Serial.print("/");
      Serial.print(sim808.GPSdata.month);
      Serial.print("/");
      Serial.print(sim808.GPSdata.day);
      Serial.print(" ");
      Serial.print(sim808.GPSdata.hour);
      Serial.print(":");
      Serial.print(sim808.GPSdata.minute);
      Serial.print(":");
      Serial.print(sim808.GPSdata.second);
      Serial.print(":");
      Serial.println(sim808.GPSdata.centisecond);
      Serial.print("latitude :");
      Serial.println(sim808.GPSdata.lat);
      Serial.print("longitude :");
      Serial.println(sim808.GPSdata.lon);
      Serial.print("speed_kph :");
      Serial.println(sim808.GPSdata.speed_kph);
      Serial.print("heading :");
      Serial.println(sim808.GPSdata.heading);
      Serial.println();
  
      float la = sim808.GPSdata.lat;
      float lo = sim808.GPSdata.lon;
      float ws = sim808.GPSdata.speed_kph;
  
      dtostrf(la, 6, 2, lat); //put float value of la into char array of lat. 6 = number of digits before decimal sign. 2 = number of digits after the decimal sign.
      dtostrf(lo, 6, 2, lon); //put float value of lo into char array of lon
      dtostrf(ws, 6, 2, wspeed);  //put float value of ws into char array of wspeed
    
      //sprintf(MESSAGE, "Latitude : %s\nLongitude : %s\nWind Speed : %s kph\nMy Module Is Working. Try With This Link.\nhttp://www.latlong.net/Show-Latitude-Longitude.html\nhttp://maps.google.com/maps?q=%s,%s\n", lat, lon, wspeed, lat, lon);
      sprintf(MESSAGE, "Latitude : %s\nLongitude : %s\nWind Speed : %s kph\nMy Module Is Working.\nhttp://maps.google.com/maps?q=%s,%s\n", lat, lon, wspeed, lat, lon);
      
       Serial.println("Sim808 init success");
       Serial.println("Start to send message ...");
       Serial.println(MESSAGE);
       Serial.println(phone);
       sim808.sendSMS(phone,MESSAGE);
      //************* Turn off the GPS power ************
      //sim808.detachGPS();
      
   }
}

What about the rest of the message? Does the received SMS say:

Latitude : 52.00
Longitude : 6.88
Wind Speed : 0.00 kph
My Module Is Working.
http://maps.google.com/maps?q=%s,%s

Or does it say:

Latitude : %s
Longitude : %s
Wind Speed : %s kph
My Module Is Working.
http://maps.google.com/maps?q=%s,%s

Hi,

It is giving back:

Latitude : 52.00
Longitude : 6.88
Wind Speed : 0.00 kph
My Module Is Working.
Google Maps 52.00, 6.88

This part is also underlined and can be clicked:
http://maps.google.com/maps?q=

The last part is missing from the underlined part
52.00, 6.88

This is not connected to the URL whom should be clicked on.

The blanks in lat, lon are a problem. Delete them from the lat, lon strings.

Or try something like this:

sprintf(MESSAGE, "Latitude : %s\nLongitude : %s\nWind Speed : %s kph\nMy Module Is Working.\nhttp://maps.google.com/maps?q=%s,%s\n", lat, lon, wspeed, &lat[1], &lon[1]);

Hi jremington,

It worked for half of the coordinates. The "52.00" is in the URL.
It's only missing the last part ", 6.08" That is

Latitude : 52.00
Longitude : 6.88
Wind Speed : 0.00 kph
My Module Is Working.
Google Maps, 6.88

You have any idee? :confused:

sprintf(MESSAGE, "Latitude : %s\nLongitude : %s\nWind Speed : %s kph\nMy Module Is Working.\nhttp://maps.google.com/maps?q=%s,%s\n", lat, lon, wspeed, &lat[1],&lon[1]);

Get rid of the other blank. Try using &lon[2] in sprintf.

Better, use the string processing functions in the <string.h> library to remove them.

HI,

That whats stupid of me! Thanks it works!!

     dtostrf(la, 6, 2, lat);

The '6' is the MINIMUM width. You're telling it to pad the string out to 6 characters with leading spaces. I think you want:

     dtostrf(la, 0, 2, lat);

DON'T pad with spaces.