My Latitude/Longitude only shows 3 decimals


#1

I use the following arduino code to send lat/log to cayenne using MQTT

typedef struct {
char Recno1{2};
char Date[7];
char Time[7];
float Latitude;
float Longitude;
int ActualCourse;
int CalcCourse;
float Speed;
} RECORD1;

RECORD1 rec1;

Cayenne.virtualWrite(1,  rec1.Latitude, "text", "");
Cayenne.virtualWrite(2,  rec1.Longitude, "text", "");

If I Serial.print these fields, they show data to 5 decimal places.
However Cayenne shows three decimals and two zeros.
Untitled
When I download the chart data, it shows only 3 decimals
How do I get the full 5 decimals, as I need 4-5 decimals of accuracy


#2

can you post the entire code.


#3

Here is the code

//#define CAYENNE_DEBUG
#define CAYENNE_PRINT Serial
#include <CayenneMQTTESP8266.h>
#include <SoftwareSerial.h>
#include <Wire.h>
#include <SPI.h>
#ifdef __AVR__
  #include <avr/power.h>
#endif

// WiFi network info.
char ssid[] = "?????";
char wifiPassword[] = "?????";

// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username[] = "?????";
char password[] = "?????";
char clientID[] = "?????";

unsigned long lastMillis = 0;

typedef struct {
   float Latitude = 33.12345;
   float Longitude = -151.78901;
   int ActualCourse = 60;
   int CalcCourse = 359;
   float Speed = 4.7;
 }  RECORD1;

RECORD1 rec1;

void setup() 
{

  Serial.begin(115200);
  Cayenne.begin(username, password, clientID, ssid, wifiPassword);
 while (!Serial) { delay(1); } // wait until serial console is open, remove if not tethered to computer

}

void loop() {

 Cayenne.loop();

          SendToCayenne();
  }
  
 void SendToCayenne()
{

  //Publish data every 30 seconds (30000 milliseconds). Change this value to publish at a different interval.
 if (millis() - lastMillis > 30000) {
   lastMillis = millis();
    
 //Write data to Cayenne here.   
     Serial.print("Cayenne Latitude");Serial.println(rec1.Latitude,5);
    Cayenne.virtualWrite(1,  rec1.Latitude, "text", "");
    Cayenne.virtualWrite(2,  rec1.Longitude, "text", "");
    Cayenne.virtualWrite(3,  rec1.CalcCourse, "analog_sensor", "null");
    Cayenne.virtualWrite(4,  rec1.Speed, "wind_speed", "kmh");
    Cayenne.virtualWrite(17,  rec1.ActualCourse, "analog_sensor", "null");
    
  }

}

#4

use dtostrf() which will convert a float to a char array and then send it.


#5

Thanks for that. It worked!
The ironic thing is that another program sends the data to this program as char fields, and I was converting to float to send to cayenne