Hello!
I've been working on this problem for a few days and haven't found a solution after much frustration. I'm attempting to modify the library according to @adafruit_support_rick's instructions but I'm having no luck (I've modified the library already to extract all other values but UTC data/time won't cooperate).
Here are code and results from a sketch I modified based on the FONA GPS Test. It displays data from the call to fona.getGPS. I also included modifications I made to the FONA library. All values get returned as expected except UTC Date/Time. What am I doing wrong??
GPStest.ino sketch:
Code: Select all
/*
* This example is meant to work with the Adafruit
* FONA 808 or 3G Shield or Breakout
*
* Copyright: 2015 Adafruit
* Author: Todd Treece
* Licence: MIT
*
*/
#include "Adafruit_FONA.h"
// standard pins for the shield, adjust as necessary
#define FONA_RX 2
#define FONA_TX 3
#define FONA_RST 4
#define TS_LENGTH 16
char timestamp[TS_LENGTH] = "";
float latitude, longitude, speed_kph, heading, altitude, HDOP, VDOP, used_sats, HPA, VPA;
// We default to using software serial. If you want to use hardware serial
// (because softserial isnt supported) comment out the following three lines
// and uncomment the HardwareSerial line
#include <SoftwareSerial.h>
SoftwareSerial fonaSS = SoftwareSerial(FONA_TX, FONA_RX);
SoftwareSerial *fonaSerial = &fonaSS;
// Hardware serial is also possible!
// HardwareSerial *fonaSerial = &Serial1;
Adafruit_FONA fona = Adafruit_FONA(FONA_RST);
// Have a FONA 3G? use this object type instead
//Adafruit_FONA_3G fona = Adafruit_FONA_3G(FONA_RST);
void setup() {
while (! Serial);
Serial.begin(115200);
Serial.println(F("Adafruit FONA 808 & 3G GPS demo"));
Serial.println(F("Initializing FONA... (May take a few seconds)"));
fonaSerial->begin(4800);
if (! fona.begin(*fonaSerial)) {
Serial.println(F("Couldn't find FONA"));
while(1);
}
Serial.println(F("FONA is OK"));
Serial.println(F("Enabling GPS..."));
fona.enableGPS(true);
}
void loop() {
delay(2000);
bool gps_succes = fona.getGPS(&latitude, &longitude, &speed_kph, &heading, &altitude, &HDOP, &VDOP, &used_sats, &HPA, &VPA, timestamp);
Serial.print("GPS lat:");
Serial.println(latitude, 6);
Serial.print("GPS long:");
Serial.println(longitude, 6);
Serial.print("GPS speed KPH:");
Serial.println(speed_kph);
Serial.print("GPS heading:");
Serial.println(heading);
Serial.print("GPS altitude:");
Serial.println(altitude);
Serial.print("HDOP:");
Serial.println(HDOP);
Serial.print("VDOP:");
Serial.println(VDOP);
Serial.print("Used Sats:");
Serial.println(used_sats,0);
Serial.print("UTC Date/time:");
Serial.println(timestamp);
Serial.print("HPA:");
Serial.println(HPA);
Serial.print("VPA:");
Serial.println(VPA);
}
Adafruit_FONA.h:
Code: Select all
boolean getGPS(float *lat, float *lon, float *speed_kph=0, float *heading=0, float *altitude=0, float *HDOP=0, float *VDOP=0, float *used_sats=0, float *HPA=0, float *VPA=0, char *timestamp="");
Adafruit_FONA.cpp:
Code: Select all
boolean Adafruit_FONA::getGPS(float *lat, float *lon, float *speed_kph, float *heading, float *altitude, float *HDOP, float *VDOP, float *used_sats, float *HPA, float *VPA, char *timestamp) {
...
// only grab date if needed
if (timestamp != NULL) {
// grab date
char *ts = strtok(NULL, ",");
if (! ts) return false;
strncpy(ts,timestamp,15); //#define TS_LENGTH 16 not passed from .ino sketch to this routine
}
Output from Serial Monitor:
Code: Select all
---> AT+CGNSINF
<--- +CGNSINF: 1,1,20180912114751.000,-2.489895,28.857263,1464.200,12.41,103.2,1,,3.3,3.5,1.0,,13,3,,,21,,
GPS lat:-2.489895
GPS long:28.857261
GPS speed KPH:12.41
GPS heading:103.20
GPS altitude:1464.20
HDOP:3.30
VDOP:1.00
Used Sats:3
UTC Date/time:
HPA:21.00
VPA:0.00
I've tried passing the UTC Date/Time string as char, uint8_t, uint16_t, float and double but nothing seems to work. The closest I get to something useful is by assigning the string to a float in the .cpp file using "atof()". However this overflows unless I do Serial.print(timestamp*0.0001) in my sketch and isn't useful because "timestamp" is truncated.
Another thread discusses using network time instead of GPS time however my project will be used in areas outside of cell reception so I need date/time from the satellites.
Thanks SO much for your help! Keep up the good work.