[SOLVED] Ubidots map, Particle Photon

Hello,
I am trying to put a location widget from my Particle code. I put instead of value=1 the accuracy of my location as a float. The converted sprintf function however, does not show up the location of my device and both the lng and lat values seem to be zero. I am not at that location :smiley: My code is attached below, what would you suggest to be done in order to resolve this problem?
Hope to hear from someone soon,
Kerem

#include <Ubidots.h>
#ifndef TOKEN
#define TOKEN "token"  // Put here your Ubidots TOKEN
#endif
#include <google-maps-device-locator.h>
Ubidots ubidots(TOKEN);
GoogleMapsDeviceLocator locator;
void setup() {
  Serial.begin(9600);
  // Scan for visible networks and publish to the cloud every 30 seconds
  // Pass the returned location to be handled by the locationCallback() method
  locator.withSubscribe(locationCallback).withLocatePeriodic(30);
}

void locationCallback(float lat, float lon, float accuracy) {
  float lng=lon;
  char context[25];
  sprintf(context, "lat=%8.4f lng=%8.4f"); //Sends latitude and longitude for watching position in a map
  ubidots.add("position",accuracy,context);  // Change for your variable name
  bool bufferSent = false;
  if(ubidots.isDirty()){  // There are stored values in buffer
      bufferSent = ubidots.sendAll();
  }
  if(bufferSent){
      // Do something if values were sent properly
      Serial.println("Values sent by the device");
  }
}  
void loop() {
  locator.loop();
  

}
void locationCallback(float lat, float lon, float accuracy) {
  float lng=lon;
  char context[50];
  sprintf(context, "lat=%f",lat,"lng=%f", lng); //Sends latitude and longitude for watching position in a map
  ubidots.add("position",accuracy,context);  // Change for your variable name
  bool bufferSent = false;
  if(ubidots.isDirty()){  // There are stored values in buffer
      bufferSent = ubidots.sendAll();
  }
  if(bufferSent){
      // Do something if values were sent properly
      Serial.println("Values sent by the device");
  }
}  

With this edit, I managed to get the location in the context, and the correct location is visible in the ubidots system too, but I still cannot make it show up on the map. What is the problem in here?

2018-07-30 08:36:04 -04:00 1.00 lat:41.106052
2018-07-30 08:35:34 -04:00 1.00 lat:41.106010
2018-07-30 08:34:47 -04:00 1.00 lat:41.106030
2018-07-30 07:57:00 -04:00 1.00 lat:41.106026
2018-07-30 07:56:23 -04:00 1.00 lat:41.11
2018-07-30 07:55:53 -04:00 1.00 lat:41.11
This is a sample to show how my data is showing up. I tried rounding to get lng values but it did not work :confused:

Hello @keremulcay,

As I can notice in your code, your trying to build the variable context in a wrong way. If you note, you’re assigning the variable context as follows:

Please remember the sprint function structure:

sprintf (char *string, const char *format, … );

In that sense, your code line should look like this:

sprint(context, "lat=%f$lng=%f", lat, lng)

Please note that you’re to replace the lat and lng values with the actual coordinates of your device.
Also, refer to the library docs here: GitHub - ubidots/ubidots-particle: Library for uploading Particle devices to Ubidots

I hope this provide the clearance you were looking for.

All the best,
-David

1 Like

I saw that you created this account just to answer me. I appreciate your dedication. I will get back to you as soon as possible :sunny:

Thank you, my problem got resolved!

Hey @keremulcay,

I’m glad to know you were able to solve your issue.

All the best,

–David

1 Like