Quick question: I want to pass on GPS data as one single variable, and then using the Auto-location option to have it live-update on the map.
However, what format is recommended for this? Would a format such as 49.5473, -126.4312 (while named ‘gps’) be okay? Does it also matter which data-type is used for this?
Hardware is the Particle Electron 3G. Current way of sending data is as follow:
{“lat”: “%.04f”, “lon”: “%.04f”} , creating two seperate variables
the sprintf() is a special C function to create char arrays, simply store your latitude and longitude inside two variables and add it to the char array. You can reference to the usage of sprintf() here.
float value1 = analogRead(A0);
char context[25];
sprintf(context, "%.2f, %.2f", lat, lng); //Sends latitude and longitude for watching position in a map
Serial.println(context);
ubidots.add("gps", value1, context); // Change for your variable name
ubidots.sendAll();
delay(5000);
The serial prints 49.19, -123.10 but the Ubidots variable is no longer updated anymore. When I do sprintf(context, “%.2f %.2f”, lat, lng) (note the lack of comma) the data sends, but doesn’t update the location on the Dashboard.
Nevermind, I think I solved it. If anyone reading this wonders how, this code should do the trick:
float value1 = analogRead(A0);
char context[25];
sprintf(context, "lat=%.2f$lng=%.2f", lat, lng); //Sends latitude and longitude for watching position in a map
Serial.println(context);
ubidots.add("gps", value1, context); // Change for your variable name
ubidots.sendAll();
delay(5000);