Stopping GPS fix

So I have an asset tracker and I am updating a cloud variable with the latitude and longitude. However, I am unfamiliar with the asset tracker library. The one I am using (not sure if there is more than one) is just called AssetTracker. My problem is that I want to stop the electron from updating the GPS location when a variable is equal to 1. But I do not know how to stop the updating. I would also like to resume updating the location after I stop it.

Right now I have it so it checks for a variable to be equal to 1, and if it does, it runs this code:

if(u == 1) {
            Serial.println("U is 1");
            if (t.gpsFix()) {
                // Only publish if we're in transmittingData mode 1;
                if (transmittingData) {
                    // Short publish names save data!
                    //Particle.publish("G", t.readLatLon(), 60, PRIVATE);
                    Particle.publish("G", t.readLatLon(), PRIVATE);
                    gpsLocation = t.readLatLon();
                }
                // but always report the data over serial for local development
                Serial.println(t.readLatLon());
            }
        }

I thought that when u is equal to 0, it would just stop updating, but the red light on the tracker keeps blinking and I think that is saying that it is still updating the GPS.

Thanks!

The GPS hardware will still be receiving the signals whether you (or rather the µC) reads the incoming data or not - this is what the blinking LED indicates.

But that doesn’t mean your variables will get updated - and you should see that by not getting your U is 1 output while the condition is not satisfied.

BTW, there is a more recent library AssetTrackerRK

Okay thanks,
The reason I wanted to stop it was to save data. If there is any other way to save data that you know of please let me know.

Also, what does the new library offer that the old one doesn’t?

When the GPS has a fix it doesn’t consume any data. You only consume data when you publish. So your idea of setting a variable flag to indicate when to publish and when not to publish will save you data. Just realize that the GPS module doesn’t consume data itself. The signal sent by satellites and received by your GPS module are essentially free to use without limitation.

What you really need to do is determine how often you want to publish that GPS location data. If you publish every Loop, yeah you are going to run out of data real fast. But if you implement some sort of mills-based timer then you can publish every few seconds, minutes or hours.

3 Likes

Alright I’ve implemented some new stuff. Thanks guys