Double treated+sent as float
T1j3ff opened this issue · comments
Please forgive me if the solution is obvious ,
I'm a bit new to InfluxDB and Grafana
I'm trying to send Double variable to InfuxDB 2.0 . (8bytes precision)
But both the printed back variable on the console, and the data receive in InfluxDB seems to be of normal 4bytes float precision.
Using ESP32
Arduino Suite 1.8.19
InfluxDB 2.0
#include <WiFiMulti.h>
WiFiMulti wifiMulti;
#include <InfluxDbClient.h>
#include <InfluxDbCloud.h>
#define WIFI_SSID "xxxxx"
#define WIFI_PASSWORD "xxxxx"
#define INFLUXDB_URL "http://192.168.xx.xx:8086"
#define INFLUXDB_TOKEN "xxxxxx"
#define INFLUXDB_ORG "LoraOrganisation"
#define INFLUXDB_BUCKET "LoraBucket4"
double Latitude = 45.605489;
double Longitude = -73.685757;
InfluxDBClient client(INFLUXDB_URL, INFLUXDB_ORG, INFLUXDB_BUCKET, INFLUXDB_TOKEN, InfluxDbCloud2CACert);
Point gps_point("gps_point06"); // -->_measurement
void setup() {
Serial.begin(115200);
WiFi.mode(WIFI_STA);
wifiMulti.addAP(WIFI_SSID, WIFI_PASSWORD);
Serial.println("Connecting to wifi");
while (wifiMulti.run() != WL_CONNECTED) {
Serial.println(".");
delay(100);
}
timeSync("EST5EDT", "pool.ntp.org", "time.nis.gov");
// Check server connection
if (client.validateConnection()) {
Serial.print("Connected to InfluxDB: ");
Serial.println(client.getServerUrl());
} else {
Serial.print("InfluxDB connection failed: ");
Serial.println(client.getLastErrorMessage());
}
}
void loop() {
Serial.println("------------MAIN-------------");
Serial.print("Latitude Long Variable: "); Serial.println( Latitude,6);
Serial.print("Longitude Long Variable: "); Serial.println(Longitude,6);
gps_point.clearFields();
gps_point.addField("Latitude", Latitude);
gps_point.addField("Longitude", Longitude);
Serial.print("Writing: ");
Serial.println(gps_point.toLineProtocol());
if (wifiMulti.run() != WL_CONNECTED) { // Check WiFi connection and reconnect if needed
Serial.println("Wifi connection lost");
}
if (!client.writePoint(gps_point)) {
Serial.print("InfluxDB write failed: ");
Serial.println(client.getLastErrorMessage());
}
delay(1000);
}
@JFPayeur, same as in Serial.println(Longitude,6);
, you can specify a custom precision in Point::addField
. The default is, as you can see in your log, 2 fractional digits:
void addField(const String &name, float value, int decimalPlaces = 2);
void addField(const String &name, double value, int decimalPlaces = 2);
https://github.com/tobiasschuerg/InfluxDB-Client-for-Arduino/blob/master/src/Point.h#L50