(GPS) Loss of precision in decimals (double)

Hi all,

Someone can help me to solve a problem with decimal accuracy loss.
Well, Im using a V0 pin to store a double value with 6 decimals, then when my device is off-line and reconnect I restore de value V0 from server but the value loss precision up to 2 decimals rounded value.

Any suggestions are welcome, …

Thx you!!!

Don’t use doubles in arduino, just use floats.

Show your code too since it will be a coding error.

@JovIoT do you know where precision lost happens?

Hi,

Im using Blynk.virtualWrite(V0, setLat, setLon) to store GPS location in a server, then when hardaware loss connection (off-line) and reconnect, i use to sync

these are before value Latitud:40.520695Longitud: -3.898539 and these are after value Latitud:40.521000Longitud: -3.899000, restored fron V0

BLYNK_CONNECTED() {.

//get data stored in virtual pin V0 from server
Blynk.syncVirtual(V0);

}

// restoring locatopm Gps from server V0
BLYNK_WRITE(V0)
{
//restoring double latAlert and lonAlert values
Serial.print(“Recupero posicion!!!”);
latAlert = param[0].asDouble();
lonAlert = param[1].asDouble();
}

When I restore latAler and lonAlert, they have lost precision

i hope this is more clear explanation

thx

Thanks! I’ll check.

@JovIoT what does param[0].asString(); shows? Correct string? If - yes, try to use asFloat() does that help?

@Dmitriy and all

This is before save in V0 with Blynk.virtualWrite()

  Latitud:40.520619 Longitud: -3.898647

after

tested with param[].asString() but the results are:

 Latitud:40.521 Longitud: -3.899 (restore string with 3 decimals)

tested using param[].asFloat() the results are equal to use param[].asDouble()

 Latitud:40.521 Longitud: -3.899 

I think that blynk server V0 storage value change data type. Could be?

Thx for any suggestions

@JovIoT as a workaround have you tried changing:

Latitud:40.520619 Longitud: -3.898647

to

Latitud:40520.619 Longitud: -389.8647

1 Like

No. Values are stored as strings. So this mean you sending to server rounded values. Please post your code that shows how you send values to server.

1 Like

@Dmitriy

This is de code that I use to send values

void guardaGpsAlert(double setLat, double setLon) {
//storing latAler and lonAlert double in V0 pin on server
//Serial.print(“Guardando Latitud:”); Serial.print(setLat, 6); Serial.print("Longitud: "); Serial.println(lonAlert, 6);
Blynk.virtualWrite(V0, setLat, setLon);
}

This Serial.print() shows : Latitud:40.520619 Longitud: -3.898647

thx

Hm… Interesting. @vshymanskyy do you know what that could be?

@Dmitriy

At the moment I´m using the workarround suggested by @Costas and I can keep the precission.

before sending (value * 1000) and after in recovering (value / 1000)

1 Like

Workaround is clear. However look like issue is in blynk library.
I created ticket Precision lost on Blynk.virtualWrite() · Issue #262 · blynkkk/blynk-library · GitHub

1 Like

Hi @Dmitriy ,

In this way I can test another little “bug”, when send location values to Map Widget through Blynk.location() method
the lat and lon values are rounded to 3 decimals showing always incorrect position. GPS cordinates need 6 decimals to work fine.

regards

Yes. I know. And that was tested and worked just fine. What hardware and lib version do you have?

@Dmitriy

Im using ESP8266 with Ublox shield GPS and latest blynk server version 0.22 in local, and lib version 0.4.3

Regards

Just increased precision in doubles to 7… will it be enough?

1 Like

@vshymanskyy 7 decimals is enough for GPS values. To fix this do I upgrade the server release or …?

Thank you and regards!!!

@JovIoT looks like the fix is in the client software not on the server side https://github.com/blynkkk/blynk-library/commit/159c60a3e4bd365e1b5f50e03b90abe4c09b8168
So if you pick up the master client you should have the fix. Server fixes take a little longer as it involves a different process.

2 Likes