Manually update GPS position of P2

Is it possible to manually push an update to Particles GPS location for a device, either from Firmware or from an API?

The "map" section on the device page in console.particle.io is using the ISP geolocation which is obviously not as good as the GPS module onboard our device

That's not really a normal use case, since the location in the console is only visible to the product owner, and typically does not need to be precise.

If you really want it to be accurate and you know the location of the device:

  • Enable location storage for the product the device is in.
  • Have the device generate a loc event with latitude, longitude, and lck.
  • Since you don't have a GNSS chip, it would probably be necessary to send the location to the device, such as with a function call.
  • There would be at least two data operations for this.

Awesome, sorry i'm not positive from that link how to format the Particle.publish() such that it gets read correctly.

I have a json string formatted as described in your link:

{
    "cmd": "loc",
    "time": 1747937961,
    "loc": {
        "lck": 1,
        "lat": 37.295945,
        "lon": -121.98683,
        "alt": 71.6
    }
}

Here's how i'm publishing it.

  String s = {see above json string};
  Particle.publish("location", s);

but it doesn't seem to be updating the map section of the device on the console.

It's just loc not location as the event name.

Like this?

Sorry my last post was a bit unlear; i implemented the above and it's not updating the position of the device on the map. I also tried just putting the "loc" object into the data field of the message and it didn't work either.

Can you verify if this looks as expected?

Tried this format that I saw in Location Services for All - #8 by gpatt1

no luck with this either

@willdueease, I assume you saw this regarding update frequency. I'm not sure when the once a week occurs, however.

Sandbox Basic Enterprise
Device Vitals location Once per week Once per week Every update
Location fusion Yes Tracker only Yes
Non-tracker location history None None 1 or 6 months

That looks like it should work; I'll take a look later this week and make sure you can manually set the location that way. It's not a normal use case, so it's possible that you can't actually do that.

1 Like

I'm not sure why your location did not update.

  • Added a Photon 2 device to a product.
  • No location was reported.
  • Made sure location storage was enabled in the product settings.

Ran this firmware on the device:

#include "Particle.h"

SYSTEM_MODE(AUTOMATIC);

// System thread defaults to on in 6.2.0 and later and this line is not required
#ifndef SYSTEM_VERSION_v620
SYSTEM_THREAD(ENABLED);
#endif

SerialLogHandler logHandler(LOG_LEVEL_INFO);
bool locationUpdated = false;

void publishLocation();

void setup() {
}

void loop() {

    if (Particle.connected() && Time.isValid() && !locationUpdated) {
        locationUpdated = true;
        publishLocation();
    }
}

void publishLocation() {
    Variant eventData;

    eventData.set("cmd", "loc");
    eventData.set("time", Time.now());

    Variant locData;
    locData.set("lck", 1);
    locData.set("time", Time.now());
    locData.set("lat", 37.78884588502295);
    locData.set("lon", -122.40424454936864);
    
    eventData.set("loc", locData);

    Particle.publish("loc", eventData);
}

This firmware requires Device OS 6.3.0 or later because it uses the Variant option for event data, but location events built manually or using JSONWriter would not require this version.

  • This event was shown in the console event log

  • This was shown in the console device details

(The location is the old Particle San Francisco office, but I work from New York, which is where my IP address location would be.)

I also flashed different firmware that changed the location and the map updated. It doesn't update live, but it does if you close and reopen the device details. It appears that you don't have to wait a week for a manual location update using a loc event.

1 Like

ok, getting somewhere! I copied your post above, i didn't have the "time" field inside the "loc" object; maybe that had something to do with it? I DID see it update in the map to the correct location and had a timestamp that matches the test I just did, but when i refreshed the page it had reverted to the old geo-ip location and was a week old.

I wonder if my tests had been working, but theres something with the location fusion or databasing thats throwing out my newer location and preferring the old one? maybe some CDN caching stuff?

Live map updated correctly when I manually pushed a location:

If I refresh the page it reverts to a different location:

Seems like it may have been web facing issue and not a firmware/backend issue all along?

Thanks for all your help!

Is there any chance we could bug the web team about this? I'm still seeing the same behavior where I correctly publish the value, the map updates with the correct location, but if I refresh the page it reverts to the ip geolocation.