|
| 1 | +#include <GSM.h> |
| 2 | +#include <MicroNMEA.h> |
| 3 | + |
| 4 | +#include "arduino_secrets.h" |
| 5 | +char pin[] = SECRET_PIN; |
| 6 | +char apn[] = SECRET_APN; |
| 7 | +char username[] = SECRET_USERNAME; |
| 8 | +char pass[] = SECRET_PASSWORD; |
| 9 | + |
| 10 | +void mycallback(char * output); |
| 11 | + |
| 12 | +void setup() { |
| 13 | + Serial.begin(115200); |
| 14 | + while (!Serial) {} |
| 15 | + //GSM.debug(Serial); |
| 16 | + Serial.println("\nStarting connection to server..."); |
| 17 | + GSM.begin(pin, apn, username, pass, CATNB); |
| 18 | + Serial.println("\nStarting connection ..."); |
| 19 | + |
| 20 | + Serial.println("\nEnable GNSS Engine..."); |
| 21 | + GSM.beginGNSS(mycallback); |
| 22 | + GSM.startGNSS(); |
| 23 | +} |
| 24 | + |
| 25 | +char nmeaBuffer[100]; |
| 26 | +MicroNMEA nmea(nmeaBuffer, sizeof(nmeaBuffer)); |
| 27 | + |
| 28 | +void loop() { |
| 29 | + |
| 30 | + delay(1000); |
| 31 | + |
| 32 | + // Output GPS information from previous second |
| 33 | + Serial.print("Valid fix: "); |
| 34 | + Serial.println(nmea.isValid() ? "yes" : "no"); |
| 35 | + |
| 36 | + if (nmea.isValid()) { |
| 37 | + |
| 38 | + Serial.print("Nav. system: "); |
| 39 | + if (nmea.getNavSystem()) |
| 40 | + Serial.println(nmea.getNavSystem()); |
| 41 | + else |
| 42 | + Serial.println("none"); |
| 43 | + |
| 44 | + Serial.print("Num. satellites: "); |
| 45 | + Serial.println(nmea.getNumSatellites()); |
| 46 | + |
| 47 | + Serial.print("HDOP: "); |
| 48 | + Serial.println(nmea.getHDOP() / 10., 1); |
| 49 | + |
| 50 | + Serial.print("Date/time: "); |
| 51 | + Serial.print(nmea.getYear()); |
| 52 | + Serial.print('-'); |
| 53 | + Serial.print(int(nmea.getMonth())); |
| 54 | + Serial.print('-'); |
| 55 | + Serial.print(int(nmea.getDay())); |
| 56 | + Serial.print('T'); |
| 57 | + Serial.print(int(nmea.getHour())); |
| 58 | + Serial.print(':'); |
| 59 | + Serial.print(int(nmea.getMinute())); |
| 60 | + Serial.print(':'); |
| 61 | + Serial.println(int(nmea.getSecond())); |
| 62 | + |
| 63 | + long latitude_mdeg = nmea.getLatitude(); |
| 64 | + long longitude_mdeg = nmea.getLongitude(); |
| 65 | + Serial.print("Latitude (deg): "); |
| 66 | + Serial.println(latitude_mdeg / 1000000., 6); |
| 67 | + |
| 68 | + Serial.print("Longitude (deg): "); |
| 69 | + Serial.println(longitude_mdeg / 1000000., 6); |
| 70 | + |
| 71 | + long alt; |
| 72 | + Serial.print("Altitude (m): "); |
| 73 | + if (nmea.getAltitude(alt)) |
| 74 | + Serial.println(alt / 1000., 3); |
| 75 | + else |
| 76 | + Serial.println("not available"); |
| 77 | + |
| 78 | + Serial.print("Speed: "); |
| 79 | + Serial.println(nmea.getSpeed() / 1000., 3); |
| 80 | + Serial.print("Course: "); |
| 81 | + Serial.println(nmea.getCourse() / 1000., 3); |
| 82 | + } |
| 83 | +} |
| 84 | + |
| 85 | +void mycallback(char * output) |
| 86 | +{ |
| 87 | + for (size_t i = 0; i < strlen(output); i++) { |
| 88 | + nmea.process(output[i]); |
| 89 | + } |
| 90 | + nmea.process('\0'); |
| 91 | + //Serial.println(output); |
| 92 | +} |
0 commit comments