I have been trying to figure out what I am doing wrong here. Below is my code and the issue is that in the Ubidots account the context for lat and lng is formatted wrong. The decimal is in the wrong place and the longitude seems to be missing the “-”. Any help or advice is appreciated I have have searched google for anything and tried various things with no luck.
Result in Ubidots context:
{“lat”:“4838.94433594”,“lng”:“11719.44531250”}
the result should be {“lat”:“48.3894433594”,“lng”:"-117.1944531250"}
My code:
double latitude = 0;
double longitude = 0;
AssetTracker t = AssetTracker();
void setup() {
// Sets up all the necessary AssetTracker bits
t.begin();
// Enable the GPS module. Defaults to off to save power.
t.gpsOn();
}
void loop() {
t.updateGPS();
float lat = t.readLat();
latitude = (double)lat;
float lon = t.readLon();
longitude = (double)lon;
float speed = 168;
/* Harcoded Coordinates */
//float latitude = latitudeA;
//float longitude = longitudeA;
/* Reserves memory to store context keys values, add as much as you need */
char* str_lat = (char *) malloc(sizeof(char) * 20);
char* str_lng = (char *) malloc(sizeof(char) * 20);
/* Saves as char the coordinates */
sprintf(str_lat, "%f", latitude);
sprintf(str_lng, "%f", longitude);
/* Reserves memory to store context array */
char* context = (char *) malloc(sizeof(char) * 30);
/* Adds context key-value pairs */
ubidots.addContext("lat", str_lat);
ubidots.addContext("lng", str_lng);
/* Builds the context with GPS coordinates to send to Ubidots */
ubidots.getContext(context);
/* Sends the position */
ubidots.add("position", speed, context); // Change for your variable name
bool bufferSent = false;
bufferSent = ubidots.send(); // Will send data to a device label that matches the device Id
if(bufferSent){
// Do something if values were sent properly
//Serial.println("Values sent by the device");
}
/* frees memory */
free(str_lat);
free(str_lng);
free(context);
delay(5000);
}