HI
I have my GPS connected up to the Argon and can see it working just using the default package example and using putty on my COM3 port to verify values are displaying.
What i am trying to do is convert this so i can publish it as part of a JSON file.
So the following works on Putty COM3 serial port with no issues;
#include "Particle-GPS.h"
// ***
// *** Create a Gps instance. The RX an TX pins are connected to
// *** the TX and RX pins on the electron (Serial1).
// ***
Gps _gps = Gps(&Serial1);
// ***
// *** Create a timer that fires every 1 ms to capture
// *** incoming serial port data from the GPS.
// ***
Timer _timer = Timer(1, onSerialData);
void setup()
{
delay(2000);
// ***
// *** Initialize the USB Serial for debugging.
// ***
Serial.begin();
Serial.println("Initializing...");
// ***
// *** Initialize the GPS.
// ***
_gps.begin(9600);
// ***
// *** Start the timer.
// ***
_timer.start();
}
void onSerialData()
{
_gps.onSerialData();
}
void loop()
{
// ***
// *** Get the Antenna Status ($PGTOP).
// ***
Pgtop pgtop = Pgtop(_gps);
if (pgtop.parse())
{
Serial.println("1) Antenna Status ($PGTOP)");
Serial.println("======================================================");
Serial.print("Command ID: "); Serial.println(pgtop.commandId);
Serial.print("Antenna Status: "); Serial.println(pgtop.reference);
Serial.println("");
}
// ***
// *** Get the Global Positioning System Fixed Data ($GPGGA).
// ***
Gga gga = Gga(_gps);
if (gga.parse())
{
Serial.print("UTC Time: "); Serial.println(gga.utcTime);
Serial.print("Latitude: "); Serial.println(gga.latitude);
Serial.print("North/SouthIndicator: "); Serial.println(gga.northSouthIndicator);
Serial.print("Longitude: "); Serial.println(gga.longitude);
Serial.print("East/WestIndicator: "); Serial.println(gga.eastWestIndicator);
}
// ***
// *** Get the Recommended Minimum Navigation Information ($GPRMC).
// ***
Rmc rmc = Rmc(_gps);
if (rmc.parse())
{
Serial.println("3) Recommended Minimum Navigation Information ($GPRMC)");
Serial.println("======================================================");
Serial.print("UTC Time: "); Serial.println(rmc.utcTime);
Serial.print("Latitude: "); Serial.println(rmc.latitude);
Serial.print("North/SouthIndicator: "); Serial.println(rmc.northSouthIndicator);
Serial.print("Longitude: "); Serial.println(rmc.longitude);
Serial.print("East/WestIndicator: "); Serial.println(rmc.eastWestIndicator);
}
delay(1000);
}
However, what i am trying to achieve is rewrite this so i can publish the co-ordinates into a JSON file to my Particle device when i attempt to compile the code below it gives an error. I am not very good at the C languageā¦
My code is as follows (basically just want to return one value for now);
// This #include statement was automatically added by the Particle IDE.
#include "Particle-GPS.h"
//GPS Setup
// ***
// *** Create a Gps instance. The RX an TX pins are connected to
// *** the TX and RX pins on the electron (Serial1).
// ***
Gps _gps = Gps(&Serial1);
// ***
// *** Create a timer that fires every 1 ms to capture
// *** incoming serial port data from the GPS.
// ***
Timer _timer = Timer(1, onSerialData);
void setup() {
Wire.begin();
Serial.begin();
_timer.start();
void loop() {
// *** Get the Antenna Status ($PGTOP).
Pgtop pgtop = Pgtop(_gps);
// *** Get the Global Positioning System Fixed Data ($GPGGA).
// ***
Gga gga = Gga(_gps);
// create JSON ojects set ups
char buf[622];
memset(buf, 0, sizeof(buf));
JSONBufferWriter writer(buf, sizeof(buf)-1);
writer.beginObject();
addToJSON(writer);
writer.endObject();
Particle.publish("JSON", String(buf), PRIVATE);
delay(10000);
toggleLed();
}
// function to add to JSON object
void addToJSON(JSONBufferWriter &writer){
writer.name("UTCTime").value(String(Gga.utcTime)));
}
void onSerialData()
{
_gps.onSerialData();
}
The issue is to do with the line;
writer.name("UTCTime").value(String(Gga.utcTime)));
Specifically, i am just trying to get the utcTime. In the example that works this is done by;
Serial.print("UTC TIme: "); Serial.println(gga.utcTime);