Issue With Combing Char Arrays

Hi all, I'm currently working on a telemetry transmitter for a weather balloon and I've been having some issues when it comes to creating the comment with data that comes down with the gps data. Although everything technically works fine, I want to send as little telemetry data as possible, and for example, if I'm not above 100,000 feet (6 digits), it sets spaces for all the digits that aren't being used, instead of just not transmitting them.

Here is the transmission code:

void APRSUpdate() {

  
  Serial.println("APRS Update");

  //Get GPS lat/long data
  gps.crack_datetime(&year, &month, &day, &hour, &minute, &second, NULL, &age);
  gps.get_position(&lat, &lon, &age);

  //Set the GPS lat/long
  APRS_setLat((char*)deg_to_nmea(lat, true));
  APRS_setLon((char*)deg_to_nmea(lon, false));

  //Get GPS alt/mph/sats data
  float falt = gps.f_altitude();
  float fmph = gps.f_speed_mph();
  float fsats = gps.satellites();
  
 
   //APRS Data comment
   char comment []= "Arduino APRS Weather Balloon Test  -  Altitude: 000000FT Speed: 000MPH Sats: 00";

   //Define GPS data arrays to store the data
   char alt[6];
   char mph[4];
   char sats[2];
 
 
   //Convert the GPS data floats to the char arrays
   dtostrf(falt*3.281,6,0,alt);
   dtostrf(fmph,4,0,mph);
   dtostrf(fsats,2,0,sats);
  
   //Convert the altitude char to the comment char
   comment[48] = alt[0];
   comment[49] = alt[1];
   comment[50] = alt[2];
   comment[51] = alt[3];
   comment[52] = alt[4];
   comment[53] = alt[5];

   //Convert the mph char to the comment char
   comment[64] = mph[0];
   comment[65] = mph[1];
   comment[66] = mph[2];

   //convert the sats char to the comment char
   comment[77] = sats[0];
   comment[78] = sats[1];

   //Transmit it all
   Serial.println(comment);
   Serial.println(alt);
   Serial3.end();
  delay(1000);
   APRS_sendLoc(comment, strlen(comment));
   Serial3.begin(9600);
}

And here would be an example of the output I would get:

Arduino APRS Weather Balloon Test  -  Altitude:     67FT Speed:    MPH Sats:  5

You can see that before the 67 Feet, there are 5 extra spaces, that's quite a bit of extra data and it doesn't look very neat.

The reason for this issue is because I have a fixed main comment, and I just substitute the data in for the 0s. I was wondering if there was a way I could combine the data with the main comment in a different way, that would stop this from happening.

Noah

Perhaps instead of doing all of the substitution, you could use the strcat() function and concatenate the various text and variables together.

By the way, I believe your alt and sats variables in your original code need to be one character larger to account for the ending null characters.

This seems to an inefficient way to send the data:

   char comment []= "Arduino APRS Weather Balloon Test  -  Altitude: 000000FT Speed: 000MPH Sats: 00";

Is there some reason this has to be formatted this way? If you have control of how the data is parsed on the receiver you could transmit much less data, even if you still use characters. In the simplest example you could transmit a comma or space delimited string in which the interpretation is based on the position of the data. Like this:

"67,23,5"

Which would be an altitude of 67 feet, speed of 23 mph, and 5 satellites.

ToddL1962:
This seems to an inefficient way to send the data:

   char comment []= "Arduino APRS Weather Balloon Test  -  Altitude: 000000FT Speed: 000MPH Sats: 00";

Is there some reason this has to be formatted this way? If you have control of how the data is parsed on the receiver you could transmit much less data, even if you still use characters. In the simplest example you could transmit a comma or space delimited string in which the interpretation is based on the position of the data. Like this:

"67,23,5"

Which would be an altitude of 67 feet, speed of 23 mph, and 5 satellites.

That might have been important to specify in the beginning, I'm am using a data packet transfer network for ham radio operators called APRS (Automatic Packet Reporting System). Although I could just send "67, 23, 5," the data is automatically put on a public website through receiver stations and anyone can see the data, so I'd prefer for it to look a bit neater.

Noah

Hate to burst your balloon...

But, did you know that commercial GPS receivers generally won't work above 60,000 ft?
(Or 1,000 Kts, but that isn't a problem for balloons).

Part 121, Category 15 of the International Traffic in Arms Regulation (ITAR) currently prohibits GPS receivers in commercial products from producing navigation data above 60,000 ft (18.3 km) while traveling at speeds greater than 1,000 knots (1852 km/h) [1].

(Reference)

Most manufacturers of GPS receivers read this as "or" just to be safe

SteveMann:
Hate to burst your balloon...

But, did you know that commercial GPS receivers generally won't work above 60,000 ft?
(Or 1,000 Kts, but that isn't a problem for balloons).

Part 121, Category 15 of the International Traffic in Arms Regulation (ITAR) currently prohibits GPS receivers in commercial products from producing navigation data above 60,000 ft (18.3 km) while traveling at speeds greater than 1,000 knots (1852 km/h) [1].

(Reference)

Most manufacturers of GPS receivers read this as "or" just to be safe

Ah lucky for us amateur balloon launters, there is one exception. Companies can sell modules that work above 60,000 feet as long as you're below a certain speed. I am using the adafruit ultimate GPS module which is pretty much the most overkill GPS you could ever find.

Noah517:
That might have been important to specify in the beginning, I'm am using a data packet transfer network for ham radio operators called APRS (Automatic Packet Reporting System). Although I could just send "67, 23, 5," the data is automatically put on a public website through receiver stations and anyone can see the data, so I'd prefer for it to look a bit neater.

Noah

Gotcha.