Examplecode for GPS functionality on the QW-GPS-DEVKIT.

Dependencies:   mbed

Fork of HelloWorld - QW Development kit by Quicksand micro-electronics

Firmware

This program starts the GPS on the TD1204 in continuous navigating mode using the following AT-command:

AT$GPS=1,16,0,65535,1,1

A timer sends the latests gps fix every 30 seconds or 10 minutes to the SIGFOX backend using the following command:

AT$GSND

LED3 burns if a 30 second interval is set. LED4 burns if a 10 minute interval is set. Switching between intervals can be done using button 1.

Button 2 instantly sends the latests fix to the SIGFOX cloud.

Settings in the SIGFOX backend

Create a new device-type and set display typte to Geolocation > Telecom Design.

/media/uploads/quicksand/gpsdecode.jpg

Assign your development kit to this device-type and the decoding will happen automatically:

/media/uploads/quicksand/gpsdecoded.jpg

Data if no GPS fix was found!

Note: The data looks like this if your device didn't get a valid fix before the transmission of a SIGFOX packet.

/media/uploads/quicksand/nofix.jpg

You can follow the NMEA messages of the GPS if you open up a terminal and connect to the virtual com-port of the QW shield. More info about NMEA messages can be found HERE.

/media/uploads/quicksand/nmea.jpg

GPS data is displayed in different message formats over a serial interface. There are standard and non-standard (proprietary) message formats. Nearly all GPS receivers output NMEA data. The NMEA standard is formatted in lines of data called sentences. Each sentence contains various bits of data organized in comma delimited format (i.e. data separated by commas). Here’s example NMEA sentences from a GPS receiver with satellite lock (4+ satellites, accurate position):

$GPRMC,235316.000,A,4003.9040,N,10512.5792,W,0.09,144.75,141112,,*19
$GPGGA,235317.000,4003.9039,N,10512.5793,W,1,08,1.6,1577.9,M,-20.7,M,,0000*5F
$GPGSA,A,3,22,18,21,06,03,09,24,15,,,,,2.5,1.6,1.9*3E

For example, the GPGGA sentence above contains the following:

  • Time: 235317.000 is 23:53 and 17.000 seconds in Greenwich mean time
  • Longitude: 4003.9040,N is latitude in degrees.decimal minutes, north
  • Latitude: 10512.5792,W is longitude in degrees.decimal minutes, west
  • Number of satellites seen: 08
  • Altitude: 1577 meters

Note, every 30 seconds an "OK" will appear after sending the SIGFOX message.

More information about the NMEA sentences coming from the TD1204 can be found in the following datasheet of the u-blox 7 series: Link.

You can even open up a track of your device:

/media/uploads/quicksand/track.jpg

/media/uploads/quicksand/trackmap.jpg

Committer:
quicksand
Date:
Wed Mar 02 12:14:48 2016 +0000
Revision:
1:18afd4c75c6e
Parent:
0:49858c4c3500
First version of a GPS example

Who changed what in which revision?

UserRevisionLine numberNew contents of line
quicksand 0:49858c4c3500 1 #include "mbed.h"
quicksand 0:49858c4c3500 2
quicksand 0:49858c4c3500 3 DigitalOut LED_0 (PB_6);
quicksand 0:49858c4c3500 4 DigitalOut LED_1 (PA_7);
quicksand 0:49858c4c3500 5 DigitalOut LED_2 (PA_6);
quicksand 0:49858c4c3500 6 DigitalOut LED_3 (PA_5);
quicksand 0:49858c4c3500 7 InterruptIn SW1(PB_10);
quicksand 0:49858c4c3500 8 InterruptIn SW2(PA_8);
quicksand 0:49858c4c3500 9
quicksand 0:49858c4c3500 10 Ticker hartbeat;
quicksand 1:18afd4c75c6e 11 Ticker position_update;
quicksand 0:49858c4c3500 12
quicksand 0:49858c4c3500 13 //Virtual serial port over USB
quicksand 0:49858c4c3500 14 Serial pc(USBTX, USBRX);
quicksand 0:49858c4c3500 15 Serial modem(PA_9, PA_10);
quicksand 0:49858c4c3500 16
quicksand 1:18afd4c75c6e 17 char * response = "OK";
quicksand 1:18afd4c75c6e 18 char * responsePtr;
quicksand 1:18afd4c75c6e 19 bool commandogiven = false;
quicksand 1:18afd4c75c6e 20 bool commandofailed = true;
quicksand 1:18afd4c75c6e 21 int updateinterval_s = 30;
quicksand 1:18afd4c75c6e 22
quicksand 1:18afd4c75c6e 23 // Send command and check if ok
quicksand 1:18afd4c75c6e 24 void command(char * commando)
quicksand 1:18afd4c75c6e 25 {
quicksand 1:18afd4c75c6e 26 LED_1=0;
quicksand 1:18afd4c75c6e 27 modem.printf(commando);
quicksand 1:18afd4c75c6e 28 commandogiven = true;
quicksand 1:18afd4c75c6e 29 commandofailed = true;
quicksand 1:18afd4c75c6e 30 }
quicksand 1:18afd4c75c6e 31
quicksand 1:18afd4c75c6e 32 // Blinking LED Ticker
quicksand 1:18afd4c75c6e 33 void beat()
quicksand 1:18afd4c75c6e 34 {
quicksand 1:18afd4c75c6e 35 LED_0 = !LED_0;
quicksand 1:18afd4c75c6e 36 }
quicksand 1:18afd4c75c6e 37
quicksand 1:18afd4c75c6e 38 // Position transmission ticker
quicksand 1:18afd4c75c6e 39 void txpos()
quicksand 1:18afd4c75c6e 40 {
quicksand 1:18afd4c75c6e 41 command("AT$GSND\n");
quicksand 1:18afd4c75c6e 42 }
quicksand 0:49858c4c3500 43
quicksand 1:18afd4c75c6e 44 void sw1interrupt()
quicksand 1:18afd4c75c6e 45 {
quicksand 1:18afd4c75c6e 46 //command("AT$GPS=1,16,0,65535,1,1\n");
quicksand 1:18afd4c75c6e 47 if(updateinterval_s == 30)
quicksand 1:18afd4c75c6e 48 {
quicksand 1:18afd4c75c6e 49 position_update.detach();
quicksand 1:18afd4c75c6e 50 updateinterval_s = 600; // Updateinterval = 10 minutes
quicksand 1:18afd4c75c6e 51 LED_3 = 1;
quicksand 0:49858c4c3500 52 LED_2 = 0;
quicksand 1:18afd4c75c6e 53 position_update.attach(&txpos, updateinterval_s);
quicksand 1:18afd4c75c6e 54 }
quicksand 1:18afd4c75c6e 55 else
quicksand 1:18afd4c75c6e 56 {
quicksand 1:18afd4c75c6e 57 position_update.detach();
quicksand 1:18afd4c75c6e 58 updateinterval_s = 30; // Updateinterval = 30 seconds
quicksand 1:18afd4c75c6e 59 LED_3 = 0;
quicksand 1:18afd4c75c6e 60 LED_2 = 1;
quicksand 1:18afd4c75c6e 61 position_update.attach(&txpos, updateinterval_s);
quicksand 1:18afd4c75c6e 62 }
quicksand 1:18afd4c75c6e 63 }
quicksand 0:49858c4c3500 64
quicksand 1:18afd4c75c6e 65 void sw2interrupt()
quicksand 1:18afd4c75c6e 66 {
quicksand 1:18afd4c75c6e 67 command("AT$GSND\n");
quicksand 1:18afd4c75c6e 68 }
quicksand 1:18afd4c75c6e 69
quicksand 1:18afd4c75c6e 70 int main()
quicksand 1:18afd4c75c6e 71 {
quicksand 1:18afd4c75c6e 72 wait(3);
quicksand 0:49858c4c3500 73 LED_0 = 1;
quicksand 0:49858c4c3500 74 LED_1 = 1;
quicksand 0:49858c4c3500 75 LED_2 = 1;
quicksand 1:18afd4c75c6e 76 LED_3 = 0;
quicksand 0:49858c4c3500 77 hartbeat.attach(&beat, 0.5);
quicksand 1:18afd4c75c6e 78 position_update.attach(&txpos, updateinterval_s);
quicksand 0:49858c4c3500 79 SW2.fall(&sw1interrupt);
quicksand 0:49858c4c3500 80 SW1.fall(&sw2interrupt);
quicksand 1:18afd4c75c6e 81 command("AT$GPS=1,16,0,65535,1,1\n");
quicksand 1:18afd4c75c6e 82 while(1) {
quicksand 1:18afd4c75c6e 83 if(!commandogiven) {
quicksand 1:18afd4c75c6e 84 if(pc.readable()) {
quicksand 1:18afd4c75c6e 85 modem.putc(pc.getc());
quicksand 1:18afd4c75c6e 86 }
quicksand 1:18afd4c75c6e 87
quicksand 1:18afd4c75c6e 88 if(modem.readable()) {
quicksand 1:18afd4c75c6e 89 pc.putc(modem.getc());
quicksand 1:18afd4c75c6e 90 }
quicksand 1:18afd4c75c6e 91 } else {
quicksand 1:18afd4c75c6e 92 int c, i;
quicksand 1:18afd4c75c6e 93 while ((c = modem.getc()) >= 0 && commandogiven && i < 10000) {
quicksand 1:18afd4c75c6e 94 if ((char) c == *responsePtr)
quicksand 1:18afd4c75c6e 95 responsePtr++;
quicksand 1:18afd4c75c6e 96 else
quicksand 1:18afd4c75c6e 97 responsePtr = response;
quicksand 1:18afd4c75c6e 98 if (*responsePtr == 0) {
quicksand 1:18afd4c75c6e 99 LED_1=1;
quicksand 1:18afd4c75c6e 100 commandogiven = false;
quicksand 1:18afd4c75c6e 101 }
quicksand 1:18afd4c75c6e 102 i++;
quicksand 1:18afd4c75c6e 103 }
quicksand 1:18afd4c75c6e 104 if(commandogiven == true) {
quicksand 1:18afd4c75c6e 105 commandogiven = false;
quicksand 1:18afd4c75c6e 106 commandofailed = true;
quicksand 1:18afd4c75c6e 107 LED_1=1;
quicksand 1:18afd4c75c6e 108 } else {
quicksand 1:18afd4c75c6e 109 commandofailed = false;
quicksand 1:18afd4c75c6e 110 }
quicksand 1:18afd4c75c6e 111
quicksand 0:49858c4c3500 112 }
quicksand 0:49858c4c3500 113 }
quicksand 0:49858c4c3500 114 }