The program sends the current location over the cellular network.

Dependencies:   aconno_I2C ublox-at-cellular-interface gnss ublox-cellular-base Lis2dh12 ublox-cellular-base-n2xx ublox-at-cellular-interface-n2xx low-power-sleep

Fork of example-gnss by u-blox

Committer:
jurica238814
Date:
Fri Nov 30 16:19:41 2018 +0100
Revision:
8:2bf886335fd0
Child:
9:f943c09d9173
Aconno init commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jurica238814 8:2bf886335fd0 1 /**
jurica238814 8:2bf886335fd0 2 * aconno helpers
jurica238814 8:2bf886335fd0 3 * Set of general purpose fuctions used within aconno projects
jurica238814 8:2bf886335fd0 4 *
jurica238814 8:2bf886335fd0 5 */
jurica238814 8:2bf886335fd0 6
jurica238814 8:2bf886335fd0 7 #include "mbed.h"
jurica238814 8:2bf886335fd0 8 #include "aconnoHelpers.h"
jurica238814 8:2bf886335fd0 9 #include "stdlib.h"
jurica238814 8:2bf886335fd0 10 #include "gnss.h"
jurica238814 8:2bf886335fd0 11 #include "aconnoConfig.h"
jurica238814 8:2bf886335fd0 12
jurica238814 8:2bf886335fd0 13 bool getGPSData(char *location, GnssSerial *gnss)
jurica238814 8:2bf886335fd0 14 {
jurica238814 8:2bf886335fd0 15 int gnssReturnCode;
jurica238814 8:2bf886335fd0 16 int length;
jurica238814 8:2bf886335fd0 17 char buffer[505];
jurica238814 8:2bf886335fd0 18 bool gotLocationFlag = false;
jurica238814 8:2bf886335fd0 19
jurica238814 8:2bf886335fd0 20 do
jurica238814 8:2bf886335fd0 21 {
jurica238814 8:2bf886335fd0 22 gnssReturnCode = gnss->getMessage(buffer, sizeof(buffer));
jurica238814 8:2bf886335fd0 23 if (gnssReturnCode > 0)
jurica238814 8:2bf886335fd0 24 {
jurica238814 8:2bf886335fd0 25 // Msg from GNSS module received
jurica238814 8:2bf886335fd0 26 length = LENGTH(gnssReturnCode);
jurica238814 8:2bf886335fd0 27 if ((PROTOCOL(gnssReturnCode) == GnssParser::NMEA) && (length > 6))
jurica238814 8:2bf886335fd0 28 {
jurica238814 8:2bf886335fd0 29 // Talker is $GA=Galileo $GB=Beidou $GL=Glonass $GN=Combined $GP=GNSS
jurica238814 8:2bf886335fd0 30 if ((buffer[0] == '$') || buffer[1] == 'G')
jurica238814 8:2bf886335fd0 31 {
jurica238814 8:2bf886335fd0 32 if (CHECK_TALKER("GLL"))
jurica238814 8:2bf886335fd0 33 {
jurica238814 8:2bf886335fd0 34
jurica238814 8:2bf886335fd0 35 double latitude = 0, longitude = 0;
jurica238814 8:2bf886335fd0 36 char ch;
jurica238814 8:2bf886335fd0 37 if (gnss->getNmeaAngle(1, buffer, length, latitude) &&
jurica238814 8:2bf886335fd0 38 gnss->getNmeaAngle(3, buffer, length, longitude) &&
jurica238814 8:2bf886335fd0 39 gnss->getNmeaItem(6, buffer, length, ch) && (ch == 'A')) {
jurica238814 8:2bf886335fd0 40 sprintf(location, "GNSS: location is %.5f %.5f.", latitude, longitude);
jurica238814 8:2bf886335fd0 41 //printf("I am here: https://maps.google.com/?q=%.5f,%.5f\r\n\r\n",
jurica238814 8:2bf886335fd0 42 // latitude, longitude);
jurica238814 8:2bf886335fd0 43 printf("Got location!\r\n");
jurica238814 8:2bf886335fd0 44 gotLocationFlag = true;
jurica238814 8:2bf886335fd0 45 }
jurica238814 8:2bf886335fd0 46 }
jurica238814 8:2bf886335fd0 47 else if (CHECK_TALKER("GGA"))
jurica238814 8:2bf886335fd0 48 {
jurica238814 8:2bf886335fd0 49 double altitude = 0;
jurica238814 8:2bf886335fd0 50 const char *timeString = NULL;
jurica238814 8:2bf886335fd0 51 // Altitude
jurica238814 8:2bf886335fd0 52 if (gnss->getNmeaItem(9, buffer, length, altitude))
jurica238814 8:2bf886335fd0 53 {
jurica238814 8:2bf886335fd0 54 printf("\r\nGNSS: altitude is %.1f m.\r\n", altitude);
jurica238814 8:2bf886335fd0 55 }
jurica238814 8:2bf886335fd0 56 // Time
jurica238814 8:2bf886335fd0 57 timeString = gnss->findNmeaItemPos(1, buffer, buffer + length);
jurica238814 8:2bf886335fd0 58 if (timeString != NULL) {
jurica238814 8:2bf886335fd0 59 printf("\r\nGNSS: time is %.6s.\r\n\r\n", timeString);
jurica238814 8:2bf886335fd0 60 }
jurica238814 8:2bf886335fd0 61 }
jurica238814 8:2bf886335fd0 62 else if (CHECK_TALKER("VTG"))
jurica238814 8:2bf886335fd0 63 {
jurica238814 8:2bf886335fd0 64 double speed = 0;
jurica238814 8:2bf886335fd0 65 // Speed
jurica238814 8:2bf886335fd0 66 if (gnss->getNmeaItem(7, buffer, length, speed))
jurica238814 8:2bf886335fd0 67 {
jurica238814 8:2bf886335fd0 68 printf("\r\nGNSS: speed is %.1f km/h.\r\n\r\n", speed);
jurica238814 8:2bf886335fd0 69 }
jurica238814 8:2bf886335fd0 70 }
jurica238814 8:2bf886335fd0 71 }
jurica238814 8:2bf886335fd0 72 }
jurica238814 8:2bf886335fd0 73 }
jurica238814 8:2bf886335fd0 74 }while(!gotLocationFlag);
jurica238814 8:2bf886335fd0 75 }