Getting Particle publish to receive proper Data

Ok so here is the Serial outpout

//===========================================================
Audio__6
 R[32676] IR[30811] G[2137]
3) Recommended Minimum Navigation Information ($GPRMC)
======================================================
Latitude: 2057.1154
Longitude: 10521.2598
Speed Over Ground: 0.52

Temperature = 35.27 *C
Pressure = 1013.70 hPa
Approx. Altitude = -3.77 m
Humidity = 64.83 %
///======================================

So my code is working properly now when I particle publish the code it comes out like this

Latitude 0.000000,Longitude 1013.723145,Speed -536870912


////===============================================================

I’ve tried the following to no avail

char message4[128];
int Speed = (rmc.speedOverGround);
sprintf(message4,"Latitude \%2s\,Longitude \%s\,Speed %.2d",(rmc.latitude),(rmc.longitude),Speed) ;
Particle.publish("Sensor_Array4",message4,PRIVATE);
delay(100); 
//==========================================
char message4[128];
int Speed = (rmc.speedOverGround);
sprintf(message4,"Latitude %d,Longitude %d,Speed %.2d",(rmc.latitude),(rmc.longitude),Speed) ;
Particle.publish("Sensor_Array4",message4,PRIVATE);
delay(100); 
//=============================================

char message4[128];
int Speed = (rmc.speedOverGround);
sprintf(message4,"Latitude %f,Longitude %f,Speed %.2d",(rmc.latitude),(rmc.longitude),Speed) ;
Particle.publish("Sensor_Array4",message4,PRIVATE);
delay(100); 

Is there any helpful tips in getting the String to come out properly in Particle Publish ??

This is what I had to learn to build proper strings to combine lots of data into one Particle publish event.

That doesn’t make sense. "%d" would indicate an integer value and "%.2" would suggest you want two decimal places. Integers have no decimal places.
If you want to format a floating point type like float or double you’d use "%.2f"

You need to find out what datatype you want to feed into the string and then select the appropriate format place holder

Have a look at this
http://www.cplusplus.com/reference/cstdio/printf/

Thanks

1 Like