Get rid of the white spaces in URL

Hey,

Could any one help me to solve this problem?: I want to print the URL correctly ,so I need to print latitude and longitude without white spaces

float la = sim808.GPSdata.lat;
 float lo = sim808.GPSdata.lon;
  float w = sim808.GPSdata.speed_kph;
  
dtostrf(la, 6, 2,latitude ); //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,longitude ); 
 dtostrf(w, 6, 2,ws);   

    //************* Turn off the GPS power ************
    sim808.detachGPS();

 Serial.println("mesaage is");
 sprintf(MESSAGE, "Latitude : %s\nLongitude : %s\nWind Speed : %s kph\nMy Module Is Working.Try With This Link.\n", latitude, longitude, ws);
 sprintf(MESSAGE2,"http://www.latlong.net/c/?lat=%s&long=%s",latitude,longitude);
 Serial.println(MESSAGE2);
  // sim808.sendSMS(PHONE_NUMBER,MESSAGE);

The second parameter to dtostrf() is the length of the output string. If you only want a length of 5 why did you specify 6 ?

1 Like

you can specify zero string length in dstrotf() and it will only use as many as needed -- dtostrf (f, 0, 3, s);

-0.010
-123.010

1 Like
sprintf(MESSAGE, "Latitude : %s\nLongitude : %s\nWind Speed : %s kph\nMy Module Is Working.Try With This Link.\n", ....

The above puts a space after e.g. the word lattitude and a space after the colon. Same for longitude and so on. '\n' is used for a new line.

1 Like

dtostrf is a bit confusing, the 2nd argument is the minimum length of the output string, and will be padded with spaces when necessary. There is no specification for maximum length, other than the sum of the maximum number of digits, sign, decimal point, and leading zero if needed.

1 Like

I change this parameter to 5 and everything is fine now, thanks so much for helping :+1:

1 Like

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.