Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: C027 C027_Support M2XStreamClient PowerControl jsonlite mbed-rtos mbed
Fork of PONY_Ph0-uAXIS by
Revision 31:f94b8f987b62, committed 2015-11-21
- Comitter:
- sgmcb
- Date:
- Sat Nov 21 01:27:50 2015 +0000
- Parent:
- 30:f9bb5aba1155
- Child:
- 32:4b94cb22d338
- Commit message:
- Friday GPS location online!
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Thu Nov 19 19:14:39 2015 +0000
+++ b/main.cpp Sat Nov 21 01:27:50 2015 +0000
@@ -1,47 +1,146 @@
#include "mbed.h"
+#include <string.h>
+
+// ublox C027 support libraries
+#include "GPS.h" // GPS support
+#include "MDM.h" // Modem support
+
+// AT&T Support
+
//------------------------------------------------------------------------------------
-/* This example was tested on C027-U20 and C027-G35 with the on board modem.
-
- Additionally it was tested with a shield where the SARA-G350/U260/U270 RX/TX/PWRON
- is connected to D0/D1/D4 and the GPS SCL/SDA is connected D15/D15. In this
- configuration the following platforms were tested (it is likely that others
- will work as well)
- - U-BLOX: C027-G35, C027-U20, C027-C20 (for shield set define C027_FORCE_SHIELD)
- - NXP: LPC1549v2, LPC4088qsb
- - Freescale: FRDM-KL05Z, FRDM-KL25Z, FRDM-KL46Z, FRDM-K64F
- - STM: NUCLEO-F401RE, NUCLEO-F030R8
- mount resistors SB13/14 1k, SB62/63 0R
-*/
-#include "GPS.h"
-#include "MDM.h"
-//------------------------------------------------------------------------------------
-// You need to configure these cellular modem / SIM parameters.
-// These parameters are ignored for LISA-C200 variants and can be left NULL.
-//------------------------------------------------------------------------------------
-//! Set your secret SIM pin here (e.g. "1234"). Check your SIM manual.
-#define SIMPIN "1111"
-/*! The APN of your network operator SIM, sometimes it is "internet" check your
- contract with the network operator. You can also try to look-up your settings in
- google: https://www.google.de/search?q=APN+list */
-#define APN "m2m.com.attz"
-//! Set the user name for your APN, or NULL if not needed
-#define USERNAME NULL
-//! Set the password for your APN, or NULL if not needed
-#define PASSWORD NULL
+// Cellular modem/SIM parameters
+#define SIMPIN "1111" //!SIMPIN is 1111 by default for AT&T SIMs.
+#define APN "m2m.com.attz" // Defined AT&T M2M APN
+#define USERNAME NULL //! Set the user name for your APN, or NULL if not needed (which, apparently, it isn't)
+#define PASSWORD NULL //! Set the password for your APN, or NULL if not needed (which, apparently, it isn't)
//------------------------------------------------------------------------------------
// Set pinout for LED
DigitalOut myled(LED);
int main(void) {
- printf("\n\n----------\nI'm alive!\n");
+ printf("\n\n\r----------\r\nI'm alive!\r\n");
- while(1) {
- myled = !myled;
+ // Loading wait
+ for(int i = 0; i < 10; i++) {
+ myled = !myled;;
wait(0.2);
}
+ int ret; // Integer returns
+
+ // Not 100% sure where this LARGE_DATA flag is being set, but I think we might be using it... (SGM)
+ #ifdef LARGE_DATA
+ char buf[2048] = "";
+ #else
+ char buf[512] = "";
+ #endif
+
+ if(sizeof(buf) > 600)
+ printf("(Using LARGE_DATA)\r\n");
+ else
+ printf("(Not using large data)\r\n");
+
+
+ printf("\r\nBegin test loop\r\n");
+
+ GPSI2C gps; // Initialize GPS object
+
+ printf("GPS initialized...\r\n");
+
+
+
+
+
+ while( (ret = gps.getMessage(buf, sizeof(buf))) < 1 ) {
+ if (ret<0)
+ printf("WAIT received from GPS\r\n");
+ if (ret==0)
+ printf("NOT FOUND received from GPS\r\n");
+ myled = !myled;
+ wait(1.0);
+ }
+
+ float locationLoopWait = 1.0;
+ int locationLoopIter = 0;
+ // Get a good GPS message
+
+ int len = LENGTH(ret);
+
+ while(true) {
+ locationLoopIter++;
+
+ ret = gps.getMessage(buf, sizeof(buf));
+
+ // Test for location data in this priority: GLL, RMC, GGA
+
+ if ( strstr(buf, "GLL") ) {
+ char ch = '-';
+ // FIX: The getNmeaItem isn't working to capture the check character in a valid GLL code, which is unusual; the workaround seems to be that invalid GLL values DOES find a "V"
+ if(!gps.getNmeaItem(6,buf,len,ch)) {
+ printf("\n\n\rHave GLL location data after %i seconds and %i requests:\r\n", ( (int) locationLoopWait * locationLoopIter), locationLoopIter );
+ printf(buf);
+ break;
+ }
+ else {
+ printf("Received invalid GLL data\r\n");
+ printf(buf);
+
+ }
+
+ }
+ else if ( strstr(buf, "RMC") ) {
+ printf("RMC loc...");
+ //printf(buf); printf("\r\n\n");
+
+ }
+ else if ( strstr(buf, "GGA") ) {
+ printf("GGA loc...");
+ //printf(buf); printf("\r\n\n");
+ }
+ else {
+ printf("\n\rNo location data this message\r\n");
+ }
+
+ wait(locationLoopWait);
+ }// LOOP THAT MOFO
+
+
+ // Begin parsing our GPS value
+
+ double la = 0, lo = 0; // Declare latitude and longitude variables
+
+ gps.getNmeaAngle(1,buf,len,la);
+ gps.getNmeaAngle(3,buf,len,lo);
+
+ printf("\r\n\nLatitude: %G\r\nLongitude: %G\r\n", la, lo);
+
+
+
+
+
+
+
+ /*
+
+
+ if ((PROTOCOL(ret) == GPSParser::NMEA) && (len > 6)) { // Check if we're getting an NMEA protocol response
+
+ printf("Indeed, an NMEA protocol response!\r\n");
+
+ // Check the talker
+ if( (buf[0] == '$') || (buf[1] == 'G' ) ) {
+ char talkerID[30] = "";
+ sprintf(talkerID, "We've got a valid talker=%c%c\r\n", buf[0], buf[1]);
+ printf(talkerID);
+ }
+ }
+ */
+
+
+
+
}
@@ -54,241 +153,3 @@
-
-
-
-
-
-
-
-
-
-/*
-
-int main(void)
-{
- int ret;
-#ifdef LARGE_DATA
- char buf[2048] = "";
-#else
- char buf[512] = "";
-#endif
-
- // Create the GPS object
-#if 1 // use GPSI2C class
- GPSI2C gps;
-#else // or GPSSerial class
- GPSSerial gps;
-#endif
- // Create the modem object
- MDMSerial mdm;
- //mdm.setDebug(4); // enable this for debugging issues
- // initialize the modem
- MDMParser::DevStatus devStatus = {};
- MDMParser::NetStatus netStatus = {};
- bool mdmOk = mdm.init(SIMPIN, &devStatus);
- mdm.dumpDevStatus(&devStatus);
- if (mdmOk) {
-#if 0
- // file system API
- const char* filename = "File";
- char buf[] = "Hello World";
- printf("writeFile \"%s\"\r\n", buf);
- if (mdm.writeFile(filename, buf, sizeof(buf)))
- {
- memset(buf, 0, sizeof(buf));
- int len = mdm.readFile(filename, buf, sizeof(buf));
- if (len >= 0)
- printf("readFile %d \"%.*s\"\r\n", len, len, buf);
- mdm.delFile(filename);
- }
-#endif
-
- // wait until we are connected
- mdmOk = mdm.registerNet(&netStatus);
- mdm.dumpNetStatus(&netStatus);
- }
- if (mdmOk)
- {
- // http://www.geckobeach.com/cellular/secrets/gsmcodes.php
- // http://de.wikipedia.org/wiki/USSD-Codes
- const char* ussd = "*130#"; // You may get answer "UNKNOWN APPLICATION"
- printf("Ussd Send Command %s\r\n", ussd);
- ret = mdm.ussdCommand(ussd, buf);
- if (ret > 0)
- printf("Ussd Got Answer: \"%*s\"\r\n", ret, buf);
-
- // join the internet connection
- MDMParser::IP ip = mdm.join(APN,USERNAME,PASSWORD);
- if (ip != NOIP)
- {
- mdm.dumpIp(ip);
- printf("Make a Http Post Request\r\n");
- int socket = mdm.socketSocket(MDMParser::IPPROTO_TCP);
- if (socket >= 0)
- {
- mdm.socketSetBlocking(socket, 10000);
- if (mdm.socketConnect(socket, "mbed.org", 80))
- {
- const char http[] = "GET /media/uploads/mbed_official/hello.txt HTTP/1.0\r\n\r\n";
- mdm.socketSend(socket, http, sizeof(http)-1);
-
- ret = mdm.socketRecv(socket, buf, sizeof(buf)-1);
- if (ret > 0)
- printf("Socket Recv \"%*s\"\r\n", ret, buf);
- mdm.socketClose(socket);
- }
- mdm.socketFree(socket);
- }
-
- int port = 7;
- const char* host = "echo.u-blox.com";
- MDMParser::IP ip = mdm.gethostbyname(host);
- char data[] = "\r\nxxx Socket Hello World\r\n"
-#ifdef LARGE_DATA
- "00 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n"
- "01 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n"
- "02 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n"
- "03 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n"
- "04 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n"
-
- "05 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n"
- "06 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n"
- "07 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n"
- "08 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n"
- "09 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n"
-
- "10 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n"
- "11 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n"
- "12 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n"
- "13 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n"
- "14 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n"
-
- "15 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n"
- "16 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n"
- "17 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n"
- "18 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n"
- "19 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n"
-#endif
- "End\r\n";
-
- printf("Testing TCP sockets with ECHO server\r\n");
- socket = mdm.socketSocket(MDMParser::IPPROTO_TCP);
- if (socket >= 0)
- {
- mdm.socketSetBlocking(socket, 10000);
- if (mdm.socketConnect(socket, host, port)) {
- memcpy(data, "\r\nTCP", 5);
- ret = mdm.socketSend(socket, data, sizeof(data)-1);
- if (ret == sizeof(data)-1) {
- printf("Socket Send %d \"%s\"\r\n", ret, data);
- }
- ret = mdm.socketRecv(socket, buf, sizeof(buf)-1);
- if (ret >= 0) {
- printf("Socket Recv %d \"%.*s\"\r\n", ret, ret, buf);
- }
- mdm.socketClose(socket);
- }
- mdm.socketFree(socket);
- }
-
- printf("Testing UDP sockets with ECHO server\r\n");
- socket = mdm.socketSocket(MDMParser::IPPROTO_UDP, port);
- if (socket >= 0)
- {
- mdm.socketSetBlocking(socket, 10000);
- memcpy(data, "\r\nUDP", 5);
- ret = mdm.socketSendTo(socket, ip, port, data, sizeof(data)-1);
- if (ret == sizeof(data)-1) {
- printf("Socket SendTo %s:%d " IPSTR " %d \"%s\"\r\n", host, port, IPNUM(ip), ret, data);
- }
- ret = mdm.socketRecvFrom(socket, &ip, &port, buf, sizeof(buf)-1);
- if (ret >= 0) {
- printf("Socket RecvFrom " IPSTR ":%d %d \"%.*s\" \r\n", IPNUM(ip),port, ret, ret,buf);
- }
- mdm.socketFree(socket);
- }
-
- // disconnect
- mdm.disconnect();
- }
- }
- printf("SMS and GPS Loop\r\n");
- char link[128] = "";
- unsigned int i = 0xFFFFFFFF;
- const int wait = 100;
- bool abort = false;
- //DigitalOut led(LED1);
- while (!abort) {
- // led = !led;
- while ((ret = gps.getMessage(buf, sizeof(buf))) > 0)
- {
- int len = LENGTH(ret);
- //printf("NMEA: %.*s\r\n", len-2, msg);
- if ((PROTOCOL(ret) == GPSParser::NMEA) && (len > 6))
- {
- // talker is $GA=Galileo $GB=Beidou $GL=Glonass $GN=Combined $GP=GPS
- if ((buf[0] == '$') || buf[1] == 'G') {
- #define _CHECK_TALKER(s) ((buf[3] == s[0]) && (buf[4] == s[1]) && (buf[5] == s[2]))
- if (_CHECK_TALKER("GLL")) {
- double la = 0, lo = 0;
- char ch;
- if (gps.getNmeaAngle(1,buf,len,la) &&
- gps.getNmeaAngle(3,buf,len,lo) &&
- gps.getNmeaItem(6,buf,len,ch) && ch == 'A')
- {
- printf("GPS Location: %.5f %.5f\r\n", la, lo);
- sprintf(link, "I am here!\n"
- "https://maps.google.com/?q=%.5f,%.5f", la, lo);
- }
- } else if (_CHECK_TALKER("GGA") || _CHECK_TALKER("GNS") ) {
- double a = 0;
- if (gps.getNmeaItem(9,buf,len,a)) // altitude msl [m]
- printf("GPS Altitude: %.1f\r\n", a);
- } else if (_CHECK_TALKER("VTG")) {
- double s = 0;
- if (gps.getNmeaItem(7,buf,len,s)) // speed [km/h]
- printf("GPS Speed: %.1f\r\n", s);
- }
- }
- }
- }
- if (mdmOk && (i++ == 5000/wait)) {
- i = 0;
- // check the network status
- if (mdm.checkNetStatus(&netStatus)) {
- mdm.dumpNetStatus(&netStatus, fprintf, stdout);
- }
-
- // checking unread sms
- int ix[8];
- int n = mdm.smsList("REC UNREAD", ix, 8);
- if (8 < n) n = 8;
- while (0 < n--)
- {
- char num[32];
- printf("Unread SMS at index %d\r\n", ix[n]);
- if (mdm.smsRead(ix[n], num, buf, sizeof(buf))) {
- printf("Got SMS from \"%s\" with text \"%s\"\r\n", num, buf);
- printf("Delete SMS at index %d\r\n", ix[n]);
- mdm.smsDelete(ix[n]);
- // provide a reply
- const char* reply = "Hello my friend";
- if (strstr(buf, "here are you")) // Omits opening "W" or "w" for case insensitive search
- reply = *link ? link : "I don't know"; // reply wil location link
- else if (strstr(buf, "hutdown")) // Omits opening "S" or "s" for case insensitive search
- abort = true, reply = "bye bye";
- printf("Send SMS reply \"%s\" to \"%s\"\r\n", reply, num);
- mdm.smsSend(num, reply);
- }
- }
- }
- wait_ms(wait);
- }
- gps.powerOff();
- mdm.powerOff();
- return 0;
-}
-
-
-*/
\ No newline at end of file
