Gps Asset tracker issue

I’m trying to get this woking, very new to particle experiments… I’m trying to read Gps some how it is not posting
Lat and Lon to my data sheet. can someone help please.

#include "AssetTracker.h"


int transmittingData = 1;

long lastPublish = 0;

int delayMinutes = 2;

AssetTracker t = AssetTracker();

FuelGauge fuel;

void setup() {
    t.begin();
    
    t.gpsOn();
    
    Serial.begin(9600);
    
    Particle.function("tmode", transmitMode);
    Particle.function("batt", batteryStatus);
    Particle.function("gps", gpsPublish);
    Particle.keepAlive();
}

void loop() {
    t.updateGPS();

    if(millis()-lastPublish > delayMinutes*60*1000){
        lastPublish = millis();
        
        Serial.println(t.preNMEA());
        if(t.gpsFix()){
            if(transmittingData){
                Particle.publish("G", t.readLatLon(), 60, PRIVATE);
            }
            Serial.println(t.readLatLon());
        }
    }
}

int transmitMode(String command){
    transmittingData = atoi(command);
    return 1;
}

int gpsPublish(String command){
    if(t.gpsFix()){ 
        Particle.publish("G", t.readLatLon(), 60, PRIVATE);
        
        return 1;
    }
    else { return 0; }
}

int batteryStatus(String command){
    Particle.publish("B", 
          "v:" + String::format("%.2f",fuel.getVCell()) + 
          ",c:" + String::format("%.2f",fuel.getSoC()),
          60, PRIVATE
    );
    if(fuel.getSoC()>10){ return 1;} 
    else { return 0;}
}

Have you got a fix on the GPS receiver?
Do you get serial output?

Hi Thankyou so much… for response, Dont know, when I run my electron events from my “particle” application on phone… Batery event returns “1” with values. But Gps is returning “0” with error. What exact serial output means?? Kindly let me know i will check it and let you know…

Your code features lines like this

  Serial.println(t.preNMEA());
  // or
  Serial.println(t.readLatLon());

When you have your Electron connected via USB to a computer you can use a serial terminal (or Particle CLI via particle serial monitor) to catch these outputs and see what's going on with your code.

That's exactly the reason why I asked[quote="ScruffR, post:2, topic:32041"]
Have you got a fix on the GPS receiver?
[/quote]

Since this code only reports data when you have

    if(t.gpsFix()){  // <-- only once you got a GPS fix you can read the data!!!
        Particle.publish("G", t.readLatLon(), 60, PRIVATE);
        
        return 1;
    }
1 Like

I see thank you Scruff, I appreciate that. Actually, it was copied code from online tried personally with interest, could you give me sample code to do or something to post Lat and Lon from Electron for each minute.

I’m a dot net developer, sometimes I do interest doing this experiment can you help me if possible.

Thanks for a very frequent response for my experiment.

@Ghani, the code WILL work as is but ONLY once a fix is obtained. Once a fix is obtained, it will publish every delayMinutes. So if you want data every minute, set delayMinutes to 1.

1 Like

Okay Thank you so much for that. I will try it and let you know.

tried to get this it is replying me this error. Can you help me how to remove associated user except me.