AssetTrackerRK, no working

Almost two months ago I started working with the code for AssetTrackerRK, and everything was fine, but two weeks ago the code stopped showing me the GPS coordinates.

The GPS antenna indicator light starts to flash, I understand that the antenna receives the signal.
Is it possible that the serial1 port is damaged?

Anyone have any idea what is going on?

// This #include statement was automatically added by the Particle IDE.
#include <AssetTrackerRK.h>

#include "Particle.h"

#include "AssetTrackerRK.h" // only used for AssetTracker::antennaExternal

// Port of TinyGPS for the Particle AssetTracker
// https://github.com/mikalhart/TinyGPSPlus
#include "TinyGPS++.h"

SYSTEM_THREAD(ENABLED);

/*
   This sample sketch demonstrates the normal use of a TinyGPS++ (TinyGPSPlus) object directly.
 */

void displayInfo(); // forward declaration

const unsigned long PUBLISH_PERIOD = 120000;
const unsigned long SERIAL_PERIOD = 5000;
const unsigned long MAX_GPS_AGE_MS = 10000; // GPS location must be newer than this to be considered valid

// The TinyGPS++ object
TinyGPSPlus gps;
unsigned long lastSerial = 0;
unsigned long lastPublish = 0;
unsigned long startFix = 0;
bool gettingFix = false;

void setup()
{
	Serial.begin(9600);

	// The GPS module on the AssetTracker is connected to Serial1 and D6
	Serial1.begin(9600);

	// Settings D6 LOW powers up the GPS module
    pinMode(D6, OUTPUT);
    digitalWrite(D6, LOW);
    startFix = millis();
    gettingFix = true;

    // If using an external antenna, uncomment this block
    // { AssetTracker t; t.antennaExternal(); }
}

void loop()
{
	while (Serial1.available() > 0) {
		if (gps.encode(Serial1.read())) {
			displayInfo();
		}
	}

}

void displayInfo()
{
	if (millis() - lastSerial >= SERIAL_PERIOD) {
		lastSerial = millis();

		char buf[128];
		if (gps.location.isValid() && gps.location.age() < MAX_GPS_AGE_MS) {
			snprintf(buf, sizeof(buf), "%f,%f,%f", gps.location.lat(), gps.location.lng(), gps.altitude.meters());
			if (gettingFix) {
				gettingFix = false;
				unsigned long elapsed = millis() - startFix;
				Serial.printlnf("%lu milliseconds to get GPS fix", elapsed);
			}
		}
		else {
			strcpy(buf, "no location");
			if (!gettingFix) {
				gettingFix = true;
				startFix = millis();
			}
		}
		Serial.println(buf);

		if (Particle.connected()) {
			if (millis() - lastPublish >= PUBLISH_PERIOD) {
				lastPublish = millis();
				Particle.publish("gps", buf, PRIVATE);
			}
		}
	}

}

Thanks

I would strongly suggest writing some code to verify if the GPS is still outputting valid data on Serial1.

A function like this could get you started:

void verifyGPS(uint32_t time)
{
        String inputLine;
        char inputByte;
        uint32_t gpsTimeout = millis() + time;

        while (millis() <= gpsTimeout)
        {
                if (Serial1.available())
                {
                        inputByte = Serial1.read();
                        if (inputByte != -1)
                        {
                                inputLine += inputByte;
                        }
                        if (inputByte == '\n')
                        {
                                Serial.println(inputLine);
                                inputLine = "";
                        }
                }
        }
}

In your loop(), to verify the GPS for 10 seconds you could do:

verifyGPS(10000);
1 Like

thank you, I will be try