I have been trying to get my GPS to work. But I am not getting the right output. I have got right output with the same code once in like 100 times. But I am not sure what I am doing wrong. Is it my network ? It is not getting the signal ?
This is my code :
#include <string>
using namespace std;
int sleep = 10 * 1000; // Every 10 seconds publish
string sentence;
void setup(){
Serial1.begin(9600); // serial1 represents the tx/rx pins
Serial.begin(9600);
}
void loop(){
for (unsigned long start = millis(); millis() - start < 1000;){
// Check GPS data is available
while (Serial1.available()){
char c = Serial1.read();
if(c == '\n') { // end of sentence
Serial.println(String(sentence.c_str()));
if(sentence.find("$GPGGA") == 0){
Serial.println("---- There is GPGGA in the sentence ------");
Particle.publish("gpsloc", sentence.c_str());
Serial.println("--------------------");
Serial.println(String(sentence.c_str()));
}
sentence = "";
} else {
sentence += c;
}
}
}
delay(sleep);
}
OUTPUT:
$GPGGA,,,,,,0,00,99.99,,,,,,*48
---- There is GPGGA in the sentence ------
--------------------
$GPGGA,,,,,,0,00,99.99,,,,,,*48
$GPGSA,A,1,,,,,,,,,,,,,99.99,99.99,99.99*30
$GPGLL,,,,,,V,N*64
$GPRMC,,V,,,,,,,,,,N*53
$GPVTG,,,,,,,,,N*30GPGLL,,,,,,V,N*64
$GPRMC,,V,,,,,,,,,,N*53
$GPVTG,,,,,,,,,N*30
$GPGGA,,,,,,0,00,99.99,,,,,,*48
---- There is GPGGA in the sentence ------
--------------------
$GPGGA,,,,,,0,00,99.99,,,,,,*48
$GPGSA,A,1,,,,,,,,,,,,,99.99,99.99,99.99*30
$GPGLL,,,,,,V,N*64
$GPRMC,,V,,,,,,,,,,N*53
PGLL,,,,,,V,N*64*30
$GPRMC,,V,,,,,,,,,,N*53
$GPVTG,,,,,,,,,N*30
$GPGGA,,,,,,0,00,99.99,,,,,,*48
---- There is GPGGA in the sentence ------
--------------------
$GPGGA,,,,,,0,00,99.99,,,,,,*48
$GPGSA,A,1,,,,,,,,,,,,,99.99,99.99,99.99*30
I am trying to get the Latitudes and Longitudes. But it is not happening.